コード例 #1
0
ファイル: teddybot.py プロジェクト: eswald/parlance
 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)
コード例 #2
0
ファイル: gameboard.py プロジェクト: eswald/parlance
 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)