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)); }
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 }); }
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() }); }
private bool IsMissileAvailable(TankBlasterBot bot, int roundNumber) { return(roundNumber - _gameConfig.RoundsBetweenMissiles > bot.LastMissileFiredRound); }
private int MissileAvailableIn(TankBlasterBot bot, int roundNumber) { int result = _gameConfig.RoundsBetweenMissiles - roundNumber + bot.LastMissileFiredRound; return(bot.LastMissileFiredRound < 0 || result < 0 ? 0 : result); }
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() }; }
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); }
private bool IsMissileAvailable(TankBlasterBot bot, int roundNumber) { return roundNumber - _gameConfig.RoundsBetweenMissiles > bot.LastMissileFiredRound; }
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 }; }
private int MissileAvailableIn(TankBlasterBot bot, int roundNumber) { int result = _gameConfig.RoundsBetweenMissiles - roundNumber + bot.LastMissileFiredRound; return bot.LastMissileFiredRound < 0 || result < 0 ? 0 : result; }