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); }
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))); }
public override string ToString() { return(FenFactory.Create(this)); }