Esempio n. 1
0
        private bool IsMoveValid(TankBlasterBot bot, BotMove move)
        {
            var newLocation = _locationService.GetNewLocation(bot.Location, move.Direction);

            return(_locationService.IsLocationValid(newLocation) && _field.Board[newLocation.X, newLocation.Y] == BoardTile.Empty &&
                   !_field.Bots.Any(blasterBot => blasterBot.Id != bot.Id && blasterBot.Location == newLocation));
        }
Esempio n. 2
0
 private BotBattlefieldInfo GetBotBattlefieldInfo(TankBlasterBot bot, int roundNumber)
 {
     return(new BotBattlefieldInfo
     {
         RoundNumber = roundNumber,
         BotId = bot.Id,
         Board = _field.Board,
         Bombs = _field.Bombs.Cast <IBomb>().ToList(),
         BotLocation = bot.Location,
         OpponentLocations = _field.Bots.Where(blasterBot => blasterBot.Id != bot.Id && !blasterBot.IsDead).Select(blasterBot => blasterBot.Location).ToList(),
         Missiles = _field.Missiles.Cast <IMissile>().ToList(),
         IsMissileAvailable = IsMissileAvailable(bot, roundNumber),
         GameConfig = _gameConfig
     });
 }
Esempio n. 3
0
        private RoundPartialHistory PerformMove(TankBlasterBot bot, BotMove move, int roundNumber)
        {
            var actionDescription = move.Direction != null ? "move " + move.Direction.Value : "stay";

            if (move.Action == BotAction.DropBomb)
            {
                _field.Bombs.Add(new Bomb
                {
                    Location            = bot.Location,
                    RoundsUntilExplodes = 5,
                    ExplosionRadius     = CurrentBombBlastRadius(roundNumber)
                });

                actionDescription += " & drop bomb";
            }

            bot.Location      = _locationService.GetNewLocation(bot.Location, move.Direction);
            bot.LastDirection = move.Direction ?? bot.LastDirection;

            if (move.Action == BotAction.FireMissile)
            {
                if (IsMissileAvailable(bot, roundNumber) && _locationService.IsLocationAvailableForMissile(_locationService.GetNewLocation(bot.Location, move.FireDirection)))
                {
                    bot.LastMissileFiredRound = roundNumber;
                    _field.Missiles.Add(new Missile
                    {
                        ExplosionRadius = CurrentMissileBlastRadius(roundNumber),
                        MoveDirection   = move.FireDirection,
                        Location        = _locationService.GetNewLocation(bot.Location, move.FireDirection)
                    });
                    actionDescription += " & fire " + move.FireDirection;
                }
                else
                {
                    actionDescription += " & can't fire " + move.FireDirection;
                }
            }

            return(new RoundPartialHistory
            {
                Caption = string.Format("Round {0} {1}: {2}", roundNumber, bot.Name, actionDescription),
                BoardState = _field.ExportState()
            });
        }
Esempio n. 4
0
 private bool IsMissileAvailable(TankBlasterBot bot, int roundNumber)
 {
     return(roundNumber - _gameConfig.RoundsBetweenMissiles > bot.LastMissileFiredRound);
 }
Esempio n. 5
0
        private int MissileAvailableIn(TankBlasterBot bot, int roundNumber)
        {
            int result = _gameConfig.RoundsBetweenMissiles - roundNumber + bot.LastMissileFiredRound;

            return(bot.LastMissileFiredRound < 0 || result < 0 ? 0 : result);
        }
Esempio n. 6
0
        private RoundPartialHistory PerformMove(TankBlasterBot bot, BotMove move, int roundNumber)
        {
            var actionDescription = move.Direction != null ? "move " + move.Direction.Value : "stay";

            if (move.Action == BotAction.DropBomb)
            {
                _field.Bombs.Add(new Bomb
                {
                    Location = bot.Location,
                    RoundsUntilExplodes = 5,
                    ExplosionRadius = CurrentBombBlastRadius(roundNumber)
                });

                actionDescription += " & drop bomb";
            }

            bot.Location = _locationService.GetNewLocation(bot.Location, move.Direction);
            bot.LastDirection = move.Direction ?? bot.LastDirection;

            if (move.Action == BotAction.FireMissile)
            {
                if (IsMissileAvailable(bot, roundNumber) && _locationService.IsLocationAvailableForMissile(_locationService.GetNewLocation(bot.Location, move.FireDirection)))
                {
                    bot.LastMissileFiredRound = roundNumber;
                    _field.Missiles.Add(new Missile
                    {
                        ExplosionRadius = CurrentMissileBlastRadius(roundNumber),
                        MoveDirection = move.FireDirection,
                        Location = _locationService.GetNewLocation(bot.Location, move.FireDirection)
                    });
                    actionDescription += " & fire " + move.FireDirection;
                }
                else
                {
                    actionDescription += " & can't fire " + move.FireDirection;
                }
            }

            return new RoundPartialHistory
            {
                Caption = string.Format("Round {0} {1}: {2}", roundNumber, bot.Name, actionDescription),
                BoardState = _field.ExportState()
            };
        }
Esempio n. 7
0
 private bool IsMoveValid(TankBlasterBot bot, BotMove move)
 {
     var newLocation = _locationService.GetNewLocation(bot.Location, move.Direction);
     return _locationService.IsLocationValid(newLocation) && _field.Board[newLocation.X, newLocation.Y] == BoardTile.Empty
            && !_field.Bots.Any(blasterBot => blasterBot.Id != bot.Id && blasterBot.Location == newLocation);
 }
Esempio n. 8
0
 private bool IsMissileAvailable(TankBlasterBot bot, int roundNumber)
 {
     return roundNumber - _gameConfig.RoundsBetweenMissiles > bot.LastMissileFiredRound;
 }
Esempio n. 9
0
 private BotBattlefieldInfo GetBotBattlefieldInfo(TankBlasterBot bot, int roundNumber)
 {
     return new BotBattlefieldInfo
     {
         RoundNumber = roundNumber,
         BotId = bot.Id,
         Board = _field.Board,
         Bombs = _field.Bombs.Cast<IBomb>().ToList(),
         BotLocation = bot.Location,
         OpponentLocations = _field.Bots.Where(blasterBot => blasterBot.Id != bot.Id && !blasterBot.IsDead).Select(blasterBot => blasterBot.Location).ToList(),
         Missiles = _field.Missiles.Cast<IMissile>().ToList(),
         IsMissileAvailable = IsMissileAvailable(bot, roundNumber),
         GameConfig = _gameConfig
     };
 }
Esempio n. 10
0
        private int MissileAvailableIn(TankBlasterBot bot, int roundNumber)
        {

            int result = _gameConfig.RoundsBetweenMissiles - roundNumber + bot.LastMissileFiredRound;

            return bot.LastMissileFiredRound < 0 || result < 0 ? 0 : result;
        }