Beispiel #1
0
    public void Initialize(int width, int height)
    {
        var map = _mapGenerator.GenerateMap(width, height);
        var startAndGoalCells = GetStartAndGoalCells(map);

        Emit(new MapEvent.Initialized(map, startAndGoalCells.startCell, startAndGoalCells.goalCell));
    }
Beispiel #2
0
        public void TestWinningCondition()
        {
            // 1x1 map
            int           w            = 1;
            int           h            = 1;
            IMapGenerator mapGenerator = MapGeneratorFactory.CreateOpenMapGenerator();
            Map           map          = mapGenerator.GenerateMap(w, h, IMapGeneratorConstants.NO_SEED);

            // place player
            AbstractPlayer player = AIPlayerFactory.CreateEmptyAIPlayer("Test empty AI", map.Grid[0, 0]);

            // create game instance
            Game game = new Game()
            {
                GameMap = map
            };

            game.AddAIPlayer(player);

            // perform one game loop step
            game.GameLoopStep();

            // check winner
            Assert.IsTrue(game.IsWinner, "No winner after game loop step!");
            Assert.IsNotNull(game.Winner, "Winner is null!");
        }
Beispiel #3
0
        // Use this for initialization
        private void Start()
        {
            _mapGenerator = GetMarkovMapGenerator();
            var map = _mapGenerator.GenerateMap(TextureWidth, TextureHeight);

            DisplayMap(map);
        }
Beispiel #4
0
    private Map SpawnMap(
        IMapGenerator mapGenerator,
        MapTileSpawner spawnMapTile,
        IMapToWorldMapper mapToWorldMapper
        )
    {
        var map = mapGenerator.GenerateMap();

        map.ForEachTile((x, y, tile) =>
        {
            var pos = mapToWorldMapper.GetWorldPosition(
                mapX: x,
                mapY: y,
                tile: tile
                );
            spawnMapTile(
                tile: tile,
                mapX: x,
                mapY: y,
                worldPos: pos
                );
        });

        return(map);
    }
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.G))
     {
         _mapGenerator.GenerateMap();
         Debug.Log("Map Generated!");
     }
 }
        public MapState GenerateNewMap(Type generatorType)
        {
            IMapGenerator generator = GetMapGenerator(generatorType);

            IMap map = generator.GenerateMap(DefaultMapWidth, DefaultMapHeight);

            return(new MapState(map));
        }
Beispiel #7
0
 // Update is called once per frame
 private void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         _mapGenerator = GetMarkovMapGenerator();
         var map = _mapGenerator.GenerateMap(TextureWidth, TextureHeight);
         DisplayMap(map);
     }
 }
Beispiel #8
0
        public Game(IMapGenerator mapGenerator, ICountriesGenerator countriesGenerator)
        {
            // TODO: remove
            var size = 100;

            Countries = countriesGenerator.GenerateCountries();
            Map       = mapGenerator.GenerateMap(Countries, size);

            ProcessTurn();
        }
Beispiel #9
0
        public void generate_map_by_mapGenerator_exactly_GamesCount_times()
        {
            settings.GamesCount = new Random().Next(1, 10);

            new AiTester(settings, loggerFactory, mapGenerator, gameVisualizer, createAi, createGame,
                         textWriter, textReader).TestAi("");

            A.CallTo(() => mapGenerator.GenerateMap())
            .MustHaveHappened(Repeated.Exactly.Times(settings.GamesCount));
        }
Beispiel #10
0
 private void Reset(IAgent agent)
 {
     foreach (var item in agent.Inventory)
     {
         agent.RemoveItem(item);
     }
     agent.ResetScore();
     _state             = new GameState();
     _state.ActiveAgent = agent;
     _state.CurrentCell = _generator.GenerateMap();
     RunInitialiseHooks();
 }
        public void TestOpenMapGenerator()
        {
            IMapGenerator openMapGenerator = MapGeneratorFactory.CreateOpenMapGenerator();
            int           w = 10;
            int           h = 15;

            Direction[] allDirections = DirectionMethods.GetAllDirections();

            MapBlock[,] grid = openMapGenerator.GenerateGrid(w, h, 0);
            Assert.IsNotNull(grid, "Null grid returned!");
            Assert.AreEqual(w, grid.GetLength(0), "Wrong width of map grid!");
            Assert.AreEqual(h, grid.GetLength(1), "Wrong height of map grid!");
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    foreach (Direction dir in allDirections)
                    {
                        Assert.IsTrue(grid[i, j].EntranceInDirection(dir).IsOpen(), $"Entrance in direction {dir} of block [{i},{j}] should be open!");
                    }
                }
            }

            Map map = openMapGenerator.GenerateMap(w, h, 0);

            Assert.IsNotNull(map, "Null map returned!");
            Assert.AreEqual(w, map.Width, "Wrong map width!");
            Assert.AreEqual(h, map.Height, "Wrong map height!");
            MapBlock[,] grid2 = map.Grid;
            Assert.AreEqual(grid.GetLength(0), grid.GetLength(0), "Widths of grids don't match!");
            Assert.AreEqual(grid.GetLength(1), grid.GetLength(1), "Widths of grids don't match!");
            Assert.IsNotNull(map.WinningBlock, "Winning block is null!");
            Assert.AreEqual((w - 1) / 2, map.WinningBlock.X, "Wrong X coordinate of winning block.");
            Assert.AreEqual((h - 1) / 2, map.WinningBlock.Y, "Wrong Y coordinate of winning block.");

            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    foreach (Direction dir in allDirections)
                    {
                        Assert.IsTrue(grid2[i, j].EntranceInDirection(dir).IsOpen(), $"Entrance in direction {dir} of block [{i},{j}] should be open!");
                    }
                }
            }
        }
