private Grid CreateGridTest(string gridString, int depth, int minLines) { var grid = GridTests.CreateGrid(gridString, 0); Assert.NotNull(grid); grid.Print(); var solver = new AISolver(grid, new AISettings() { maxDepth = depth, pickNotTheBestProbability = 0f, minLinesBeforeSpeed = minLines }); solver.Work(); Assert.AreNotEqual(0, solver.Moves.Count, "Solver found no moves"); foreach (var m in solver.Moves) { grid.Move(grid.Get(m.x, m.y), m.direction); } for (var i = 0f; i < 10f; i += 0.05f) { grid.Update(0f, 0.05f); } grid.Print(); return(grid); }
public void TestConsistency() { var gs = "1 0 0\n" + "2 0 3\n" + "2 0 3\n" + "3 0 2\n" + "3 0 2\n" + "1 0 1"; var grid = GridTests.CreateGrid(gs, 0); Assert.NotNull(grid); grid.Print(); var solver = new AISolver(grid, new AISettings() { maxDepth = 1, pickNotTheBestProbability = 0f, minLinesBeforeSpeed = 0 }); solver.Work(); Assert.AreNotEqual(0, solver.Moves.Count, "Solver found no moves"); foreach (var m in solver.Moves) { Debug.Log("Move " + m); grid.Move(grid.Get(m.x, m.y), m.direction); for (var i = 0f; i < 10f; i += 0.05f) { grid.Update(0f, 0.05f); } var g1 = Grid.ToString(grid.ToIntArray()); var g2 = Grid.ToString(m.gridAfterMove); if (g1.StartsWith("0 0 0 \n")) { g1 = g1.Replace("0 0 0 \n", ""); } if (g1.EndsWith("0 0 0 \n")) { g1 = g1.Replace("0 0 0 \n", ""); } if (g2.StartsWith("0 0 0 \n")) { g2 = g2.Replace("0 0 0 \n", ""); } if (g2.EndsWith("0 0 0 \n")) { g1 = g1.Replace("0 0 0 \n", ""); } Debug.Log("COMPARE\n" + g1 + "VS\n" + g2); Assert.AreEqual(g1, g2, "Grid after moves are different!"); } }
private AISolver SolveTestGrid(string gridString, int depth, int minLines = 0) { var grid = GridTests.CreateGrid(gridString, 0); Assert.NotNull(grid); var solver = new AISolver(grid, new AISettings() { maxDepth = depth, pickNotTheBestProbability = 0f, minLinesBeforeSpeed = minLines }); solver.Work(); return(solver); }