示例#1
0
        public void CaseA()
        {
            var report = new TestReport();

            var sample = new[]
            {
                "#############",
                "#a ###    b##",
                "# A######  ##",
                "#  ######B ##",
                "#########  ##",
                "#############"
            };


            var boundry = Bitmap.Create(sample, x => x == '#');  //sample.ToMap('#', 'A', 'B');

            var staticMaps = new StaticMaps(
                Bitmap.Create(sample, '#'),
                Bitmap.Create(sample, ' ', 'a', 'b'),
                null,
                null
                );
            var stateMaps = new StateMaps(
                Bitmap.Create(sample, 'A', 'B'),
                FloodFill.Fill(staticMaps.WallMap, Bitmap.FindPosition(sample, 'a')));

            var pushMap = PushMap.Find(staticMaps, stateMaps, Bitmap.FindPosition(sample, 'A'),
                                       Bitmap.FindPosition(sample, 'b'));


            report.WriteLine(pushMap);

            Assert.Equal(new TestReport(@".............
..X..........
.............
..X..........
.............
............."), report);
        }
示例#2
0
        public void FillsSimpleArea()
        {
            var map = new int[][] {
                new int[] { 0, 0, 0, 0, 0 },
                new int[] { 1, 1, 1, 1, 1 },
                new int[] { 1, 0, 0, 0, 1 },
                new int[] { 1, 0, 0, 0, 1 },
                new int[] { 1, 0, 0, 0, 1 },
                new int[] { 1, 1, 1, 1, 1 },
                new int[] { 0, 0, 0, 0, 0 }
            };

            var f = new FloodFill((p) => {
                if (p.x >= 0 && p.x < map.Length && p.y >= 0 && p.y < map[p.x].Length)
                {
                    var matches = map[p.x][p.y] == 0;

                    if (matches)
                    {
                        map[p.x][p.y] = 2;
                    }

                    return(matches);
                }

                return(false);
            });

            var totalFilled = f.Fill(new Point(2, 1));

            Assert.AreEqual(totalFilled, 9);

            for (var x = 2; x < 5; x++)
            {
                for (var y = 1; y < 4; y++)
                {
                    Assert.AreEqual(map[x][y], 2);
                }
            }
        }
示例#3
0
        public void Sample()
        {
            var bountry = Bitmap.Create(new[]
            {
                "~~~###~~~~~",
                "~~## #~####",
                "~##  ###  #",
                "## X      #",
                "#    X #  #",
                "### X###  #",
                "~~#  #    #",
                "~## ## # ##",
                "~#      ##~",
                "~#     ##~~",
                "~#######~~~"
            });

            var expected = Bitmap.Create(new[]
            {
                "~~~###~~~~~",
                "~~## #~####",
                "~##  ###  #",
                "## X      #",
                "#    X #  #",
                "### X###  #",
                "~~#  #    #",
                "~## ## # ##",
                "~#      ##~",
                "~#     ##~~",
                "~#######~~~"
            }, x => x == ' ');

            var start = new VectorInt2(4, 4);


            var result = FloodFill.Fill(bountry, start);

            Assert.Equal(expected, result);
        }
示例#4
0
    static void Main(string[] args)
    {
        // Example usage:
        int length = 10, width = 10;

        bool[,] map = new bool[10, 10];
        map[2, 2]   = true;
        map[2, 3]   = true;
        map[3, 3]   = true;
        map[4, 3]   = true;
        map[4, 2]   = true;
        map[4, 1]   = true;
        map[3, 1]   = true;
        map[2, 1]   = true;
        // //Define filled/empty nodes here
        int count = FloodFill.GetSizeOfBlock(map, new Vector2(10, 10), new Vector2(2, 2));

        Console.WriteLine("Count = " + count);
        for (int i = 0; i < length; i++)
        {
            for (int j = 0; j < width - 1; j++)
            {
                Console.Write(map[i, j] + ", ");
            }
            Console.WriteLine(map[i, width - 1]);
        }
        Console.ReadKey();
        map = FloodFill.Fill(map, new Vector2(10, 10), new Vector2(0, 0));
        for (int i = 0; i < length; i++)
        {
            for (int j = 0; j < width - 1; j++)
            {
                Console.Write(map[i, j] + ", ");
            }
            Console.WriteLine(map[i, width - 1]);
        }
        Console.ReadKey();
    }