3 class PlayerBits(object):
8 def __init__(self, bits):
16 def bits(self, value):
17 assert 0 <= value <= 0xff
20 # Operate on individual bits
22 def check_bit(self, bit):
23 return bool(self.bits & (1 << bit))
25 def set_bit(self, bit):
26 self.bits |= (1 << bit)
28 def clear_bit(self, bit):
29 self.bits &= (0xff ^ (1 << bit))
31 def toggle_bit(self, bit):
32 self.bits ^= (1 << bit)
34 # Operate on sets of bits
36 def check_bits(self, bits):
37 return all(self.check_bit(bit) for bit in bits)
39 def set_bits(self, bits):
43 def clear_bits(self, bits):
47 def toggle_bits(self, bits):
54 A representation of the player.
57 def __init__(self, bits, position):
58 self.bits = PlayerBits(bits)
59 self.position = position
62 def import_player(cls, definition):
63 return cls(definition['bits'], tuple(definition['position']))
67 'bits': self.bits.bits,
68 'position': list(self.position),