diff --git a/Chess-Challenge/src/API/Board.cs b/Chess-Challenge/src/API/Board.cs index 094a284..52c86d6 100644 --- a/Chess-Challenge/src/API/Board.cs +++ b/Chess-Challenge/src/API/Board.cs @@ -13,7 +13,6 @@ namespace ChessChallenge.API readonly HashSet repetitionHistory; readonly PieceList[] allPieceLists; readonly PieceList[] validPieceLists; - readonly Piece[] pieces; Move[] cachedLegalMoves; bool hasCachedMoves; @@ -47,14 +46,6 @@ namespace ChessChallenge.API // Init rep history repetitionHistory = new HashSet(board.RepetitionPositionHistory); 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)); - } } /// @@ -191,18 +182,20 @@ namespace ChessChallenge.API return new Square(board.KingSquare[colIndex]); } - /// - /// Gets the piece on the given square. If the square is empty, the piece will have a PieceType of None. - /// - public Piece GetPiece(Square square) - { - return pieces[square.Index]; - } + /// + /// Gets the piece on the given square. If the square is empty, the piece will have a PieceType of None. + /// + public Piece GetPiece(Square square) + { + int p = board.Square[square.Index]; + bool white = PieceHelper.IsWhite(p); + return new Piece((PieceType)PieceHelper.PieceType(p), white, square); + } - /// - /// Gets a list of pieces of the given type and colour - /// - public PieceList GetPieceList(PieceType pieceType, bool white) + /// + /// Gets a list of pieces of the given type and colour + /// + public PieceList GetPieceList(PieceType pieceType, bool white) { return allPieceLists[PieceHelper.MakePiece((int)pieceType, white)]; } @@ -271,5 +264,16 @@ namespace ChessChallenge.API /// public ulong ZobristKey => board.ZobristKey; - } + /// + /// 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. + /// + public static Board CreateBoardFromFEN(string fen) + { + Chess.Board boardCore = new Chess.Board(); + boardCore.LoadPosition(fen); + return new Board(boardCore); + } + + } } \ No newline at end of file diff --git a/Chess-Challenge/src/Framework/Application/Core/ChallengeController.cs b/Chess-Challenge/src/Framework/Application/Core/ChallengeController.cs index b9be8cd..f27ed51 100644 --- a/Chess-Challenge/src/Framework/Application/Core/ChallengeController.cs +++ b/Chess-Challenge/src/Framework/Application/Core/ChallengeController.cs @@ -55,6 +55,7 @@ namespace ChessChallenge.Application public ChallengeController() { + Log($"Launching Chess-Challenge version {Settings.Version}"); tokenCount = GetTokenCount(); Warmer.Warm(); @@ -228,8 +229,7 @@ namespace ChessChallenge.Application { moveToPlay = chosenMove; isWaitingToPlayMove = true; - const float minDelay = 0.1f; - playMoveTime = lastMoveMadeTime + minDelay; + playMoveTime = lastMoveMadeTime + MinMoveDelay; } else { diff --git a/Chess-Challenge/src/Framework/Application/Core/Settings.cs b/Chess-Challenge/src/Framework/Application/Core/Settings.cs index b03ff30..f924ff4 100644 --- a/Chess-Challenge/src/Framework/Application/Core/Settings.cs +++ b/Chess-Challenge/src/Framework/Application/Core/Settings.cs @@ -4,10 +4,14 @@ namespace ChessChallenge.Application { public static class Settings { + public const string Version = "1.1"; + public const int GameDurationMilliseconds = 60 * 1000; - public const int MaxTokenCount = 1024; + public const float MinMoveDelay = 0; public static readonly bool RunBotsOnSeparateThread = true; + public const int MaxTokenCount = 1024; + public const LogType MessagesToLog = LogType.All; public static readonly Vector2 ScreenSizeSmall = new(1280, 720); diff --git a/Chess-Challenge/src/Framework/Application/Helpers/Token Counter/TokenCounter.cs b/Chess-Challenge/src/Framework/Application/Helpers/Token Counter/TokenCounter.cs index f45ce27..27d2a72 100644 --- a/Chess-Challenge/src/Framework/Application/Helpers/Token Counter/TokenCounter.cs +++ b/Chess-Challenge/src/Framework/Application/Helpers/Token Counter/TokenCounter.cs @@ -7,7 +7,7 @@ namespace ChessChallenge.Application public static class TokenCounter { - static HashSet tokensToIgnore = new(new SyntaxKind[] + static readonly HashSet tokensToIgnore = new(new SyntaxKind[] { SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword,