Example #1
0
        public void ProblemCase1()
        {
            GameState gameState = TestGameState(7, 10);
            DistanceField <GameState.Tile> dut = new DistanceField <GameState.Tile>(gameState, gameState.map, tile => tile.isFood);

            const Tile f = Tile.Food;
            const Tile _ = Tile.Land;
            const Tile w = Tile.Water;
            const Tile u = Tile.Unseen;

            Tile[,] map = new Tile[, ]
            {
                { _, _, _, u, _, _, w },
                { _, f, _, u, _, _, w },
                { _, _, _, w, _, _, w },
                { _, _, _, w, _, _, w },
                { _, _, _, w, _, _, w },
                { _, _, _, w, w, _, w },
                { _, _, _, _, w, f, w },
                { _, _, _, w, w, _, w },
                { _, _, _, _, w, _, w },
                { w, w, w, w, w, w, w },
            };

            gameState.Set(map);
            dut.Propagate();

            {
                Vector2i r = dut.GetDescent(3, 6).First();
                Assert.AreEqual(-1, r.x);
                Assert.AreEqual(0, r.y);
            }
        }
Example #2
0
        public void TestDescent()
        {
            GameState gameState = TestGameState(7, 5);
            DistanceField <GameState.Tile> dut = new DistanceField <GameState.Tile>(gameState, gameState.map, tile => tile.isFood);

            const Tile f = Tile.Food;
            const Tile _ = Tile.Land;
            const Tile w = Tile.Water;

            Tile[,] map = new Tile[, ]
            {
                { _, w, _, w, _, w, _ },
                { _, w, _, w, _, w, _ },
                { _, w, f, w, _, _, _ },
                { _, _, w, w, w, w, _ },
                { _, w, _, _, _, w, _ }
            };

            gameState.Set(map);
            dut.Propagate();

            {
                Vector2i r = dut.GetDescent(6, 4).First();
                Assert.AreEqual(-1, r.y);
                Assert.AreEqual(0, r.x);
            }

            {
                Vector2i r = dut.GetDescent(6, 3).First();
                Assert.AreEqual(-1, r.y);
                Assert.AreEqual(0, r.x);
            }

            {
                Vector2i r = dut.GetDescent(6, 2).First();
                Assert.AreEqual(-1, r.x);
                Assert.AreEqual(0, r.y);
            }

            {
                Vector2i r = dut.GetDescent(5, 2).First();
                Assert.AreEqual(-1, r.x);
                Assert.AreEqual(0, r.y);
            }

            {
                Vector2i r = dut.GetDescent(4, 2).First();
                Assert.AreEqual(0, r.x);
                Assert.AreEqual(-1, r.y);
            }

            {
                Vector2i r = dut.GetDescent(2, 1).First();
                Assert.AreEqual(0, r.x);
                Assert.AreEqual(1, r.y);
            }
        }
        public void TestDescent()
        {
            DistanceField dut = new DistanceField(7, 5, Tile.Food);

            const Tile f = Tile.Food;
            const Tile _ = Tile.Land;
            const Tile w = Tile.Water;

            Tile[,] map = new Tile[, ]
            {
                { _, w, _, w, _, w, _ },
                { _, w, _, w, _, w, _ },
                { _, w, f, w, _, _, _ },
                { _, _, w, w, w, w, _ },
                { _, w, _, _, _, w, _ }
            };

            dut.Propagate(map, 20);

            {
                Vector2i r = dut.GetDescent(6, 4).First();
                Assert.AreEqual(-1, r.y);
                Assert.AreEqual(0, r.x);
            }

            {
                Vector2i r = dut.GetDescent(6, 3).First();
                Assert.AreEqual(-1, r.y);
                Assert.AreEqual(0, r.x);
            }

            {
                Vector2i r = dut.GetDescent(6, 2).First();
                Assert.AreEqual(-1, r.x);
                Assert.AreEqual(0, r.y);
            }

            {
                Vector2i r = dut.GetDescent(5, 2).First();
                Assert.AreEqual(-1, r.x);
                Assert.AreEqual(0, r.y);
            }

            {
                Vector2i r = dut.GetDescent(4, 2).First();
                Assert.AreEqual(0, r.x);
                Assert.AreEqual(-1, r.y);
            }

            {
                Vector2i r = dut.GetDescent(2, 1).First();
                Assert.AreEqual(0, r.x);
                Assert.AreEqual(1, r.y);
            }
        }
Example #4
0
        public void Exploration2()
        {
            GameState gameState = TestGameState(7, 10);
            DistanceField <GameState.Tile> dut = new DistanceField <GameState.Tile>(gameState, gameState.map, tile => tile.terrain == GameState.Terrain.Unknown);

            const Tile u = Tile.Unseen;
            const Tile f = Tile.Food;
            const Tile _ = Tile.Land;
            const Tile w = Tile.Water;

            Tile[,] map = new Tile[, ]
            {
                { w, w, w, w, w, w, w },
                { w, _, _, _, _, _, u },
                { w, _, _, _, _, _, u },
                { w, _, _, _, _, _, u },
                { w, _, _, _, _, _, u },
                { w, _, _, _, _, _, u },
                { w, _, _, _, _, _, u },
                { w, w, w, w, w, _, u },
                { w, _, _, _, _, _, u },
                { w, u, u, u, u, u, u },
            };

            gameState.Set(map);
            dut.Propagate();

            {
                Assert.AreEqual(5, dut.GetDistance(1, 1));
                Assert.AreEqual(5, dut.GetDistance(1, 2));
                Assert.AreEqual(0, dut.GetDistance(6, 2));
                Assert.AreEqual(1, dut.GetDistance(5, 2));
                Assert.AreEqual(5, dut.GetDistance(1, 6));
            }

            {
                Vector2i result = dut.GetDescent(1, 6).First();
                Assert.AreEqual(1, result.x);
                Assert.AreEqual(0, result.y);
            }
        }
