diff --git a/MiniAiCup.Paperio.Core/BestTrajectoryFinder.cs b/MiniAiCup.Paperio.Core/BestTrajectoryFinder.cs index 89c0c95..952acf4 100644 --- a/MiniAiCup.Paperio.Core/BestTrajectoryFinder.cs +++ b/MiniAiCup.Paperio.Core/BestTrajectoryFinder.cs @@ -31,12 +31,14 @@ public GameStateInternal FindBestState(GameStateInternal initialState) } var simulationQueue = new Queue<(GameStateInternal State, int Depth)>(); - var finalSimulations = new List(); simulationQueue.Enqueue((initialState, 0)); int startTickNumber = initialState.TickNumber; + GameStateInternal bestState = null; + int bestScore = Int32.MinValue; + while (simulationQueue.Count > 0) { (var currentState, int currentDepth) = simulationQueue.Dequeue(); @@ -50,7 +52,12 @@ public GameStateInternal FindBestState(GameStateInternal initialState) } if (currentDepth == depth - 1) { - finalSimulations.Add(nextState); + int score = _scorer.Score(nextState); + if (score > bestScore) + { + bestScore = score; + bestState = nextState; + } } else { @@ -59,18 +66,6 @@ public GameStateInternal FindBestState(GameStateInternal initialState) } } - GameStateInternal bestState = null; - int bestScore = Int32.MinValue; - foreach (var state in finalSimulations) - { - int score = _scorer.Score(state); - if (score > bestScore) - { - bestScore = score; - bestState = state; - } - } - return bestState; } }