Пример #1
0
        private Direction[] GetNearbyCells(Point point, Func <CellColor, bool> test)
        {
            var fieldZone = new RectZone(0, 0, width, height);

            var nearby = new List <Direction>();

            foreach (var d in directions)
            {
                var p = point.Move(d.offset.X, d.offset.Y);
                if (fieldZone.Contains(p) && (field[point.Y, point.X] & d.wall) == Wall.None && test(colors[p.Y, p.X]))
                {
                    nearby.Add(d);
                }
            }
            return(nearby.ToArray());
        }
Пример #2
0
        public void CheckSymmetry(int width, int height, int left, int top, int rw, int rh)
        {
            var mazeGenerator = new MazeGeneratorMock();
            var field         = mazeGenerator.CreateFieldWrapper(width, height);

            var seed = DateTime.Now.Millisecond;

            TestContext.WriteLine($"seed: {seed}");

            var winZone = new RectZone(left, top, rw, rh);

            mazeGenerator.GenerateWaysWrapper(field, winZone, new Random(seed));

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    Wall cell = field[y, x];

                    if (winZone.Contains(new Point(x, y)) == false)
                    {
                        Assert.That(cell, Is.Not.EqualTo(Wall.Full));
                    }

                    Wall symmetryCell = field[height - y - 1, width - x - 1];

                    if ((cell & Wall.Top) == Wall.Top && (symmetryCell & Wall.Bottom) == Wall.Bottom)
                    {
                        Assert.That(symmetryCell & Wall.Bottom, Is.EqualTo(Wall.Bottom));
                    }
                    else
                    {
                        Assert.That(symmetryCell & Wall.Bottom, Is.EqualTo(Wall.None));
                    }

                    if ((cell & Wall.Bottom) == Wall.Bottom)
                    {
                        Assert.That(symmetryCell & Wall.Top, Is.EqualTo(Wall.Top));
                    }
                    else
                    {
                        Assert.That(symmetryCell & Wall.Top, Is.EqualTo(Wall.None));
                    }

                    if ((cell & Wall.Left) == Wall.Left)
                    {
                        Assert.That(symmetryCell & Wall.Right, Is.EqualTo(Wall.Right));
                    }
                    else
                    {
                        Assert.That(symmetryCell & Wall.Right, Is.EqualTo(Wall.None));
                    }

                    if ((cell & Wall.Right) == Wall.Right)
                    {
                        Assert.That(symmetryCell & Wall.Left, Is.EqualTo(Wall.Left));
                    }
                    else
                    {
                        Assert.That(symmetryCell & Wall.Left, Is.EqualTo(Wall.None));
                    }
                }
            }
        }