public static List <Command> GenerateCommandQueue() { foreach (var ship in AvailableShips) { var dirs = DirectionExtensions.ALL_CARDINALS.ToList(); if (ship.CellHalite > 0) { dirs.Insert(0, Direction.STILL); } else { dirs.Add(Direction.STILL); } if (dirs.Any(d => Safety.IsSafeMove(ship, d))) { AddMove(ship.Move(dirs.First(d => Safety.IsSafeMove(ship, d)), "Left-over ship, making move from fleet logic.")); } else if (dirs.Any(d => !CollisionCells.Contains(GameInfo.CellAt(ship, d)))) { AddMove(ship.Move(dirs.First(d => !CollisionCells.Contains(GameInfo.CellAt(ship, d))), "Left-over ship, Moving towards an enemy instead of crashing myself...")); } } var commands = usedShips.Values.ToList();; if (shouldSpawnShip) { commands.Add(GameInfo.Me.shipyard.Spawn()); } return(commands); }
public static void AddMove(Command command) { availableShipMoves.Remove(command.Ship); Safety.TwoTurnAvoider.Remove(command.TargetCell); usedShips[command.Ship] = command; collisionCells.Add(command.TargetCell); Log.LogMessage(command.Comment); if (availableShipMoves.Any(kvp => GameInfo.AvailableMoveCounts(kvp.Key, !command.Ship.OnDropoff) == 1)) { var shipToMove = availableShipMoves.First(kvp => GameInfo.AvailableMoveCounts(kvp.Key, !command.Ship.OnDropoff) == 1).Key; var dirs = shipToMove.OnDropoff ? DirectionExtensions.ALL_CARDINALS : DirectionExtensions.ALL_DIRECTIONS; if (dirs.Any(d => !CollisionCells.Contains(GameInfo.CellAt(shipToMove, d)))) { var dir = dirs.First(d => !CollisionCells.Contains(GameInfo.CellAt(shipToMove, d))); AddMove(shipToMove.Move(dir, $"Moving ship {shipToMove.Id} because there were no other moves remaining")); } } }