Example #1
0
        public void Create_NewBoxWithSnakes_CountsTwoSnakes()
        {
            int[]        snakeHeads = new int[] { 0, 63 };
            BoxCartesian b          = new BoxCartesian(world, snakeHeads, heuristicForBox, heuristicForSnakes);

            Assert.AreEqual(2, b.NumberOfSnake);
        }
Example #2
0
        public void Generate_BoxGenerateTwoSnakesBadSpread_PruneAll()
        {
            int[]              snakeHeads = new int[] { 0, 3 };
            BoxCartesian       b          = new BoxCartesian(world, snakeHeads, heuristicForBox, heuristicForSnakes);
            LinkedList <INode> boxes      = b.Children;

            Assert.AreEqual(0, boxes.Count);
        }
Example #3
0
        public void Generate_BoxGenerateFourSnakes_SomeValidSnakesAreCreated()
        {
            int[]              snakeHeads = new int[] { 0, 63, 15, 27 };
            BoxCartesian       b          = new BoxCartesian(world, snakeHeads, heuristicForBox, heuristicForSnakes);
            LinkedList <INode> boxes      = b.Children;

            Assert.AreEqual(28, boxes.Count);
        }
        public void Run_NewAStarBox()
        {
            World w             = new World(5, 2, 2);
            var   heuristicFunc = new SnakeNoneHeuristic();

            int[]        snakeHeads = new int[] { 0, 31 };
            BoxCartesian b          = new BoxCartesian(w, snakeHeads, new BoxNoneHeuristic(), heuristicFunc);
            AStarMax     astar      = new AStarMax(b, new ImplicitGoal());

            astar.Run(1);
            var maxGoal = astar.GetMaxGoal();

            Assert.IsNotNull(maxGoal);
        }
        public void Calculate_RightBoxCartesianSnakesSumHeuristic()
        {
            World w = new World(7, 2, 3);

            int[] snakeHeads = new int[] { 0, 127 };
            Box   b          = new BoxCartesian(w, snakeHeads, new BoxSnakesSumHeuristic(), new SnakeLegalHeuristic());

            Assert.AreEqual(0, b.g);
            Assert.AreEqual(128, b.h);
            Assert.AreEqual(128, b.f);
            var lstGen = b.Children;

            Assert.AreEqual(0, lstGen.Last.Value.g);
            Assert.AreEqual(127, lstGen.Last.Value.h);
            Assert.AreEqual(127, lstGen.Last.Value.f);
            lstGen = lstGen.Last.Value.Children;
            Assert.AreEqual(1, lstGen.Last.Value.g);
            Assert.AreEqual(126, lstGen.Last.Value.h);
            Assert.AreEqual(127, lstGen.Last.Value.f);
        }
        public void Calculate_RightBoxCartesianLegalHeuristic()
        {
            World w = new World(7, 2, 3);

            int[] snakeHeads = new int[] { 0, 127 };
            Box   b          = new BoxCartesian(w, snakeHeads, new BoxLegalHeuristic(), new SnakeNoneHeuristic());

            Assert.AreEqual(0, b.g);
            Assert.AreEqual(114, b.h);
            Assert.AreEqual(114, b.f);
            var lstGen = b.Children;

            Assert.AreEqual(0, lstGen.Last.Value.g);
            Assert.AreEqual(108, lstGen.Last.Value.h);
            Assert.AreEqual(108, lstGen.Last.Value.f);
            lstGen = lstGen.First.Value.Children;
            Assert.AreEqual(1, lstGen.Last.Value.g);
            Assert.AreEqual(97, lstGen.Last.Value.h);
            Assert.AreEqual(98, lstGen.Last.Value.f);
            lstGen = lstGen.First.Value.Children;
            Assert.AreEqual(2, lstGen.Last.Value.g);
            Assert.AreEqual(87, lstGen.Last.Value.h);
            Assert.AreEqual(89, lstGen.Last.Value.f);
        }
        public void Calculate_RightBoxCartesianShortestSnakeReachableHeuristic()
        {
            World w = new World(7, 2, 3);

            int[] snakeHeads = new int[] { 0, 127 };
            Box   b          = new BoxCartesian(w, snakeHeads, new BoxShortestSnakeReachableHeuristic(), new SnakeNoneHeuristic());

            Assert.AreEqual(0, b.g);
            Assert.AreEqual(127, b.h);
            Assert.AreEqual(127, b.f);
            var lstGen = b.Children;

            Assert.AreEqual(0, lstGen.Last.Value.g);
            Assert.AreEqual(127, lstGen.Last.Value.h);
            Assert.AreEqual(127, lstGen.Last.Value.f);
            lstGen = lstGen.First.Value.Children;
            Assert.AreEqual(1, lstGen.Last.Value.g);
            Assert.AreEqual(119, lstGen.Last.Value.h);
            Assert.AreEqual(120, lstGen.Last.Value.f);
            lstGen = lstGen.First.Value.Children;
            Assert.AreEqual(2, lstGen.Last.Value.g);
            Assert.AreEqual(105, lstGen.Last.Value.h);
            Assert.AreEqual(107, lstGen.Last.Value.f);
        }