diff --git a/Chess-Challenge/src/Framework/Application/Core/ChallengeController.cs b/Chess-Challenge/src/Framework/Application/Core/ChallengeController.cs index f27ed5101..4011b7317 100644 --- a/Chess-Challenge/src/Framework/Application/Core/ChallengeController.cs +++ b/Chess-Challenge/src/Framework/Application/Core/ChallengeController.cs @@ -50,13 +50,13 @@ public enum PlayerType // Other readonly BoardUI boardUI; readonly MoveGenerator moveGenerator; - readonly int tokenCount; + static int tokenCount; readonly StringBuilder pgns; public ChallengeController() { Log($"Launching Chess-Challenge version {Settings.Version}"); - tokenCount = GetTokenCount(); + UpdateTokenCount(); Warmer.Warm(); moveGenerator = new(); @@ -212,13 +212,16 @@ ChessPlayer CreatePlayer(PlayerType type) }; } - static int GetTokenCount() + public static void UpdateTokenCount(bool isHotReloadUpdate = false) { - string path = Path.Combine(Directory.GetCurrentDirectory(), "src", "My Bot", "MyBot.cs"); - - using StreamReader reader = new(path); - string txt = reader.ReadToEnd(); - return TokenCounter.CountTokens(txt); + var location = isHotReloadUpdate ? "../../../src/My Bot/MyBot.cs" : "src/My Bot/MyBot.cs"; + var path = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), location)); + if (!File.Exists(path)) + { + Log("Could not find MyBot.cs", true); + } + var txt = File.ReadAllText(path); + tokenCount = TokenCounter.CountTokens(txt); } void OnMoveChosen(Move chosenMove) diff --git a/Chess-Challenge/src/Framework/Application/Core/HotReloadmanager.cs b/Chess-Challenge/src/Framework/Application/Core/HotReloadmanager.cs new file mode 100644 index 000000000..ca0fbc9fe --- /dev/null +++ b/Chess-Challenge/src/Framework/Application/Core/HotReloadmanager.cs @@ -0,0 +1,14 @@ +using System; +using ChessChallenge.Application; + +[assembly: System.Reflection.Metadata.MetadataUpdateHandler(typeof(HotReloadmanager))] + +namespace ChessChallenge.Application; + +public static class HotReloadmanager +{ + public static void UpdateApplication(Type[]? updatedTypes) + { + ChallengeController.UpdateTokenCount(true); + } +} \ No newline at end of file