Esempio n. 1
0
        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!");
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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));
            }
        }