# Player bits
BITS = AttrDict({
# Direction bits
- 'NORTH': 0,
- 'SOUTH': 1,
- 'EAST': 2,
- 'WEST': 3,
+ 'NORTH': 1,
+ 'SOUTH': 2,
+ 'EAST': 4,
+ 'WEST': 8,
# Condition bits
- 'CYAN': 4,
- 'MAGENTA': 5,
- 'YELLOW': 6,
- 'MSB': 7,
+ 'CYAN': 16,
+ 'MAGENTA': 32,
+ 'YELLOW': 64,
+ 'MSB': 128,
})
DIRECTION_BITS = AttrDict((k, v) for k, v in BITS.items() if v < 4)
CONDITION_BITS = AttrDict((k, v) for k, v in BITS.items() if v >= 4)
# Operate on individual bits
def check_bit(self, bit):
- return bool(self.bits & (1 << bit))
+ return bool(self.bits & bit)
def set_bit(self, bit):
- self.bits |= (1 << bit)
+ self.bits |= bit
def clear_bit(self, bit):
- self.bits &= (0xff ^ (1 << bit))
+ self.bits &= (0xff ^ bit)
def toggle_bit(self, bit):
- self.bits ^= (1 << bit)
+ self.bits ^= bit
# Operate on sets of bits
class TestActions(TestCase):
def make_player(self, *bits):
- return Player(sum(1 << bit for bit in bits), None)
+ player_bits = 0
+ for bit in bits:
+ player_bits |= bit
+ return Player(player_bits, None)
def make_board(self, player_bits=None, locations=None):
if locations is None: