def collect_orders(self, now, sco, country): orders = OrderSet() datc = DatcOptions() board = Map(self.variant) if sco: board.handle_SCO(sco) if now: board.handle_NOW(now) power = board.powers[country] phase = board.current_turn.phase() self.start_game(now, sco, country) for msg in self.replies: if msg[0] is SUB: for item in msg.fold()[1:]: order = createUnitOrder(item, power, board, datc) note = order.order_note(power, phase, orders) self.failUnlessEqual(note, MBV) orders.add(order, country) elif msg[0] is NOT and msg[2] is SUB: # Todo: Handle partial unsubmittals correctly. orders = OrderSet() return phase, power, orders
def generate_orders(self): orders = OrderSet(self.power) turn = self.map.current_turn phase = turn.phase() if phase == turn.move_phase: for unit in self.power.units: values = {} self.log_debug(9, unit) for site in unit.location.borders_out: space = self.map.spaces[site[1]] supply = 0 if space.is_supply(): if space.owner != self.power: supply = len(space.owner.centers) value = (supply, self.centrality[site]) values[value] = site self.log_debug(9, '%s: %s', site, value) destination = self.map.locs[values[max(values)]] order = MoveOrder(unit, destination) orders.add(order, unit.nation) elif phase == turn.build_phase: builds = -self.power.surplus() if builds > 0: values = [] for prov in self.power.homes: space = self.map.spaces[prov] if not space.units: for site in space.locations: val = self.centrality[site.key] values.append((val, site)) for value, site in sorted(values)[-builds:]: unit = Unit(self.power, site) order = BuildOrder(unit) orders.add(order, unit.nation) orders.complete_set(self.map) self.submit_set(orders)
def test_complete_waives(self): board = Map(standard) board.handle_NOW(NOW(WIN, 1901)(RUS, AMY, MOS)) orders = OrderSet() orders.complete_set(board) self.failUnlessEqual(len(orders), 21)