Example #1
0
        public void Given_AStar_When_SearchingForPathThatExists_Then_ShortestPathReturned()
        {
            var map = OceanNavigator.FromString(new string[]
            {
                "    ##  ##   ##",
                "##           ##",
                "#### ##  ##   #",
                "  ## ######   #",
                "      ### ##   ",
                " ##   ### ###  ",
                " ###  ## ####  ",
                "#######  ####  ",
                "##   ####     #",
                "       ##   ###",
                "               ",
                "               ",
                "#####    ##   #",
                "#####  ####  ##",
                "       ##    ##"
            });

            var pf    = new AStar(map);
            var start = new Location(0, 0);
            var end   = new Location(12, 14);

            var path = pf.FindPath(start, end);

            path.Count.Should().Be(31);
        }
Example #2
0
        private void RenderFloodFillVisualization()
        {
            var map = OceanNavigator.FromString(new string[]
            {
                "    ##  ##   ##",
                "##           ##",
                "#### ##  ##   #",
                "  ## ######   #",
                "      ### ##   ",
                " ##   ### ###  ",
                " ###  ## ####  ",
                "#######  ####  ",
                "##   ####     #",
                "       ##   ###",
                "               ",
                "               ",
                "#####    ##   #",
                "#####  ####  ##",
                "       ##    ##"
            });

            var ff = new FloodFill(map);

            var overlay = ff.GetRegion(new Location(0, 0));

            var mv = new OceanNavigatorVisualizer(map);

            pictureBox2.Image = mv.Render(overlay);
        }
Example #3
0
        private void RenderAStarVisualization()
        {
            var map = OceanNavigator.FromString(new string[]
            {
                "    ##  ##   ##",
                "##           ##",
                "#### ##  ##   #",
                "  ## ######   #",
                "      ### ##   ",
                " ##   ### ###  ",
                " ###  ## ####  ",
                "#######  ####  ",
                "##   ####     #",
                "       ##   ###",
                "               ",
                "               ",
                "#####    ##   #",
                "#####  ####  ##",
                "       ##    ##"
            });

            var pf = new AStar(map);

            var path = pf.FindPath(new Location(0, 0), new Location(12, 14));

            var mv = new OceanNavigatorVisualizer(map);

            pictureBox1.Image = mv.Render(path);
        }
Example #4
0
        public void Given_FloodFill_When_GettingRegionSize_Then_CorrectSizeReturned()
        {
            var map = OceanNavigator.FromString(new string[]
            {
                "    ##  ##   ##",
                "##           ##",
                "#### ##  ##   #",
                "  ## ######   #",
                "      ### ##   ",
                " ##   ### ###  ",
                " ###  ## ####  ",
                "#######  ####  ",
                "##   ####     #",
                "       ##   ###",
                "               ",
                "               ",
                "#####    ##   #",
                "#####  ####  ##",
                "       ##    ##"
            });

            var ff = new FloodFill(map);

            var size = ff.GetRegionSize(new Location(0, 0));

            size.Should().Be(124);

            var size2 = ff.GetRegionSize(new Location(8, 6));

            size2.Should().Be(3);
        }
Example #5
0
        public void Given_FloodFill_When_FillingValidRegion_Then_EntireRegionIsFilled()
        {
            var map = OceanNavigator.FromString(new string[]
            {
                "    ##  ##   ##",
                "##           ##",
                "#### ##  ##   #",
                "  ## ######   #",
                "      ### ##   ",
                " ##   ### ###  ",
                " ###  ## ####  ",
                "#######  ####  ",
                "##   ####     #",
                "       ##   ###",
                "               ",
                "               ",
                "#####    ##   #",
                "#####  ####  ##",
                "       ##    ##"
            });

            var ff    = new FloodFill(map);
            var start = new Location(0, 0);

            var filled = ff.GetRegion(start);

            filled[0, 0].Should().Be(true);
            filled[3, 10].Should().Be(true);

            // Not part of the original region
            filled[8, 6].Should().Be(false);

            // Not traversable
            filled[4, 0].Should().Be(false);
        }
Example #6
0
        public void Given_AStar_When_SearchingForPathThatDoesNotExist_Then_EmptyListReturned()
        {
            var map = OceanNavigator.FromString(new string[]
            {
                "### #",
                "    #",
                "#####",
                " #   ",
                "   # ",
            });

            var pf    = new AStar(map);
            var start = new Location(4, 4);
            var end   = new Location(3, 0);

            var path = pf.FindPath(start, end);

            path.Count.Should().Be(0);
        }
Example #7
0
        public void Given_AStar_When_SearchingForPath_Then_FirstLocationInPathIsStartTile()
        {
            var map = OceanNavigator.FromString(new string[]
            {
                "### #",
                "    #",
                " ####",
                " #   ",
                "   # ",
            });

            var pf    = new AStar(map);
            var start = new Location(4, 4);
            var end   = new Location(3, 0);

            var path = pf.FindPath(start, end);

            path.First().X.Should().Be(4);
            path.First().Y.Should().Be(4);

            path.Last().X.Should().Be(3);
            path.Last().Y.Should().Be(0);
        }