Beispiel #12
0
        public void GenerateMap()
        {
            var startingTechs = TechCanon.GetTechsOfPreviousEras(StartingEra).Concat(TechCanon.GetEntryTechsOfEra(StartingEra));

            var variables = new MapGenerationVariables()
            {
                CellCountX = Mathf.RoundToInt(DimensionsInCells.x),
                CellCountZ = Mathf.RoundToInt(DimensionsInCells.y),
                ContinentalLandPercentage = ContinentalLandPercentage,
                Civilizations             = ChosenTemplates.ToList(),
                StartingTechs             = startingTechs
            };

            MapGenerator.GenerateMap(
                SelectedMapTemplate,
                variables
                );

            UIAnimator.SetTrigger(UIAnimatorTrigger);
        }
Beispiel #13
0
        public void TestAi(string aiExePath)
        {
            var badShots    = 0;
            var crashes     = 0;
            var gamesPlayed = 0;
            var shots       = new List <int>();
            var ai          = createAi(aiExePath);

            for (var gameIndex = 0; gameIndex < settings.GamesCount; gameIndex++)
            {
                var map  = mapGenerator.GenerateMap();
                var game = createGame(map, ai);
                RunGameToEnd(game);
                gamesPlayed++;
                badShots += game.BadShots;
                if (game.AiCrashed)
                {
                    crashes++;
                    if (crashes > settings.CrashLimit)
                    {
                        break;
                    }
                    ai.ResetProcess();
                }
                else
                {
                    shots.Add(game.TurnsCount);
                }
                if (settings.Verbose)
                {
                    textWriter.WriteLine(
                        "Game #{3,4}: Turns {0,4}, BadShots {1}{2}",
                        game.TurnsCount, game.BadShots, game.AiCrashed ? ", Crashed" : "", gameIndex);
                }
            }
            ai.Dispose();
            WriteTotal(ai, shots, crashes, badShots, gamesPlayed);
        }
Beispiel #14
0
        public void TestSingleFile(string exe)
        {
            var badShots    = 0;
            var crashes     = 0;
            var gamesPlayed = 0;
            var shots       = new List <int>();
            var ai          = aiFactory.Create(exe, monitor);

            for (var gameIndex = 0; gameIndex < settings.GamesCount; gameIndex++)
            {
                var map  = mapGenerator.GenerateMap();
                var game = gameFactory.Create(map, ai);
                RunGameToEnd(game);
                gamesPlayed++;
                badShots += game.BadShots;
                if (game.AiCrashed)
                {
                    crashes++;
                    if (crashes > settings.CrashLimit)
                    {
                        break;
                    }
                    ai = aiFactory.Create(exe, monitor);
                }
                else
                {
                    shots.Add(game.TurnsCount);
                }
                if (settings.Verbose)
                {
                    Console.WriteLine(
                        "Game #{3,4}: Turns {0,4}, BadShots {1}{2}",
                        game.TurnsCount, game.BadShots, game.AiCrashed ? ", Crashed" : "", gameIndex);
                }
            }
            ai.Dispose();
            WriteTotal(ai, shots, crashes, badShots, gamesPlayed);
        }
        public void TestSimpleMapGenerator()
        {
            IMapGenerator simpleMapGenerator = MapGeneratorFactory.CreateSimpleMapGenerator();
            int           w = 5;
            int           h = 10;

            Direction[] allDirections = DirectionMethods.GetAllDirections();

            Map map = simpleMapGenerator.GenerateMap(w, h, IMapGeneratorConstants.NO_SEED);

            MapBlock[,] grid = map.Grid;

            Assert.IsNotNull(grid, "Null grid returned!");
            Assert.AreEqual(w, grid.GetLength(0), "Wrong width of map grid!");
            Assert.AreEqual(h, grid.GetLength(1), "Wrong height of map grid!");
            Assert.IsNotNull(map.WinningBlock, "Winning block is null!");
            Assert.AreEqual((w - 1) / 2, map.WinningBlock.X, "Wrong X coordinate of winning block.");
            Assert.AreEqual((h - 1) / 2, map.WinningBlock.Y, "Wrong Y coordinate of winning block.");

            // test that no map block has all entrances closed
            for (int i = 0; i < w; i++)
            {
                for (int j = 0; j < h; j++)
                {
                    int entrances = 0;
                    foreach (Direction dir in allDirections)
                    {
                        if (grid[i, j].EntranceInDirection(dir).Exists())
                        {
                            entrances++;
                        }
                    }

                    Assert.IsTrue(entrances > 0, $"Block at [{i},{j}] has no entrance!");
                }
            }
        }
Beispiel #16
0
 public IGame Create(IAi ai)
 {
     return(new Game(mapGenerator.GenerateMap(), ai));
 }