示例#1
0
        /// <summary>
        /// Moves the piece in the Chess board
        /// </summary>
        /// <param name="movementType"></param>
        /// <param name="newX"></param>
        /// <param name="newY"></param>
        public void Move(MovementType movementType, int newX, int newY)
        {
            //first determine if the new position is valid
            //I am using the chessboard
            if (_chessBoard.IsLegalBoardPosition(newX, newY))
            {
                //verify that the x move is correct
                if (!VerifyXMove(newX, this.XCoordinate))
                {
                    //don't do the move
                    return;
                }

                //verify that the Y move is correct
                if (!VerifyYMove(newY, this.YCoordinate))
                {
                    //don't do the move
                    return;
                }

                this.XCoordinate = newX;
                this.YCoordinate = newY;


                _chessBoard.Add(this, this.XCoordinate, this.YCoordinate, this.PieceColor);
            }
            else
            {
                string result = string.Format("Not an acceptable move X: {0} Y: {1}", newX, newY);
            }

            // throw new NotImplementedException("Need to implement Pawn.Move()");
        }
示例#2
0
        public void SetUpChessBoard()
        {
            ChessBoard.Add(new BlackPawn(ChessBoard), 0, 6);
            ChessBoard.Add(new BlackPawn(ChessBoard), 1, 6);
            ChessBoard.Add(new BlackPawn(ChessBoard), 2, 6);
            ChessBoard.Add(new BlackPawn(ChessBoard), 3, 6);
            ChessBoard.Add(new BlackPawn(ChessBoard), 4, 6);
            ChessBoard.Add(new BlackPawn(ChessBoard), 5, 6);
            ChessBoard.Add(new BlackPawn(ChessBoard), 6, 6);
            ChessBoard.Add(new BlackPawn(ChessBoard), 7, 6);
            ChessBoard.Add(new Rook(PieceColor.Black, ChessBoard), 0, 7);
            ChessBoard.Add(new Knight(PieceColor.Black, ChessBoard), 1, 7);
            ChessBoard.Add(new Bishop(PieceColor.Black, ChessBoard), 2, 7);
            ChessBoard.Add(new Queen(PieceColor.Black, ChessBoard), 3, 7);
            ChessBoard.Add(new BlackKing(ChessBoard), 4, 7);
            ChessBoard.Add(new Bishop(PieceColor.Black, ChessBoard), 5, 7);
            ChessBoard.Add(new Knight(PieceColor.Black, ChessBoard), 6, 7);
            ChessBoard.Add(new Rook(PieceColor.Black, ChessBoard), 7, 7);

            ChessBoard.Add(new WhitePawn(ChessBoard), 0, 1);
            ChessBoard.Add(new WhitePawn(ChessBoard), 1, 1);
            ChessBoard.Add(new WhitePawn(ChessBoard), 2, 1);
            ChessBoard.Add(new WhitePawn(ChessBoard), 3, 1);
            ChessBoard.Add(new WhitePawn(ChessBoard), 4, 1);
            ChessBoard.Add(new WhitePawn(ChessBoard), 5, 1);
            ChessBoard.Add(new WhitePawn(ChessBoard), 6, 1);
            ChessBoard.Add(new WhitePawn(ChessBoard), 7, 1);
            ChessBoard.Add(new Rook(PieceColor.White, ChessBoard), 0, 0);
            ChessBoard.Add(new Knight(PieceColor.White, ChessBoard), 1, 0);
            ChessBoard.Add(new Bishop(PieceColor.White, ChessBoard), 2, 0);
            ChessBoard.Add(new Queen(PieceColor.White, ChessBoard), 3, 0);
            ChessBoard.Add(new WhiteKing(ChessBoard), 4, 0);
            ChessBoard.Add(new Bishop(PieceColor.White, ChessBoard), 5, 0);
            ChessBoard.Add(new Knight(PieceColor.White, ChessBoard), 6, 0);
            ChessBoard.Add(new Rook(PieceColor.White, ChessBoard), 7, 0);
        }
示例#3
0
 public void _01_placing_the_white_pawn_on_X_equals_6_and_Y_equals_1_should_place_the_white_pawn_on_that_place_on_the_board()
 {
     _chessBoard.Add(_pawn, 6, 1, PieceColor.White);
     Assert.That(_pawn.XCoordinate, Is.EqualTo(6));
     Assert.That(_pawn.YCoordinate, Is.EqualTo(1));
 }
示例#4
0
 public void _01_placing_the_black_pawn_on_X_equals_6_and_Y_equals_3_should_place_the_black_pawn_on_that_place_on_the_board()
 {
     _chessBoard.Add(_pawn, 6, 3, PieceColor.Black);
     Assert.That(_pawn.XCoordinate, Is.EqualTo(6));
     Assert.That(_pawn.YCoordinate, Is.EqualTo(3));
 }
示例#5
0
        /// <summary>
        /// Moves the piece in the Chess board
        /// </summary>
        /// <param name="movementType"></param>
        /// <param name="newX"></param>
        /// <param name="newY"></param>
        public override void Move(MovementType movementType, int newX, int newY)
        {
            Logger.LogMessage(string.Format("Pawn at current location of {0},{1} is doing a movement type of {2} to {3}, {4}", XCoordinate, YCoordinate, movementType.ToString(), newX, newY), LogLevel.info);

            try
            {
                //first determine if the new position is valid
                //I am using the chessboard method to determine if the new X and Y are located on the
                //chess board
                if (_chessBoard.IsLegalBoardPosition(newX, newY))
                {
                    //determine legal moves for move vs capture
                    switch (movementType)
                    {
                    case MovementType.Move:

                        //verify that the x move is correct
                        if (!VerifyXMove(newX))
                        {
                            Logger.LogMessage("the new x coordinate is incorrect " + newX, LogLevel.error);
                            //don't do the move
                            return;
                        }

                        //verify that the Y move is correct
                        if (!VerifyYMove(newY))
                        {
                            Logger.LogMessage("the new y coordinate is incorrect " + newY, LogLevel.error);
                            //don't do the move
                            return;
                        }
                        break;

                    //in this case Pawns can only move diagonally
                    case MovementType.Capture:
                        if (!VerifyDiagonalMove(newX, newY))
                        {
                            Logger.LogMessage("the new x  " + newX + " or y coordinate is incorrect " + newY, LogLevel.error);
                            return;
                        }
                        break;

                    case MovementType.Special:
                        if (!VerifySpecialMove(newX, newY))
                        {
                            Logger.LogMessage("the new x  " + newX + " or y coordinate is incorrect " + newY, LogLevel.error);
                            return;
                        }
                        break;

                    default:

                        break;
                    }

                    this.XCoordinate = newX;
                    this.YCoordinate = newY;

                    _chessBoard.Add(this, this.XCoordinate, this.YCoordinate, this.PieceColor);
                }
                else
                {
                    string result = string.Format("Not an acceptable move X: {0} Y: {1}", newX, newY);
                    Logger.LogMessage(result, LogLevel.error);
                }
            }
            catch (Exception ex)
            {
                Logger.LogMessage("An exception occurred" + ex.Message, LogLevel.error);
            }
        }