/// <summary>
        ///     Redo the last command that has been undone
        /// </summary>
        /// <returns>The last command, null if there is none</returns>
        public ICompensableCommand Redo()
        {
            if (_redoCommands.Count == 0)
            {
                return(null);
            }

            ICompensableCommand command = _redoCommands.Pop();

            command.Execute();
            _undoCommands.Push(command);

            return(command);
        }
        public void Execute()
        {
            _moveCommand.Execute();

            var   square = _board.SquareAt(Move.TargetCoordinate);
            Piece piece;

            switch (Move.PromotePieceType)
            {
            case Type.Bishop:
                piece = new Bishop(Move.PieceColor, square);
                break;

            case Type.King:
                piece = new King(Move.PieceColor, square);
                break;

            case Type.Queen:
                piece = new Queen(Move.PieceColor, square);
                break;

            case Type.Pawn:
                piece = new Pawn(Move.PieceColor, square);
                break;

            case Type.Knight:
                piece = new Knight(Move.PieceColor, square);
                break;

            case Type.Rook:
                piece = new Rook(Move.PieceColor, square);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            square.Piece = piece;
        }
示例#3
0
        public bool IsMoveValid(Move move, Board board)
        {
            IState checkState = new CheckState();
            Board  tempBoard  = new Board(board);

            bool castling = new CastlingRule().IsMoveValid(move, board) && (move.PieceType == Type.King) &&
                            (tempBoard.PieceAt(move.TargetCoordinate)?.Type == Type.Rook) &&
                            (move.PieceColor == tempBoard.PieceAt(move.TargetCoordinate)?.Color);

            if (!castling)
            {
                if (move.PieceColor == tempBoard.PieceAt(move.TargetCoordinate)?.Color)
                {
                    return(true);
                }
            }
            ICompensableCommand command = castling
                ? new CastlingCommand(move, tempBoard)
                : new MoveCommand(move, tempBoard) as ICompensableCommand;

            command.Execute();

            return(!checkState.IsInState(tempBoard, move.PieceColor));
        }
 public void Execute()
 {
     _rookCommand.Execute();
     _kingCommand.Execute();
 }
示例#5
0
 public void Execute()
 {
     _firstMove.Execute();
     _secondMove.Execute();
 }
示例#6
0
 /// <summary>
 ///     Executes a command
 /// </summary>
 /// <param name="command">The command to execute</param>
 public void Execute(ICompensableCommand command)
 {
     command.Execute();
     _undoCommands.Push(command);
     _redoCommands.Clear();
 }