示例#1
0
        /// <summary>
        /// Checks to see if the move made violates any of the players castling possibilities, and updates the
        /// this.gameBoard accordingly
        /// </summary>
        private void updateCastleingPossibilities()
        {
            if (liftedPiece.getType() == pieceType.rook)
            {
                if (liftedFrom == InitialPieceLocations.rightRookInitialPosition(liftedPiece.getColour()))
                {
                    if (liftedPiece.getColour() == pieceColour.light)
                    {
                        gameBoard.setCanLightCastleKingSide(false);
                    }
                    else
                    {
                        gameBoard.setCanDarkCastleKingSide(false);
                    }
                }
                else if (liftedFrom == InitialPieceLocations.leftRookInitialPosition(liftedPiece.getColour()))
                {
                    if (liftedPiece.getColour() == pieceColour.light)
                    {
                        gameBoard.setCanLightCastleQueenSide(false);
                    }

                    else
                    {
                        gameBoard.setCanDarkCastleQueenSide(false);
                    }
                }
            }
            else if (liftedPiece.getType() == pieceType.king)
            {
                if (liftedFrom == InitialPieceLocations.kingInitialPosition(liftedPiece.getColour()))
                {
                    if (liftedPiece.getColour() == pieceColour.light)
                    {
                        gameBoard.setCanLightCastleKingSide(false);
                        gameBoard.setCanLightCastleQueenSide(false);
                    }
                    else
                    {
                        gameBoard.setCanDarkCastleKingSide(false);
                        gameBoard.setCanDarkCastleQueenSide(false);
                    }
                }
            }
        }
示例#2
0
 /// <summary>
 /// Checks to see if the attemptedMove was a castle. If it is, moves the rook accordingly
 /// </summary>
 /// <param name="attemptedMove">The move made</param>
 private void checkForAndApplyCastle(ChessMove attemptedMove)
 {
     if (liftedPiece.getType() == pieceType.king)
     {
         if (liftedFrom == InitialPieceLocations.kingInitialPosition(attemptedMove.piece.getColour()))
         {
             if (attemptedMove.final == InitialPieceLocations.rightKnightInitialPosition(attemptedMove.piece.getColour()))//castling kingside
             {
                 ChessPiece LiftedRook = gameBoard.getSquare(InitialPieceLocations.rightRookInitialPosition(attemptedMove.piece.getColour())).liftPiece();
                 gameBoard.getSquare(InitialPieceLocations.rightBishopInitialPosition(attemptedMove.piece.getColour())).placePiece(LiftedRook);
             }
             else if (attemptedMove.final == InitialPieceLocations.leftBishopInitialPosition(attemptedMove.piece.getColour()))//castling queenside
             {
                 ChessPiece LiftedRook = gameBoard.getSquare(InitialPieceLocations.leftRookInitialPosition(attemptedMove.piece.getColour())).liftPiece();
                 gameBoard.getSquare(InitialPieceLocations.queenInitialPosition(attemptedMove.piece.getColour())).placePiece(LiftedRook);
             }
         }
     }
 }
