Ejemplo n.º 1
0
        private void UpdateState(Move move, ulong startSquare, ulong endSquare)
        {
            var newState       = GameStateMutator.ApplyMove(CurrentState, move, startSquare, endSquare);
            var opponentPieces = (endSquare & newState.Board.WhitePieces) != 0
                ? newState.Board.BlackPieces : newState.Board.WhitePieces;

            newState = AnalyzeAndApplyState(newState, endSquare, opponentPieces);

            CurrentState = newState;
            CurrentTurn  = opponentPieces;

            History.Push(newState);
        }
Ejemplo n.º 2
0
        private static bool WillMovePlaceKingUnderAttack(GameState state, ulong square, ulong targetMove)
        {
            // Try the move and see if it lands in check
            // TODO: Use a stateful 'squares attacked by' approach to do this better
            var newState = GameStateMutator.ApplyMove(state, square, targetMove);
            var newBoard = newState.Board;

            var ownPieces         = (newBoard.WhitePieces & targetMove) != 0 ? newBoard.WhitePieces : newBoard.BlackPieces;
            var opposingPieces    = newBoard.AllPieces & ~ownPieces;
            var opposingAttack    = GenerateSquaresAttackedBy(newState, opposingPieces);
            var isKingUnderAttack = opposingAttack & (ownPieces & newBoard.Kings);

            return(isKingUnderAttack != 0);
        }