Expose game start fen and game move history

This commit is contained in:
Sebastian Lague 2023-07-24 23:09:12 +02:00
parent 188f6f8d3a
commit 46ae3c2e20
2 changed files with 26 additions and 12 deletions

View file

@ -51,6 +51,9 @@ namespace ChessChallenge.API
GameRepetitionHistory = repetitionHistory.ToArray(); GameRepetitionHistory = repetitionHistory.ToArray();
GameRepetitionHistory.Reverse(); GameRepetitionHistory.Reverse();
repetitionHistory.Remove(board.ZobristKey); repetitionHistory.Remove(board.ZobristKey);
// Init game moves history
GameMoveHistory = board.AllGameMoves.Select(m => new Move(MoveUtility.GetMoveNameUCI(m), this)).ToArray();
} }
/// <summary> /// <summary>
@ -262,11 +265,11 @@ namespace ChessChallenge.API
/// </summary> /// </summary>
public string GetFenString() => FenUtility.CurrentFen(board); public string GetFenString() => FenUtility.CurrentFen(board);
/// <summary> /// <summary>
/// 64-bit number where each bit that is set to 1 represents a /// 64-bit number where each bit that is set to 1 represents a
/// square that contains a piece of the given type and colour. /// square that contains a piece of the given type and colour.
/// </summary> /// </summary>
public ulong GetPieceBitboard(PieceType pieceType, bool white) public ulong GetPieceBitboard(PieceType pieceType, bool white)
{ {
return board.pieceBitboards[PieceHelper.MakePiece((int)pieceType, white)]; return board.pieceBitboards[PieceHelper.MakePiece((int)pieceType, white)];
} }
@ -305,13 +308,24 @@ namespace ChessChallenge.API
public ulong ZobristKey => board.ZobristKey; public ulong ZobristKey => board.ZobristKey;
/// <summary> /// <summary>
/// Zobrist keys for all the positions played in the game so far. This is reset whenever a pawn move or /// Zobrist keys for all the positions played in the game so far. This is reset whenever a
/// capture is made, as previous positions are now impossible to reach again. /// pawn move or capture is made, as previous positions are now impossible to reach again.
/// Note that this is not updated when your bot makes moves on the board during its search, but only when /// Note that this is not updated when your bot makes moves on the board while thinking,
/// moves are actually played in the game. /// but rather only when moves are actually played in the game.
/// </summary> /// </summary>
public ulong[] GameRepetitionHistory { get; private set; } public ulong[] GameRepetitionHistory { get; private set; }
/// <summary>
/// FEN representation of the game's starting position.
/// </summary>
public string GameStartFenString => board.GameStartFen;
/// <summary>
/// All the moves played in the game so far.
/// This only includes moves played in the actual game, not moves made on the board while the bot is thinking.
/// </summary>
public Move[] GameMoveHistory { get; private set; }
/// <summary> /// <summary>
/// Creates a board from the given fen string. Please note that this is quite slow, and so it is advised /// Creates a board from the given fen string. Please note that this is quite slow, and so it is advised
/// to use the board given in the Think function, and update it using MakeMove and UndoMove instead. /// to use the board given in the Think function, and update it using MakeMove and UndoMove instead.

View file

@ -76,10 +76,10 @@ namespace ChessChallenge.Chess
LoadPosition(fen); LoadPosition(fen);
RepetitionPositionHistory = new(source.RepetitionPositionHistory); RepetitionPositionHistory = new(source.RepetitionPositionHistory);
//AllGameMoves = new(source.AllGameMoves); AllGameMoves = new(source.AllGameMoves);
//Console.WriteLine(source.gameStateHistory.Count);
//gameStateHistory = new(source.gameStateHistory);
currentGameState = source.currentGameState; currentGameState = source.currentGameState;
} }
} }