Пример #1
0
        public void GarbageFall7()
        {
            var grid = GridTests.CreateGrid(
                "x x x x 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 1 0 0 0\n0 0 4 0 0 0\n0 0 4 0 0\n1 2 2 1 0 0", 0);

            grid.Print();

            for (int i = 0; i < TIME_STEP; i++)
            {
                grid.Update(1f / TIME_STEP, 1f / TIME_STEP);
                // GridTests.Print(grid.ToIntArray());

                grid.Print();

                // Assert all garbages are ALWAYS aligned
                for (int y = 0; y < grid.height; y++)
                {
                    var b = grid.Get(0, y);
                    if (b != null && b.IsEmpty == false && b.Definition.isGarbage)
                    {
                        var debugMessage = "step " + i + " failed: ";

                        var right = b.Right;
                        while (right != null)
                        {
                            Assert.AreEqual(b.position.y, right.position.y,
                                            debugMessage + "POS= " + b.position.y + " != " + right.position.y);
                            Assert.AreEqual(b.y, right.y, debugMessage + "Y= " + b.y + " != " + right.y);

                            right = right.Right;
                        }
                    }
                }
            }
        }
Пример #2
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!");
            }
        }
Пример #3
0
        public void GarbageFall1()
        {
            var grid = GridTests.CreateGrid("x x x x\n0 x 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0", 0);

            grid.Print();

            Assert.NotNull(grid.Get(0, 4));
            Assert.NotNull(grid.Get(0, 3));
            Assert.NotNull(grid.Get(1, 3));

            Assert.False(grid.Get(0, 4).IsEmpty);
            Assert.True(grid.Get(0, 3).IsEmpty);
            Assert.False(grid.Get(1, 3).IsEmpty);

            for (int i = 0; i < 4 * TIME_STEP; i++)
            {
                grid.Update(0f, 1f / TIME_STEP);
            }

            grid.Print();

            Assert.NotNull(grid.Get(0, 1));
            Assert.NotNull(grid.Get(0, 0));
            Assert.NotNull(grid.Get(1, 0));

            Assert.False(grid.Get(0, 1).IsEmpty);
            Assert.True(grid.Get(0, 0).IsEmpty);
            Assert.False(grid.Get(1, 0).IsEmpty);
        }
Пример #4
0
        private void TestGetHighestY(string gridString, int expectedY)
        {
            var grid = GridTests.CreateGrid(gridString, 0).ToIntArray();
            var h    = new AIHeuristic();

            Assert.AreEqual(expectedY, h.GetHighest(grid).y);
        }
Пример #5
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);
        }
Пример #6
0
        public void GarbageFall2()
        {
            var grid = GridTests.CreateGrid("0 0 0 0\nx x x x\n0 x x 0\n0 x 0 0\n0 x x 0\n0 0 0 0\n0 0 0 0", 0);

            grid.Print();

            for (int i = 0; i < 6 * TIME_STEP; i++)
            {
                grid.Update(0f, 1f / TIME_STEP);
            }

            grid.Print();

            Assert.False(grid.Get(0, 3).IsEmpty);
            Assert.False(grid.Get(1, 3).IsEmpty);
            Assert.False(grid.Get(2, 3).IsEmpty);
            Assert.False(grid.Get(3, 3).IsEmpty);
            Assert.True(grid.Get(0, 2).IsEmpty);
            Assert.False(grid.Get(1, 2).IsEmpty);
            Assert.False(grid.Get(2, 2).IsEmpty);
            Assert.True(grid.Get(0, 2).IsEmpty);
            Assert.True(grid.Get(0, 1).IsEmpty);
            Assert.False(grid.Get(1, 1).IsEmpty);
            Assert.True(grid.Get(2, 1).IsEmpty);
            Assert.True(grid.Get(3, 1).IsEmpty);
            Assert.True(grid.Get(0, 0).IsEmpty);
            Assert.False(grid.Get(1, 0).IsEmpty);
            Assert.False(grid.Get(2, 0).IsEmpty);
            Assert.True(grid.Get(3, 0).IsEmpty);
        }
Пример #7
0
        public void GarbageFall6()
        {
            var grid = GridTests.CreateGrid("x x x 0\n0 4 0 0\n1 1 0 1\n2 2 0 2\n3 3 0 3\n1 1 0 1\n2 2 0 2\n3 3 0 3\n1 1 0 1",
                                            0);

            grid.Print();

            for (int n = 0; n <= 7; n++)
            {
                grid.Move(grid.Get(3, n), -1);
            }

            for (int i = 0; i < 4 * TIME_STEP; i++)
            {
                grid.Update(0f, 1f / TIME_STEP);
            }

            grid.Print();

            Assert.True(grid.Get(0, 0).IsEmpty);
            Assert.False(grid.Get(1, 0).IsEmpty);
            Assert.False(grid.Get(1, 0).Definition.isGarbage);
            Assert.True(grid.Get(2, 0).IsEmpty);

            Assert.True(grid.Get(0, 1).Definition.isGarbage);
            Assert.True(grid.Get(1, 1).Definition.isGarbage);
            Assert.True(grid.Get(2, 1).Definition.isGarbage);
        }
