Exemplo n.º 1
0
    // default constructor
    public GameState(GameState previousState, ChessMove lastMove)
    {
        if (previousState == null) // set GameState values for start of game
        {
            // initialize castling flags
            wCanCastle00  = true;
            wCanCastle000 = true;
            bCanCastle00  = true;
            bCanCastle000 = true;

            // check to see if we have first move
            if (lastMove == null)
            {
                // set default values
                enPassant       = -1;
                hundredMoveDraw = 0;
                theLastMove     = new ChessMove();
            }
            else
            {
                // get en passant target square
                enPassant = lastMove.GetEnPassant();

                // check for pawn advancement, pawn promotion, or capture since last GameState
                hundredMoveDraw = lastMove.GetHundredDrawUpdate(0);

                // update theLastMove
                theLastMove = lastMove;
            }
        }
        else // set GameState values for non-starting game position
        {
            // update castling flags
            wCanCastle00  = lastMove.GetWCastle00(previousState.wCanCastle00);
            wCanCastle000 = lastMove.GetWCastle000(previousState.wCanCastle000);
            bCanCastle00  = lastMove.GetBCastle00(previousState.bCanCastle00);
            bCanCastle000 = lastMove.GetBCastle000(previousState.bCanCastle000);

            // get en passant target square
            enPassant = lastMove.GetEnPassant();

            // check for pawn advancement, pawn promotion, or capture since last GameState
            hundredMoveDraw = lastMove.GetHundredDrawUpdate(previousState.hundredMoveDraw);

            // update theLastMove
            theLastMove = lastMove;
        }

        // set state FEN
        state_fen = AI.board.GetFENString();
    }