Chess.Domain.GameManager.MovePiece C# (CSharp) Метод

MovePiece() публичный Метод

public MovePiece ( Move move ) : void
move Chess.Data.Entities.Move
Результат void
        public void MovePiece(Move move)
        {
            var piece = _board.Squares[move.StartRow][move.StartColumn].ChessPiece;
            var defender = _board.Squares[move.EndRow][move.EndColumn].ChessPiece;
            var currentTeam = TeamToMove();

            ValidateActiveGame();
            ValidateIsCurrentTeam(piece);
            ValidateIsLegalMove(move, piece);

            PerformMove(move, defender, piece);

            MarkGameProgress(piece, defender);
            ValidateKingNotInCheck(currentTeam);
        }

Usage Example

        public ActionResult MakeMove(long id, Move move)
        {
            var game = GetChessGame(id);
            var gameManager = new GameManager(game);

            if (!IsPlayersMove(game, CurrentUser))
                throw new Exception("It is not your turn!");

            try
            {
                var movingTeam = gameManager.TeamToMove();

                gameManager.MovePiece(move);

                if (gameManager.IsDraw())
                    gameManager.MarkGameAsDraw();
                else if (gameManager.IsCheckmate())
                    gameManager.MarkWinningTeam(movingTeam);

                UnitOfWork.Commit();

                var model = GetGameModel(game);

                return Json(model, JsonRequestBehavior.AllowGet);
            }
            catch (Exception ex)
            {
                throw NewMoveFailureException(move, ex);
            }
        }