From 92748475e3aa35f76d1322637f08f86d015eb5c9 Mon Sep 17 00:00:00 2001 From: Alexander Zheltov Date: Tue, 20 Aug 2019 04:43:17 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BF=D1=82=D0=B8=D0=BC=D0=B8=D0=B7?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20=D0=BF=D0=BE=D0=B8=D1=81?= =?UTF-8?q?=D0=BA=20=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=B3=D0=BE=20=D1=85?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0=20=D0=B2=20=D1=87=D0=B0=D1=81=D1=82=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=82=D1=80=D0=B5=D0=B1=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=B0=D0=BC=D1=8F=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BestTrajectoryFinder.cs | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) 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; } }