public void SelectZone(Zone zone) { Debug.Log("SELECT ZONE1! " + zone); UnselectAllZones(); Debug.Log("SELECT ZONE2! " + zone); selectedZones.Add(zone); Debug.Log("SELECT ZONE3! " + zone); zone.Select(); Debug.Log("SELECT ZONE4! " + zone); Main.instance.dude.GotTo(zone); }
static Command solve(IEnumerable<Drone> myDrones, Zone[] zones, bool IsFirstLoop = true) { if (!myDrones.Any()) return null; var drone = myDrones.First(); Command bestCommand = null; foreach (var zone in zones.Where(z => z.RequiredDrones > 0)) { //log("Testing drone #{0} at zone #{1}", drone.Index, zone.Index); var oldZoneTurns = zone.Turns; zone.RequiredDrones--; var overTakesZone = zone.RequiredDrones == 0; zone.Turns = Math.Max(zone.Turns, drone.SquareDistanceTo(zone) / 10000 - 1); var nextCommand = solve(myDrones.Skip(1), zones, false); var isBest = bestCommand == null; if (!isBest) { var bestCommandArray = flatten(bestCommand); var bestOverTakenZones = bestCommandArray.Select(c => c.OvertakesZone).Count(); var commandArray = flatten(nextCommand); var overTakenZones = commandArray.Select(c => c.OvertakesZone).Count(); isBest = overTakenZones > bestOverTakenZones; if (overTakenZones == bestOverTakenZones) { var bestScore = bestCommandArray.Where(c => c.OvertakesZone).Sum(c => c.Turns); var score = commandArray.Where(c => c.OvertakesZone).Sum(c => c.Turns); isBest = score > bestScore; } } if (isBest) { //log("Choosing drone #{0} to zone #{1}", drone.Index, zone.Index); bestCommand = new Command { Drone = drone, Zone = zone, Destination = zone, //TODO: Move to the outer rim of the zone OvertakesZone = overTakesZone, Turns = overTakesZone ? zone.Turns : 0, Next = nextCommand }; } zone.RequiredDrones++; zone.Turns = oldZoneTurns; } if (bestCommand == null) //There are NO zones to win { //TODO: Also choose this if the best zone still can't be captured //log("No zone to win for drone #{0}.", drone.Index); //TODO: Move to a strategic position instead var centerOfZones = new Point { X = (int)zones.Select(z => z.X).Average(), Y = (int)zones.Select(z => z.Y).Average() }; bestCommand = new Command { Drone = drone, Destination = centerOfZones, Next = solve(myDrones.Skip(1), zones, false) }; } return bestCommand; }