public HeatingSearcher(Map map) { this.original = map; this.hMapPrev = new HeatMap(original, 300f); this.hMapFol = new HeatMap(original, 300f); this.heatedBlocks = new Queue <HeatMap.Block>(); }
public Map Solve() { heatedBlocks.Enqueue(hMapPrev.startBlock); double indexTime = 0f; double calcuTime = 0f; bool foundGoal = false; int count = 0; while (true) { count++; for (int i = 0; i < hMapPrev.blocks.Count; i++) { double t1 = Timer.ElapsedMilliSec(); var prev = hMapPrev.blocks[i]; var fol = hMapFol.blocks[i]; double t2 = Timer.ElapsedMilliSec(); indexTime += t2 - t1; bool transferredFirst = Mathf.gatherHeat(prev, fol); if (transferredFirst) { heatedBlocks.Enqueue(fol); // 入れるものは、PrevのとFolのとで、交互になるが、ルート生成時には距離で判断するので、多分問題にはならない if (fol.isGoal) { // 修了する foundGoal = true; goto FINISHED; } } double t3 = Timer.ElapsedMilliSec(); calcuTime += t3 - t2; } // 反転させる var tmpMap = hMapPrev; hMapPrev = hMapFol; hMapFol = tmpMap; } FINISHED :; Console.WriteLine("結果報告"); Console.WriteLine(" 総フレーム数: " + count); Console.WriteLine(" インデクス: " + indexTime / (double)count); Console.WriteLine(" 計算: " + calcuTime / (double)count); if (foundGoal) { Console.WriteLine("経路を求められました."); var heatedBlocks = this.heatedBlocks.ToArray(); HeatMap.Block lastBlock = heatedBlocks[heatedBlocks.Length - 1]; for (int i = heatedBlocks.Length - 2; i >= 0; i--) { var block = heatedBlocks[i]; if ((lastBlock.pos - block.pos).SqrDistance == 1) { original[block.pos.x, block.pos.y] = Map.ROUTE; lastBlock = block; } } return(original); } else { Console.WriteLine("経路を求められませんでした.\n作業内容を表示します.\n"); Dump(); return(null); } }