Exemplo n.º 1
0
        private GameState GetNewGameState(GameState gameState, int piecePosition, StateInfo stateInfo, int newPiecePosition)
        {
            var transitionGameState = manageSquares(gameState, stateInfo, piecePosition, newPiecePosition);

            if (stateInfo.IsCastle)
            {
                var rookPositions = CastlingEngine.GetRookPositionsForCastle(gameState.ActiveColor, piecePosition, newPiecePosition);
                transitionGameState = manageSquares(transitionGameState, stateInfo, rookPositions.RookPos, rookPositions.NewRookPos);
            }
            if (stateInfo.IsEnPassant)
            {
                //remove the attacked pawn
                var enPassantAttackedPawnPosition = gameState.ActiveColor == Color.White ? newPiecePosition - 8 : newPiecePosition + 8;
                var enPassantAttackedPawnSquare   = transitionGameState.Squares.GetSquare(enPassantAttackedPawnPosition);
                enPassantAttackedPawnSquare.Piece = null;
            }
            _notationService.SetGameStateSnapshot(gameState, transitionGameState, stateInfo, piecePosition, newPiecePosition);

            var fenRecords       = gameState.History.DeepCopy();
            var previousStateFEN = gameState.ToString();

            fenRecords.Add(FenFactory.Create(previousStateFEN));
            transitionGameState.History = fenRecords;

            return(transitionGameState);
        }
Exemplo n.º 2
0
        public OperationResult <GameState> Initialize(string fen)
        {
            if (string.IsNullOrEmpty(fen))
            {
                fen = GeneralReference.Starting_FEN_Position;
            }
            var fenRecord = FenFactory.Create(fen);

            if (fenRecord == null)
            {
                OperationResult <GameState> .Fail("Bad fen.");
            }
            return(hydrateGameState(new GameState(fenRecord)));
        }
Exemplo n.º 3
0
 public override string ToString()
 {
     return(FenFactory.Create(this));
 }