Example #5
0
        public void ProblemCase3_AntHills()
        {
            GameState gameState = TestGameState(7, 10);
            DistanceField <GameState.Tile> dut = new DistanceField <GameState.Tile>(gameState, gameState.map, tile => tile.isEnemyHill);

            const Tile f = Tile.Food;
            const Tile _ = Tile.Land;
            const Tile w = Tile.Water;
            const Tile h = Tile.TheirHill;
            const Tile u = Tile.Unseen;

            gameState.Set(new Tile[, ]
            {
                { _, w, w, _, _, _, w },
                { _, w, w, h, _, _, w },
                { _, w, w, _, _, _, w },
                { w, w, w, _, _, _, w },
                { w, w, w, _, _, _, w },
                { _, _, _, _, _, _, w },
                { _, _, _, _, _, _, w },
                { _, _, _, _, _, _, w },
                { _, _, _, _, _, _, w },
                { w, w, w, w, w, w, w },
            });

            dut.Propagate();

            Assert.AreEqual(1, dut.GetDistance(3, 2));

            {
                Vector2i r = dut.GetDescent(2, 5).First();
                Assert.AreEqual(1, r.x);
                Assert.AreEqual(0, r.y);
            }

            {
                Vector2i r = dut.GetDescent(1, 5).First();
                Assert.AreEqual(1, r.x);
                Assert.AreEqual(0, r.y);
            }



            gameState.Set(new Tile[, ]
            {
                { _, w, w, _, _, _, w },
                { _, w, w, u, _, _, w },
                { _, w, w, _, _, _, w },
                { w, w, w, _, _, _, w },
                { w, w, w, _, _, _, w },
                { _, _, _, _, _, _, w },
                { _, _, _, _, _, _, w },
                { _, _, _, _, _, _, w },
                { _, _, _, _, _, _, w },
                { w, w, w, w, w, w, w },
            });

            dut.Propagate();

            Assert.AreEqual(1, dut.GetDistance(3, 2));

            {
                Vector2i r = dut.GetDescent(2, 5).First();
                Assert.AreEqual(1, r.x);
                Assert.AreEqual(0, r.y);
            }

            {
                Vector2i r = dut.GetDescent(1, 5).First();
                Assert.AreEqual(1, r.x);
                Assert.AreEqual(0, r.y);
            }
        }
Example #6
0
        public void Exploration3()
        {
            GameState gameState = TestGameState(7, 10);
            DistanceField <GameState.Tile> dut = new DistanceField <GameState.Tile>(gameState, gameState.map, tile => tile.terrain == GameState.Terrain.Unknown);

            const Tile u = Tile.Unseen;
            const Tile f = Tile.Food;
            const Tile _ = Tile.Land;
            const Tile w = Tile.Water;



            gameState.Set(new Tile[, ]
            {
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u },
                { w, w, w, _, w, w, w },
                { w, w, w, _, w, w, w },
                { w, w, w, _, w, w, w },
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u }
            });
            dut.Propagate();
            {
                Assert.AreEqual(0, dut.GetDistance(3, 2));
                Assert.AreEqual(1, dut.GetDistance(3, 3));
                Assert.AreEqual(2, dut.GetDistance(3, 4));
                Assert.AreEqual(1, dut.GetDistance(3, 5));
                Assert.AreEqual(0, dut.GetDistance(3, 6));
            }

            gameState.Set(new Tile[, ]
            {
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u },
                { w, w, w, _, w, w, w },
                { w, w, w, _, w, w, w },
                { w, w, w, _, w, w, w },
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u }
            });
            dut.Propagate();
            {
                Assert.AreEqual(0, dut.GetDistance(3, 1));
                Assert.AreEqual(1, dut.GetDistance(3, 2));
                Assert.AreEqual(2, dut.GetDistance(3, 3));
                Assert.AreEqual(2, dut.GetDistance(3, 4));
                Assert.AreEqual(1, dut.GetDistance(3, 5));
                Assert.AreEqual(0, dut.GetDistance(3, 6));


                Vector2i r = dut.GetDescent(3, 2).First();
                Assert.AreEqual(0, r.x);
                Assert.AreEqual(-1, r.y);
            }


            gameState.Set(new Tile[, ]
            {
                { u, u, u, u, u, u, u },
                { w, w, w, _, w, w, w },
                { w, w, w, _, w, w, w },
                { w, w, w, _, w, w, w },
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u },
                { u, u, u, u, u, u, u }
            });
            dut.Propagate();
            {
                Assert.AreEqual(0, dut.GetDistance(3, 0));
                Assert.AreEqual(1, dut.GetDistance(3, 1));
                Assert.AreEqual(2, dut.GetDistance(3, 2));
                Assert.AreEqual(3, dut.GetDistance(3, 3));
                Assert.AreEqual(2, dut.GetDistance(3, 4));
                Assert.AreEqual(1, dut.GetDistance(3, 5));
                Assert.AreEqual(0, dut.GetDistance(3, 6));

                Vector2i r = dut.GetDescent(3, 2).First();
                Assert.AreEqual(0, r.x);
                Assert.AreEqual(-1, r.y);
            }
        }