V1.1 fix GetPiece function and add CreateBoardFromFen
This commit is contained in:
parent
951ac24ae9
commit
24fa340cc9
4 changed files with 33 additions and 25 deletions
|
@ -13,7 +13,6 @@ namespace ChessChallenge.API
|
||||||
readonly HashSet<ulong> repetitionHistory;
|
readonly HashSet<ulong> repetitionHistory;
|
||||||
readonly PieceList[] allPieceLists;
|
readonly PieceList[] allPieceLists;
|
||||||
readonly PieceList[] validPieceLists;
|
readonly PieceList[] validPieceLists;
|
||||||
readonly Piece[] pieces;
|
|
||||||
|
|
||||||
Move[] cachedLegalMoves;
|
Move[] cachedLegalMoves;
|
||||||
bool hasCachedMoves;
|
bool hasCachedMoves;
|
||||||
|
@ -47,14 +46,6 @@ namespace ChessChallenge.API
|
||||||
// Init rep history
|
// Init rep history
|
||||||
repetitionHistory = new HashSet<ulong>(board.RepetitionPositionHistory);
|
repetitionHistory = new HashSet<ulong>(board.RepetitionPositionHistory);
|
||||||
repetitionHistory.Remove(board.ZobristKey);
|
repetitionHistory.Remove(board.ZobristKey);
|
||||||
|
|
||||||
// Create piece array
|
|
||||||
pieces = new Piece[64];
|
|
||||||
for (int i = 0; i < 64; i++)
|
|
||||||
{
|
|
||||||
int p = board.Square[i];
|
|
||||||
pieces[i] = new Piece((PieceType)PieceHelper.PieceType(p), PieceHelper.IsWhite(p), new Square(i));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -196,7 +187,9 @@ namespace ChessChallenge.API
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Piece GetPiece(Square square)
|
public Piece GetPiece(Square square)
|
||||||
{
|
{
|
||||||
return pieces[square.Index];
|
int p = board.Square[square.Index];
|
||||||
|
bool white = PieceHelper.IsWhite(p);
|
||||||
|
return new Piece((PieceType)PieceHelper.PieceType(p), white, square);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -271,5 +264,16 @@ namespace ChessChallenge.API
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ulong ZobristKey => board.ZobristKey;
|
public ulong ZobristKey => board.ZobristKey;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
public static Board CreateBoardFromFEN(string fen)
|
||||||
|
{
|
||||||
|
Chess.Board boardCore = new Chess.Board();
|
||||||
|
boardCore.LoadPosition(fen);
|
||||||
|
return new Board(boardCore);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -55,6 +55,7 @@ namespace ChessChallenge.Application
|
||||||
|
|
||||||
public ChallengeController()
|
public ChallengeController()
|
||||||
{
|
{
|
||||||
|
Log($"Launching Chess-Challenge version {Settings.Version}");
|
||||||
tokenCount = GetTokenCount();
|
tokenCount = GetTokenCount();
|
||||||
Warmer.Warm();
|
Warmer.Warm();
|
||||||
|
|
||||||
|
@ -228,8 +229,7 @@ namespace ChessChallenge.Application
|
||||||
{
|
{
|
||||||
moveToPlay = chosenMove;
|
moveToPlay = chosenMove;
|
||||||
isWaitingToPlayMove = true;
|
isWaitingToPlayMove = true;
|
||||||
const float minDelay = 0.1f;
|
playMoveTime = lastMoveMadeTime + MinMoveDelay;
|
||||||
playMoveTime = lastMoveMadeTime + minDelay;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,10 +4,14 @@ namespace ChessChallenge.Application
|
||||||
{
|
{
|
||||||
public static class Settings
|
public static class Settings
|
||||||
{
|
{
|
||||||
|
public const string Version = "1.1";
|
||||||
|
|
||||||
public const int GameDurationMilliseconds = 60 * 1000;
|
public const int GameDurationMilliseconds = 60 * 1000;
|
||||||
public const int MaxTokenCount = 1024;
|
public const float MinMoveDelay = 0;
|
||||||
public static readonly bool RunBotsOnSeparateThread = true;
|
public static readonly bool RunBotsOnSeparateThread = true;
|
||||||
|
|
||||||
|
public const int MaxTokenCount = 1024;
|
||||||
|
|
||||||
public const LogType MessagesToLog = LogType.All;
|
public const LogType MessagesToLog = LogType.All;
|
||||||
|
|
||||||
public static readonly Vector2 ScreenSizeSmall = new(1280, 720);
|
public static readonly Vector2 ScreenSizeSmall = new(1280, 720);
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace ChessChallenge.Application
|
||||||
public static class TokenCounter
|
public static class TokenCounter
|
||||||
{
|
{
|
||||||
|
|
||||||
static HashSet<SyntaxKind> tokensToIgnore = new(new SyntaxKind[]
|
static readonly HashSet<SyntaxKind> tokensToIgnore = new(new SyntaxKind[]
|
||||||
{
|
{
|
||||||
SyntaxKind.PrivateKeyword,
|
SyntaxKind.PrivateKeyword,
|
||||||
SyntaxKind.PublicKeyword,
|
SyntaxKind.PublicKeyword,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue