Beispiel #1
0
        public void SimulateBattle_NoPath()
        {
            map = new int[][]
            {
                new int[] { 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 1, 1, 1, 1, 1, 1, 1, 1 },
                new int[] { 0, 0, 0, 1, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 1, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 1, 0, 0, 0, 0 },
                new int[] { 1, 0, 1, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 1, 0, 0, 0, 0, 0 },
                new int[] { 1, 1, 1, 1, 1, 1, 0, 0 },
                new int[] { 1, 0, 1, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 1, 1, 0, 0, 0, 0 }
            };
            //arrange
            var game = new TankBattleGame(map, panzer, new int[2] {
                0, 0
            }, T60, new int[2] {
                2, 7
            });

            //action
            var list = game.SimulateBattle();

            //assert
            Assert.AreEqual(100, list.Count);
        }
Beispiel #2
0
        public async Task <ActionResult <GameSimulationDto> > GenerateSimulation(int gameId)
        {
            var gameDb = _gameRepository.GetFullGame(gameId);

            if (gameDb == null)
            {
                return(NotFound());
            }
            var blueTank = new Engine.TankModel
            {
                ModelName  = gameDb.BlueTankModel.TankModelName,
                GunPower   = gameDb.BlueTankModel.GunPower,
                ShieldLife = gameDb.BlueTankModel.ShieldLife,
                GunRange   = gameDb.BlueTankModel.GunRange,
                Speed      = gameDb.BlueTankModel.Speed
            };
            var redTank = new Engine.TankModel
            {
                ModelName  = gameDb.RedTankModel.TankModelName,
                GunPower   = gameDb.RedTankModel.GunPower,
                ShieldLife = gameDb.RedTankModel.ShieldLife,
                GunRange   = gameDb.RedTankModel.GunRange,
                Speed      = gameDb.RedTankModel.Speed
            };
            var map  = gameDb.GameMap.Map.ToMatrix();
            var game = new TankBattleGame(map,
                                          blueTank, new int[2] {
                gameDb.BlueTankX, gameDb.BlueTankY
            },
                                          redTank, new int[2] {
                gameDb.RedTankX, gameDb.RedTankY
            });

            var simulation = game.SimulateBattle();

            var gameSimulation = new GameSimulation
            {
                GameBattleId = gameId,
                Simulation   = JsonSerializer.Serialize(simulation),
                IsActive     = true,
                CreatedTime  = DateTime.Now
            };
            var newSimulation = await _simulationRepository.Add(gameSimulation);

            if (newSimulation == null)
            {
                return(BadRequest("Unable to generate simulation"));
            }
            var dbGame = _gameRepository.GetFullGame(gameId);

            newSimulation.GameBattle = dbGame;
            return(CreatedAtRoute("GetSimulationForGame", new { gameId = gameId, simulationId = newSimulation.GameSimulationId }
                                  , newSimulation));
        }
Beispiel #3
0
        public void SimulateBattle_BigMap()
        {
            map = new int[][]
            {
                new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                new int[] { 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
            };
            //arrange
            var game = new TankBattleGame(map, panzer, new int[2] {
                0, 0
            }, T60, new int[2] {
                19, 30
            });

            //action
            var list = game.SimulateBattle();

            //assert
            Assert.AreEqual(26, list.Count);
        }