public void DoTurn(IPirateGame state) { // Initing stuff List <Island> islands = state.NotMyIslands(); List <Pirate> myPirates = state.MyPirates(); List <Pirate> copyPirates = new List <Pirate>(myPirates); Dictionary <Pirate, Island> pirateToIsland = new Dictionary <Pirate, Island>(); for (int i = 0; i < islands.Count; i++) { Pirate closestPirate = GetClosestPirate(state, islands[i], myPirates); //state.Debug($"closest: {closestPirate.Id.ToString()} to island: {islands[i]}"); if (closestPirate != null) { myPirates.Remove(closestPirate); pirateToIsland.Add(closestPirate, islands[i]); } } copyPirates.ForEach(pirate => { if (pirateToIsland.ContainsKey(pirate) && pirateToIsland[pirate] != null) { Island island = pirateToIsland[pirate]; state.Debug($"Pirate {pirate.Id.ToString()} to island {island.Id.ToString()}"); List <Direction> movingDirections = state.GetDirections(pirate, island); if (movingDirections.Count > 0 && !pirate.IsLost) { state.Debug($"Pirate: {pirate.Id.ToString()}"); movingDirections.ForEach(direc => { state.Debug($"{direc}"); }); state.SetSail(pirate, movingDirections[0]); } } else // Bot that has no island { state.Debug($"Nothing {pirate.Id.ToString()}"); Island closestIsland = GetClosestIsland(state, pirate, state.NotMyIslands()); if (closestIsland != null) { List <Direction> movingDirections = state.GetDirections(pirate, closestIsland); state.SetSail(pirate, movingDirections[0]); } } }); }