Пример #8
0
        public void TestTestMapCreation3()
        {
            var gridString = "1 2 3 x\n4 5 1 3";
            var grid       = GridTests.CreateGrid(gridString, 0);

            Assert.AreEqual(gridString,
                            Grid.ToString(grid.ToIntArray(), true));
        }
Пример #9
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));
        }
Пример #10
0
        public void TestTestMapCreation2()
        {
            var grid = GridTests.CreateGrid("0 0 1 0\n1 1 0 0", 0);

            Assert.AreEqual(4, grid.width);
            Assert.AreEqual(2, grid.height);

            grid = GridTests.CreateGrid("1 0\n1 1\n0 0", 0);
            Assert.AreEqual(2, grid.width);
            Assert.AreEqual(3, grid.height);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
0
        /// <summary>
        /// Test Heuristic.WeightMove
        /// </summary>
        private void TestComboDetection(string gridString, int combosCount)
        {
            var grid = GridTests.CreateGrid(gridString, 0);
            var move = new AIMove()
            {
                gridAfterMove = grid.ToIntArray()
            };
            var h = new AIHeuristic();
            var w = h.WeightMove(move, grid.width, grid.height, 0);

            Assert.AreEqual(combosCount, w.combosCount);
            if (combosCount > 0)
            {
                Assert.AreNotEqual(0, w.total);
            }
        }
Пример #14
0
        public void GarbageFall0()
        {
            var grid = GridTests.CreateGrid("0 x x 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0", 0);

            grid.Print();

            Assert.True(grid.Get(1, 4).Definition.isGarbage);
            Assert.True(grid.Get(2, 4).Definition.isGarbage);

            for (int i = 0; i < 4 * TIME_STEP; i++)
            {
                grid.Update(0f, 1f / TIME_STEP);
            }

            grid.Print();

            Assert.True(grid.Get(1, 0).Definition.isGarbage);
            Assert.True(grid.Get(2, 0).Definition.isGarbage);
        }
Пример #15
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));
            }
        }
Пример #16
0
        public void TestTestMapCreation()
        {
            var grid = GridTests.CreateGrid("0 0 1 2\n1 2 2 3\n3 1 2 3", 0);

            Assert.NotNull(grid);

            Assert.AreEqual(4, grid.width);
            Assert.AreEqual(3, grid.height);

            Assert.AreEqual(12, grid.Map.Count);
            Assert.AreEqual(10, grid.Map.Values.Count(b => b.IsEmpty == false));

            // Check first line to be sure Y coordinates are from bot to top.
            Assert.True(grid.Get(0, 2).IsEmpty);
            Assert.True(grid.Get(1, 2).IsEmpty);
            Assert.False(grid.Get(2, 2).IsEmpty);
            Assert.False(grid.Get(3, 2).IsEmpty);

            // Check x,y and position
            Assert.AreEqual(1, grid.Get(1, 2).x);
            Assert.AreEqual(2, grid.Get(1, 2).y);
            Assert.AreEqual(new Vector2(1, 2), grid.Get(1, 2).position);
        }
Пример #17
0
        public void GarbageFall4()
        {
            var grid = GridTests.CreateGrid("0 0 0\nx x 0\n0 5 0\n0 2 0\n0 1 0\n0 1 0\n1 4 0\n1 3 0\n4 4 0", 0);

            grid.Print();

            for (int i = 0; i < 4 * TIME_STEP; i++)
            {
                grid.Update(0f, 1f / TIME_STEP);
            }

            grid.Print();

            System.Action <int> check = (y) =>
            {
                // GridTests.Print(grid.ToIntArray());
                Assert.False(grid.Get(0, y).IsEmpty, "0," + y + " empty");
                Assert.True(grid.Get(0, y).Definition.isGarbage, "0," + y + " not garbage");
                Assert.False(grid.Get(1, y).IsEmpty, "1," + y + " empty");
                Assert.True(grid.Get(1, y).Definition.isGarbage, "1," + y + " not garbage");
                Assert.False(grid.Get(1, y - 1).IsEmpty, "0," + (y - 1) + " empty");
                Assert.False(grid.Get(1, y - 1).Definition.isGarbage, "0," + (y - 1) + " garbage");
            };

            check(7);

            grid.Move(grid.Get(1, 2), 1);

            for (int i = 0; i < 4 * TIME_STEP; i++)
            {
                grid.Update(0f, 1f / TIME_STEP);
            }

            check(5);

            grid.Move(grid.Get(1, 3), 1);

            for (int i = 0; i < 4 * TIME_STEP; i++)
            {
                grid.Update(0f, 1f / TIME_STEP);
            }

            check(4);

            grid.Move(grid.Get(1, 2), 1);

            for (int i = 0; i < 4 * TIME_STEP; i++)
            {
                grid.Update(0f, 1f / TIME_STEP);
            }

            check(2);

            grid.Move(grid.Get(1, 1), 1);

            for (int i = 0; i < 4 * TIME_STEP; i++)
            {
                grid.Update(0f, 1f / TIME_STEP);
            }

            check(1);
        }