Example #1
0
 public PositionHistoryItem(
     Move.Move move,
     Option <int> enPassantCaptureColumn,
     CastlingAvailability whiteCastlingAvailability,
     CastlingAvailability blackCastlingAvailability)
 {
     Move = move;
     EnPassantCaptureColumn    = enPassantCaptureColumn;
     WhiteCastlingAvailability = whiteCastlingAvailability;
     BlackCastlingAvailability = blackCastlingAvailability;
 }
Example #2
0
        internal void UndoMove()
        {
            var stateToRestore = history.Last();

            history.RemoveAt(history.Count - 1);

            PlayerToMove = GetOtherPlayer(PlayerToMove);
            Board.UndoMove(stateToRestore.Move, PlayerToMove);
            EnPassantCaptureColumn    = stateToRestore.EnPassantCaptureColumn;
            whiteCastlingAvailability = stateToRestore.WhiteCastlingAvailability;
            blackCastlingAvailability = stateToRestore.BlackCastlingAvailability;
        }
Example #3
0
 public void SetCastlingAvailability(
     CastlingAvailability castlingAvailability,
     Player player)
 {
     if (player == Player.Black)
     {
         blackCastlingAvailability = castlingAvailability;
     }
     else
     {
         whiteCastlingAvailability = castlingAvailability;
     }
 }
Example #4
0
        private CastlingAvailability OptimizeCastlingAvailability(
            CastlingAvailability currentFlags,
            Player player)
        {
            if (!IsKingAtInitialSquare(player))
            {
                return(CastlingAvailability.None);
            }

            var canCastleShort = currentFlags.CanCastleShort &&
                                 IsRookAtInitialPositionForShortCastle(player);

            var canCastleLong = currentFlags.CanCastleLong &&
                                IsRookAtInitialPositionForLongCastle(player);

            return(new CastlingAvailability(canCastleShort, canCastleLong));
        }
Example #5
0
        internal Position(
            List <PieceOnBoard> pieces,
            Player playerToMove,
            CastlingAvailability whiteCastlingAvailability,
            CastlingAvailability blackCastlingAvailability,
            Option <int> enPassantCaptureColumn,
            int halfMoveClock,
            int fullMoveNumber)
        {
            Board                  = new Board.Board(pieces);
            PlayerToMove           = playerToMove;
            EnPassantCaptureColumn = enPassantCaptureColumn;
            HalfMoveClock          = halfMoveClock;
            FullMoveNumber         = fullMoveNumber;

            this.whiteCastlingAvailability = OptimizeCastlingAvailability(
                whiteCastlingAvailability,
                Player.White);

            this.blackCastlingAvailability = OptimizeCastlingAvailability(
                blackCastlingAvailability,
                Player.Black);
        }