public SokobanIDAstarStrategy(int maxNodes, int tableSize, int maxDepth, double epsilon) { this.maxNodes = maxNodes; this.tableSize = tableSize; this.maxDepth = maxDepth; this.epsilon = epsilon; idaStar = new IDAStarSearch(); }
private static void SokobanIDAStarTest(string levelPath, int maxCost, RewardType rewardType, int maxTableSize, bool useNormalizedPosition, bool useTunnelMacro, bool useGoalMacro, bool useGoalCut) { string[] levels = ReadSokobanLevels(levelPath); IPuzzleState[] states = new IPuzzleState[levels.Length]; int solvedLevels = 0; Stopwatch stopwatch = new Stopwatch(); long stateInitTime; long solvingTime; //GoalMacroWrapper.BuildMacroTree(null); for (int i = 0; i < states.Length; i++) { stopwatch.Restart(); states[i] = new AbstractSokobanState(levels[i], rewardType, useNormalizedPosition, useGoalMacro, useTunnelMacro, useGoalCut, null); stopwatch.Stop(); stateInitTime = stopwatch.ElapsedMilliseconds; IDAStarSearch idaStar = new IDAStarSearch(); //Log("Level" + (i + 1) + ":\n" + states[i].PrettyPrint()); stopwatch.Restart(); List <IPuzzleMove> solution = idaStar.Solve(states[i], maxCost, maxTableSize, 700); stopwatch.Stop(); solvingTime = stopwatch.ElapsedMilliseconds; string moves = ""; int pushCount = 0; if (solution != null) { foreach (IPuzzleMove m in solution) { //Debug.WriteLine(states[i]); //Debug.WriteLine(m); SokobanPushMove push = (SokobanPushMove)m; foreach (IPuzzleMove basicMove in push.MoveList) { moves += basicMove; if (basicMove.move > 3)//the move is a push move { pushCount++; } } states[i].DoMove(m); } if (states[i].EndState()) { solvedLevels++; } Log("Level " + (i + 1) + " solved: " + (states[i].EndState()) + " with " + idaStar.NodeCount + " nodes; solution length:" + moves.Count() + "/" + pushCount + " - Init Time: " + TimeFormat(stateInitTime) + " - Solving Time: " + TimeFormat(solvingTime)); Log("Moves: " + moves); Log("Solved " + solvedLevels + "/" + (i + 1)); Console.Write("\rSolved " + solvedLevels + "/" + (i + 1)); } } }
private static void SamegameIDAStarTest(string levelPath, int maxCost, int tableSize)//TODO Need a good heuristic for samegame { string[] levels = ReadSamegameLevels(levelPath); IPuzzleState[] states = new IPuzzleState[levels.Length]; int solvedLevels = 0; double totalScore = 0; for (int i = 0; i < states.Length; i++) { states[i] = new SamegameGameState(levels[i], null, null); IDAStarSearch idaStar = new IDAStarSearch(); Log("Level" + (i + 1) + ":\n" + states[i].PrettyPrint()); List <IPuzzleMove> solution = null; string moves = ""; while (!states[i].isTerminal()) { solution = idaStar.Solve(states[i], maxCost, tableSize, 100); if (solution.Count > 0) { moves += solution[0]; states[i].DoMove(solution[0]); } else { break; } } if (states[i].EndState()) { solvedLevels++; } totalScore += states[i].GetResult(); Log("Level " + (i + 1) + " solved: " + (states[i].EndState()) + " solution length:" + moves.Count() + " Score: " + states[i].GetResult()); Log("Moves: " + moves); Log("Solved " + solvedLevels + "/" + (i + 1)); Console.Write("\rSolved " + solvedLevels + "/" + (i + 1)); } Log("Total score: " + totalScore); }