Beispiel #1
0
 def generate_move_combos(self):
     adj_provs = defaultdict(list)
     for unit in self.power.units:
         for key in unit.location.borders_out:
             dest = self.map.locs[key]
             if not any(other.nation == self.power
                     for other in dest.province.units):
                 adj_provs[key[1]].append(MoveOrder(unit, dest))
     return [OrderCombo(self, combo)
         for value in adj_provs.values()
         for combo in sublists(value)
         if combo]
Beispiel #2
0
 def unpack_message(self, data):
     r'''Produces a Message from a string of token numbers.
         Uses values in the representation, if available.
     '''#'''
     try:
         msg = self.rep.unpack(data)
     except ValueError:
         # Someone foolishly chose to disconnect over an unknown token.
         msg = None
     else:
         # Tokens in the "Reserved for AI use" category
         # must never be sent over the wire.
         if any('Reserved' in token.category_name() for token in msg):
             msg = None
     return msg
Beispiel #3
0
 def run_game(self, clients, games=1, **kwargs):
     self.set_option('games', games)
     server = self.connect_server()
     manager = self.manager
     
     for dummy in range(games):
         if server.closed: raise UserWarning('Server closed early')
         game = server.default_game()
         players = []
         for player_class in clients:
             player = manager.add_client(player_class, **kwargs)
             if not player:
                 raise UserWarning('Manager failed to start a client')
             players.append(player)
             manager.process(.2)
         while any(not p.closed for p in players):
             manager.process(2)
     return game
Beispiel #4
0
 def occupied(province, friendly=self.player.power.key):
     ''' Determines whether an enemy is in a space.'''
     return any(unit.nation != friendly for unit in province.units)