public Battlefield ExportState() { var arena = new Battlefield(Board.GetLength(0), Board.GetLength(1)); Board.ForEveryElement((x, y, val) => { arena.Board[x, y] = val; }); arena.Bots = Bots.Select(bot => new TankBlasterBot(bot)).ToList(); arena.Bombs = Bombs.Select(bomb => new Bomb(bomb)).ToList(); arena.Missiles = Missiles.Select(missile => new Missile(missile)).ToList(); return(arena); }
public int ComputeThreatScore(Position pos) { var threats = Bombs.Select((b) => { if (pos.x - b.pos.x == 0 && Math.Abs(pos.y - b.pos.y) <= b.power) { return(new Threat { ThreatLevel = ThreatLevel.Danger, Direction = Direction.North }); } else if (pos.x - b.pos.x == 0 && Math.Abs(b.pos.y - pos.y) <= b.power) { return(new Threat { ThreatLevel = ThreatLevel.Danger, Direction = Direction.South }); } else if (pos.y - b.pos.y == 0 && Math.Abs(pos.x - b.pos.x) <= b.power) { return(new Threat { ThreatLevel = ThreatLevel.Danger, Direction = Direction.West }); } else if (pos.y - b.pos.y == 0 && Math.Abs(b.pos.x - pos.x) <= b.power) { return(new Threat { ThreatLevel = ThreatLevel.Danger, Direction = Direction.East }); } return(new Threat { ThreatLevel = ThreatLevel.None, Direction = Direction.None }); }).Where((threat) => threat.ThreatLevel != ThreatLevel.None); return(threats.Count()); }