def summary_text(self, result, summary): # Mostly like the results from the AiServer, but with "and" in the lists. year = summary[3] players = summary.fold()[2:] if not result: result_line = "Game finished in %s." % (year,) elif result[0] is SLO: winner = result[2] result_line = "Solo Declared in %s. Winner is %s." % (year, winner) elif result == +DRW: winners = expand_list(p[0] for p in players if not p[4:]) result_line = "DIAS Draw Declared in %s. Powers in the draw are %s." % (year, winners) elif result[0] is DRW: winners = expand_list(result.fold()[1]) result_line = "Partial Declared in %s. Powers in the draw are %s." % (year, winners) lines = [ result_line, "", "The Powers were :", ] for player in players: lines.append("%s %s %s %s" % (player[0], player[1][0], player[2][0], player[-1])) return "\n".join(lines)
def generate_build_orders(self, build_count, values): ''' Generate the build orders for an adjustment turn''' self.log_debug(10, "Build orders for %s", self.map.current_turn) orders = OrderSet(self.power) # Put all the locations of our open home centres into a map self.log_debug(11, ' Choosing from locations of %s.', expand_list(self.power.homes)) build_map = [location.key for prov in [self.map.spaces[p] for p in self.power.homes] if prov.owner == self.power and not prov.units for location in prov.locations] # For each build, while we have a vacant home centre builds_remaining = build_count while build_map and builds_remaining: # Select the best location, more or less dest = self.random_destination(build_map, values) self.log_debug(13, " Considering build: %s", dest) build_map.remove(dest.key) if orders.has_order(dest.province): self.log_debug(13, ' Already building in %s', dest.province) else: self.log_debug(11, ' Ordering build') orders.add(BuildOrder(Unit(self.power, dest))) builds_remaining -= 1 # If not all builds ordered, order some waives. if builds_remaining: self.log_debug(11, " Waiving %d builds", builds_remaining) orders.waive(builds_remaining) return orders
def consider_convoy(self, fleet, orders, values, dest=None): if self.vals.convoy_weight > 0 and fleet.can_convoy(): self.log_debug(13, " Considering convoys through %s." % fleet) beach = None if dest: key = dest.province.is_coastal() if key: beach = self.map.locs[key] else: self.log_debug(13, " Selected location not coastal.") else: locations = self.map.locs possible = [] for border in fleet.location.borders_out: prov = locations[border].province if not orders.moving_into(prov): for unit in prov.units: # Don't land on our holding or unsure unit. # Side effect: prevents convoying a unit to itself. if not (self.friendly(unit.nation) and not orders.is_moving(unit)): key = prov.is_coastal() if key: possible.append(key) if possible: beach = self.random_destination(possible, values) self.log_debug(13, " %s selected for landing." % beach.province) else: self.log_debug(13, " No available landing sites.") if beach: # The last two conditions deserve explanation: # If it has already been ordered, we run the risk of an # inconsistent order set. If it can move there anyway, # a support is usually better than a convoy. # (Granted, that could be the solution to BUL/CON...) armies = [unit.location.key for unit in self.map.units if unit.can_be_convoyed() and self.friendly(unit.nation) and fleet.can_move_to(unit.location.province) and not orders.get_order(unit) and not unit.can_move_to(beach.province.key)] if armies: # Consider the army we least want to keep in place. army = self.random_source(armies, values) self.log_debug(13, ' %s chosen (from among %s).' % (army, expand_list([key[1] for key in armies]))) if dest: alternate = fleet.location else: alternate = beach convoy_value = values.destination_value[alternate.key] * self.vals.convoy_weight army_value = values.destination_value[army.key] convoy_best = army_value < convoy_value if convoy_best: first = convoy_value; second = army_value else: first = army_value; second = convoy_value if convoy_best != self.weighted_choice(first, second): self.log_debug(11, " Ordered to convoy") unit = [u for u in self.map.units if u.location.key == army.key][0] orders.add(ConvoyedOrder(unit, beach, [fleet]), unit.nation) return ConvoyingOrder(fleet, unit, beach) else: self.log_debug(13, " Convoy rejected") else: self.log_debug(13, " Nobody available to convoy") return None
def handle_DRW(self, message): if len(message) > 2: self.output('Draw declared among %s', expand_list(message[2:-1])) else: self.output('Draw declared among surviving players')