示例#3
0
        /// <summary>
        /// Sets all pieces to their initial locations on the board and clears all other locations
        /// </summary>
        private void setInitialBoardState()
        {
            this.gameBoard.getSquare(InitialPieceLocations.leftRookInitialPosition(pieceColour.light)).placePiece(new Rook(pieceColour.light));
            this.gameBoard.getSquare(InitialPieceLocations.leftKnightInitialPosition(pieceColour.light)).placePiece(new Knight(pieceColour.light));
            this.gameBoard.getSquare(InitialPieceLocations.leftBishopInitialPosition(pieceColour.light)).placePiece(new Bishop(pieceColour.light));
            this.gameBoard.getSquare(InitialPieceLocations.queenInitialPosition(pieceColour.light)).placePiece(new Queen(pieceColour.light));
            this.gameBoard.getSquare(InitialPieceLocations.kingInitialPosition(pieceColour.light)).placePiece(new King(pieceColour.light));
            this.gameBoard.getSquare(InitialPieceLocations.rightBishopInitialPosition(pieceColour.light)).placePiece(new Bishop(pieceColour.light));
            this.gameBoard.getSquare(InitialPieceLocations.rightKnightInitialPosition(pieceColour.light)).placePiece(new Knight(pieceColour.light));
            this.gameBoard.getSquare(InitialPieceLocations.rightRookInitialPosition(pieceColour.light)).placePiece(new Rook(pieceColour.light));

            this.gameBoard.getSquare(StaticBoardLocations.A2).placePiece(new Pawn(pieceColour.light));
            this.gameBoard.getSquare(StaticBoardLocations.B2).placePiece(new Pawn(pieceColour.light));
            this.gameBoard.getSquare(StaticBoardLocations.C2).placePiece(new Pawn(pieceColour.light));
            this.gameBoard.getSquare(StaticBoardLocations.D2).placePiece(new Pawn(pieceColour.light));
            this.gameBoard.getSquare(StaticBoardLocations.E2).placePiece(new Pawn(pieceColour.light));
            this.gameBoard.getSquare(StaticBoardLocations.F2).placePiece(new Pawn(pieceColour.light));
            this.gameBoard.getSquare(StaticBoardLocations.G2).placePiece(new Pawn(pieceColour.light));
            this.gameBoard.getSquare(StaticBoardLocations.H2).placePiece(new Pawn(pieceColour.light));

            this.gameBoard.getSquare(StaticBoardLocations.A3).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.B3).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.C3).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.D3).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.E3).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.F3).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.G3).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.H3).placePiece(null);

            this.gameBoard.getSquare(StaticBoardLocations.A4).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.B4).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.C4).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.D4).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.E4).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.F4).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.G4).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.H4).placePiece(null);

            this.gameBoard.getSquare(StaticBoardLocations.A5).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.B5).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.C5).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.D5).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.E5).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.F5).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.G5).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.H5).placePiece(null);

            this.gameBoard.getSquare(StaticBoardLocations.A6).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.B6).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.C6).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.D6).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.E6).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.F6).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.G6).placePiece(null);
            this.gameBoard.getSquare(StaticBoardLocations.H6).placePiece(null);

            this.gameBoard.getSquare(StaticBoardLocations.A7).placePiece(new Pawn(pieceColour.dark));
            this.gameBoard.getSquare(StaticBoardLocations.B7).placePiece(new Pawn(pieceColour.dark));
            this.gameBoard.getSquare(StaticBoardLocations.C7).placePiece(new Pawn(pieceColour.dark));
            this.gameBoard.getSquare(StaticBoardLocations.D7).placePiece(new Pawn(pieceColour.dark));
            this.gameBoard.getSquare(StaticBoardLocations.E7).placePiece(new Pawn(pieceColour.dark));
            this.gameBoard.getSquare(StaticBoardLocations.F7).placePiece(new Pawn(pieceColour.dark));
            this.gameBoard.getSquare(StaticBoardLocations.G7).placePiece(new Pawn(pieceColour.dark));
            this.gameBoard.getSquare(StaticBoardLocations.H7).placePiece(new Pawn(pieceColour.dark));

            this.gameBoard.getSquare(InitialPieceLocations.leftRookInitialPosition(pieceColour.dark)).placePiece(new Rook(pieceColour.dark));
            this.gameBoard.getSquare(InitialPieceLocations.leftKnightInitialPosition(pieceColour.dark)).placePiece(new Knight(pieceColour.dark));
            this.gameBoard.getSquare(InitialPieceLocations.leftBishopInitialPosition(pieceColour.dark)).placePiece(new Bishop(pieceColour.dark));
            this.gameBoard.getSquare(InitialPieceLocations.queenInitialPosition(pieceColour.dark)).placePiece(new Queen(pieceColour.dark));
            this.gameBoard.getSquare(InitialPieceLocations.kingInitialPosition(pieceColour.dark)).placePiece(new King(pieceColour.dark));
            this.gameBoard.getSquare(InitialPieceLocations.rightBishopInitialPosition(pieceColour.dark)).placePiece(new Bishop(pieceColour.dark));
            this.gameBoard.getSquare(InitialPieceLocations.rightKnightInitialPosition(pieceColour.dark)).placePiece(new Knight(pieceColour.dark));
            this.gameBoard.getSquare(InitialPieceLocations.rightRookInitialPosition(pieceColour.dark)).placePiece(new Rook(pieceColour.dark));

            this.turn = pieceColour.light;
        }