/// <summary> /// MakeMove - Сделать ход /// Attempt to make the specified move on the board starting at the given position if present /// Попытка сделать указанное движение на доске, начиная с заданной позиции, если присутствует /// </summary> /// <param name="move"> /// The move /// Движение /// </param> /// <param name="startPosition"> /// The starting position of the move if this move is a jump continuation /// Начальная позиция хода, если этот ход является продолжением прыжка /// </param> public void MakeMove(Move move, int?startPosition) { const int INVALID_POSITION = -1; int origin = move.Origin ?? INVALID_POSITION; if (origin == INVALID_POSITION) { HandleInvalidMove(move, "Move contains no steps");//ход не содержит шагов } else if ((startPosition.HasValue) && (origin != startPosition.Value)) { HandleInvalidMove(move, "You must finish jump");//Вы должны закончить прыжок } else { Piece piece = board[origin]; Player player = BoardUtilities.GetPlayer(piece); PlayerInfo playerInfo = GetPlayerInfo(player); MoveStatus moveStatus = MoveStatus.Illegal; move = boardRules.ResolveAmbiguousMove(board, move); if (piece == Piece.None) { HandleInvalidMove(move, "No piece selected");//Не выбрано ни одного предмета } else if (playerInfo != turn) { HandleInvalidMove(move, string.Format(CultureInfo.InvariantCulture, "Not {0}'s turn", playerInfo.Player.ToString()));//Не ход {0} } else if ((moveStatus = boardRules.IsValidMove(board, move, turn.Player)) == MoveStatus.Illegal) { HandleInvalidMove(move, string.Format(CultureInfo.InvariantCulture, "Invalid move: {0}", move));// Неверный ход: {0} } else if (!boardRules.ApplyMove(board, move)) { HandleInvalidMove(move, string.Format(CultureInfo.InvariantCulture, "Unable to apply move move: {0}", move));// Невозможно применить ход перемещения: {0} } else { view.SetBoardState(board.Copy()); // swap turn if the player has a complete move (no jumps) // меняем ход, если у игрока полный ход (без прыжков) if (moveStatus == MoveStatus.Incomplete) { // at this point the move was valid and hence must have a destination // в этот момент перемещение было допустимым и, следовательно, должно иметь пункт назначения view.SetMoveStartPosition(move.Destination.Value); } else { view.SetMoveStartPosition(null); view.LockPlayer(turn.Player, true); this.SwapTurn(); } this.GameStep(); } } }
/// <summary> /// Attempt to make the specified move on the board starting at the given position if present /// </summary> /// <param name="move">The move</param> /// <param name="startPosition">The starting position of the move if this move is a jump continuation</param> public void MakeMove(Move move, int? startPosition) { const int INVALID_POSITION = -1; int origin = move.Origin ?? INVALID_POSITION; if (origin == INVALID_POSITION) { HandleInvalidMove(move, "Move contains no steps"); } else if ((startPosition.HasValue) && (origin != startPosition.Value)) { HandleInvalidMove(move, "You must finish jump"); } else { Piece piece = board[origin]; Player player = BoardUtilities.GetPlayer(piece); PlayerInfo playerInfo = GetPlayerInfo(player); MoveStatus moveStatus = MoveStatus.Illegal; move = boardRules.ResolveAmbiguousMove(board, move); if (piece == Piece.None) { HandleInvalidMove(move, "No piece selected"); } else if (playerInfo != turn) { HandleInvalidMove(move, string.Format(CultureInfo.InvariantCulture, "Not {0}'s turn", playerInfo.Player.ToString())); } else if ((moveStatus = boardRules.IsValidMove(board, move, turn.Player)) == MoveStatus.Illegal) { HandleInvalidMove(move, string.Format(CultureInfo.InvariantCulture, "Invalid move: {0}", move)); } else if (!boardRules.ApplyMove(board, move)) { HandleInvalidMove(move, string.Format(CultureInfo.InvariantCulture, "Unable to apply move move: {0}", move)); } else { view.SetBoardState(board.Copy()); // swap turn if the player has a complete move (no jumps) if (moveStatus == MoveStatus.Incomplete) { // at this point the move was valid and hence must have a destination view.SetMoveStartPosition(move.Destination.Value); } else { view.SetMoveStartPosition(null); view.LockPlayer(turn.Player, true); this.SwapTurn(); } this.GameStep(); } } }