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 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 AIPlayer(string name, Guid globalId) { _logger.Debug($"AI player constructor called with name = {name}, GUID = {globalId}"); GlobalId = globalId.Equals(Guid.Empty) ? Guid.NewGuid() : globalId; Name = name; CanUndoMoves = false; Solver = new AISolver(true); }
private void TestApplyMove(string input, AIMove move, string output) { var grid = GridTests.CreateGrid(input, 0); var solver = new AISolver(grid, new AISettings()); var grid2 = solver.GetGridWithMove(grid.ToIntArray(), move); Assert.AreEqual(output.ToLower().Trim(), Grid.ToString(grid2, true)); }
private void TestGetMoves(string gridString, int expectedMoves) { var grid = GridTests.CreateGrid(gridString, 0); var solver = new AISolver(grid, new AISettings() { maxDepth = 1, pickNotTheBestProbability = 0f }); var moves = solver.GetMoves(0, grid.ToIntArray(), 0, grid.width, null); Assert.AreEqual(expectedMoves, moves.Count); }
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); }
private void TestWeightMoves(string gridString, bool hasWeight) { var grid = GridTests.CreateGrid(gridString, 0); var solver = new AISolver(grid, new AISettings() { maxDepth = 1, pickNotTheBestProbability = 0f }); var moves = solver.GetWeightedMoves(0, 0, grid.ToIntArray(), 0, grid.width, null); if (hasWeight) { Assert.AreNotEqual(0, moves.Count); Assert.True(moves.Any(m => m.weight > 0)); } else { Assert.False(moves.Any(m => m.weight > 0)); } }