Example #1
0
 public MazeController(IMazeToCharConverter mazeToCharConverter, IHero hero, IMazeBuilder builder)
 {
     _mazeToCharConverter = mazeToCharConverter;
     _hero   = hero;
     _maze   = builder.ConstrainMaze(10, 15);
     _engine = new Processor(hero, _maze);
 }
Example #2
0
        private static void Test(IMazeBuilder builder, int rows, int columns, int samples)
        {
            if (builder == null)
            {
                return;
            }

            Console.WriteLine("{0}x{1}: {2}", rows, columns, builder);

            int sumPathLength = 0;
            int sumDeadEnds   = 0;

            for (int i = 0; i < samples; i++)
            {
                var grid = Grid.CreateGrid(rows, columns);
                builder.Build(grid);

                Distances longestPath = Distances.LongestPath(grid);
                sumPathLength += longestPath.MaxDistance().Value;

                Distances deadEnds = Distances.DeadEnds(grid);
                sumDeadEnds += deadEnds.Count();
            }

            Console.WriteLine("Longest Path: {0}", (double)sumPathLength / samples);
            Console.WriteLine("Nr Dead Ends: {0}", (double)sumDeadEnds / samples);
        }
Example #3
0
 public void CreateMaze(IMazeBuilder builder)
 {
     builder.BuildMaze();
     builder.BuildRoom(1);
     builder.BuildRoom(2);
     builder.BuildDoor(1, 2);
 }
Example #4
0
 public void CreateComplexMaze(IMazeBuilder builder)
 {
     for (int i = 0; i < 100; i++)
     {
         builder.BuildRoom(i);
     }
 }
Example #5
0
        public RectangleMaze(IMazeBuilder mazeBuilder, IMazeSchema mazeSchema, ILocation startLocation)
        {
            StartLocation  = startLocation;
            Walls          = new List <IWall>();
            Paths          = new List <IPath>();
            ThreeSixtyView = new Dictionary <ILocation, Dictionary <Direction, IBuildingBlock> >();

            string[] schemaLines = mazeSchema.GetSchema().Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            IBuildingBlockIdentifier wallIdentifier = GetBuildingBlockIdentifier(mazeSchema, BuildingBlockType.Wall);
            IBuildingBlockIdentifier pathIdentifier = GetBuildingBlockIdentifier(mazeSchema, BuildingBlockType.Path);

            List <List <IBuildingBlock> > buildingBlocksByRows = CreateBuildingBlocks(mazeBuilder, schemaLines, wallIdentifier, pathIdentifier);

            PopulateThreeSixtyView(buildingBlocksByRows);

            foreach (List <IBuildingBlock> buildingBlocks in buildingBlocksByRows)
            {
                foreach (IBuildingBlock buildingBlock in buildingBlocks)
                {
                    switch (buildingBlock.GetBuildingBlockType())
                    {
                    case BuildingBlockType.Wall:
                        Walls.Add(buildingBlock as IWall);
                        break;

                    case BuildingBlockType.Path:
                        Paths.Add(buildingBlock as IPath);
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
            }
        }
        public Maze CreateMaze(IMazeBuilder builder)
        {
            builder.BuildMaze();
            builder.BuildRoom(1);
            builder.BuildRoom(2);
            builder.BuildDoor(1, 2);

            return(builder.GetMaze());
        }
Example #7
0
        public IMaze CreateMaze(IMazeBuilder mazeBuilder)
        {
            mazeBuilder.BuildMaze();

            mazeBuilder.BuildRoom(1);
            mazeBuilder.BuildRoom(2);
            mazeBuilder.BuildDoor(1, 2);

            return(mazeBuilder.GetMaze());
        }
Example #8
0
        private List <List <IBuildingBlock> > CreateBuildingBlocks(IMazeBuilder mazeBuilder, string[] schemaLines, IBuildingBlockIdentifier wallIdentifier, IBuildingBlockIdentifier pathIdentifier)
        {
            List <List <IBuildingBlock> > buildingBlocksByRows = new List <List <IBuildingBlock> >();

            for (int schemaRowIndex = 0; schemaRowIndex <= schemaLines.Length - 1; schemaRowIndex++)
            {
                List <IBuildingBlock> buildingBlocksInRow = new List <IBuildingBlock>();
                buildingBlocksByRows.Add(buildingBlocksInRow);

                string   schemaRow     = schemaLines[schemaRowIndex].Trim();
                string[] schemaColumns = schemaRow.Split();

                int        latiduteIndex = -1; //To Keep track of space which is not BuildingBlock
                ILongitude longitude     = mazeBuilder.CreateLongitude(schemaRowIndex);

                for (int schemaColumnIndex = 0; schemaColumnIndex <= schemaColumns.Length - 1; schemaColumnIndex++)
                {
                    BuildingBlockType?buildingBlockType = null;

                    if (schemaColumns[schemaColumnIndex].ToString() == wallIdentifier.GetIdentifier().ToString())
                    {
                        buildingBlockType = BuildingBlockType.Wall;
                    }
                    else if (schemaColumns[schemaColumnIndex].ToString() == pathIdentifier.GetIdentifier().ToString())
                    {
                        buildingBlockType = BuildingBlockType.Path;
                    }

                    if (buildingBlockType.HasValue)
                    {
                        latiduteIndex++;
                        ILatitude      latitude = mazeBuilder.CreateLatitude(latiduteIndex);
                        ILocation      location = mazeBuilder.CreateLocation(latitude, longitude);
                        IBuildingBlock buildingBlock;
                        switch (buildingBlockType)
                        {
                        case BuildingBlockType.Wall:
                            buildingBlock = mazeBuilder.CreateWall(location);
                            break;

                        case BuildingBlockType.Path:
                            buildingBlock = mazeBuilder.CreatePath(location);
                            break;

                        default:
                            throw new NotImplementedException();
                        }

                        buildingBlocksInRow.Add(buildingBlock);
                    }
                }
            }

            return(buildingBlocksByRows);
        }
Example #9
0
        public IMaze CreateComplexMaze(IMazeBuilder mazeBuilder)
        {
            mazeBuilder.BuildMaze();

            for (var i = 0; i < 1000; i++)
            {
                mazeBuilder.BuildRoom(i);
            }
            // ...

            return(mazeBuilder.GetMaze());
        }
Example #10
0
 public Maze(IMazeBuilder builder)
 {
     if (builder == null)
         throw new ArgumentNullException("builder");
     Width = builder.Width;
     Height = builder.Height;
     HWalls = new bool[Width, Height + 1];
     VWalls = new bool[Width + 1, Height];
     ClearMaze();
     builder.Build(this);
     MazeHasBeenBuilt(Width, Height);
     startPosition = builder.MazeStartPosition;
     x = startPosition.X;
     y = startPosition.Y;
     direction = Direction.East;
     MouseHasMoved(new Position(x, y));
     MouseHasTurned(direction);
 }
        public Maze CreateMaze(IMazeBuilder builder)
        {
            builder.BuildMaze();

            builder.BuildRoom(1);
            builder.BuildRoom(2);
            builder.BuildDoor(1, 2);

            return builder.GetMaze();
        }
Example #12
0
 public MazeGame(IMazeBuilder builder)
 {
     this.builder = builder;
 }
Example #13
0
 public MazeGenerator()
 {
     mazeBuilder = new EasyMazeBuilder();
     rng         = new Random();
 }