def __init__(self, *arg, **kw): # +2 to allow server->master and master->server connection since enet # allocates peers for both clients and hosts. this is done at # enet-level, not application-level, so even for masterless-servers, # this should not allow additional players. self.max_connections = self.max_players + 2 BaseProtocol.__init__(self, *arg, **kw) self.entities = [] self.players = {} self.player_ids = IDPool() self._create_teams() self.world = world.World() self.set_master() # safe position LUT # # Generates a LUT to check for safe positions. The slighly weird # sorting is used to sort by increasing distance so the nearest spots # get chosen first # product(repeat=3) is the equivalent of 3 nested for loops self.pos_table = list(product(range(-5, 6), repeat=3)) self.pos_table.sort(key=lambda vec: abs(vec[0] * 1.03) + abs(vec[1] * 1.02) + abs(vec[2] * 1.01))
def test_putting_back(self): pool = IDPool(start=5) self.assertEqual(5, pool.pop()) self.assertEqual(6, pool.pop()) pool.put_back(5) self.assertEqual(5, pool.pop())
def test_start(self): pool = IDPool(start=5) self.assertEqual(5, pool.pop())