static void Main(string[] args) { Random randGen = new Random(); int turnCounter = 0; List <Field> takenFieldDestinations = new List <Field>(); // don't send several ships to the same Field List <Field> takenShotDestinations = new List <Field>(); // don't shoot at the same field as other ships // game loop while (true) { StartFunction("MainLoop"); takenFieldDestinations.Clear(); takenShotDestinations = GetShotsInTheAir(); ++turnCounter; int myShipCount = int.Parse(Console.ReadLine()); // the number of remaining ships int entityCount = int.Parse(Console.ReadLine()); // the number of entities (e.g. ships, mines or cannonballs) Gameboard.UpdateBoard(entityCount); foreach (var ship in Gameboard.GetPlayerShips() .OrderBy(x => x.EntityId)) { StartFunction("ShipLogic"); GetDesination() } Console.Out.Flush(); Console.Error.Flush(); StopFunction("MainLoop", LogLevel.INFO); } }
private static List <Field> GetShotsInTheAir() { StartFunction("GetShotsInTheAir"); List <Field> result = new List <Field>(); foreach (var shot in Gameboard.GetCannonballs()) { result.Add(Gameboard.Fields[shot.Col, shot.Row]); } StopFunction("GetShotsInTheAir", Program.LogLevel.TRACE); return(result); }
private static IEnumerable <Field> getBlockedFields(Ship ship) { var mines = Gameboard.GetMines(); var otherShips = Gameboard.GetShips().Where(x => x.EntityId != ship.EntityId); var cannonBalls = Gameboard.GetCannonballs(); return(mines.Cast <Entity>() .Concat(otherShips.Cast <Entity>()) .Concat(cannonBalls.Cast <Entity>()) .Select(x => Gameboard.Fields[x.Col, x.Row])); }