Move *Move::Clone() { Move *move = new Move(player, prevState, piece, startPos); for (auto it = steps.begin(); it != steps.end(); it++) { MoveStep *step = *it; move->AddStep(new MoveStep(*step), false); } move->references = references; move->description = description; if (hasCustomNotation) move->notation = notation; move->hasCustomNotation = hasCustomNotation; strcpy(move->appendNotation, appendNotation); return move; }
std::list<Move*> *Slide::DetermineNextSteps(Move *baseMove, Piece *piece, MoveStep *previousStep) { std::list<Move*> *moves = new std::list<Move*>(); // some steps will specify a different piece to act upon, rather than the piece being moved if (!moveSelf) { piece = baseMove->GetPieceByReference(pieceRef, piece); if (piece == 0) { ReportError("Referenced piece not found for slide move: %s\n", pieceRef); return moves; } } Player *player = baseMove->GetPlayer(); Game *game = player->GetGame(); direction_t dirs = player->ResolveDirections(direction, previousStep != 0 && previousStep->GetDirection() != 0 ? previousStep->GetDirection() : player->GetForwardDirection()); FOR_EACH_DIR_IN_SET(dirs, dir) { int boardMaxDist = piece->GetPosition()->GetMaxDist(dir); int minDist = distance->GetValue(previousStep, boardMaxDist); int maxDist = distance->GetMaxValue(distanceMax, previousStep, boardMaxDist); Cell *cell = piece->GetPosition(); for (int dist = 1; dist <= maxDist; dist++) { cell = cell->FollowLink(dir); if (cell == 0) break; Piece *target = cell->GetPiece(); if (dist >= minDist) { MoveStep *captureStep = 0; if (target == 0) { if (when == Capturing) continue; // needs to be a capture for this slide to be valid, and there is no piece here. But there might be pieces beyond this one. } else { if (when == Moving) break; else if (piece->CanCapture(target)) captureStep = CreateCapture(target, piece); else break; // cannot capture this piece. Slides cannot pass over pieces, so there can be no more valid slides in this direction. } Move *move = baseMove->Clone(); MoveStep *lastPerformedStep = move->GetSteps().empty() ? 0 : *move->GetSteps().rbegin(); if (captureStep != 0) { move->AddStep(captureStep); move->AddPieceReference(target, "target"); } move->AddStep(MoveStep::CreateMove(piece, piece->GetPosition(), cell, dir, dist)); if (conditions == 0 || conditions->IsSatisfied(piece, move, lastPerformedStep)) moves->push_back(move); else delete move; } if (target != 0) break; // Slides can't pass intervening pieces. As this cell was occupied, can be no more valid slides in this direction. } }