"""
TEXT = None
- REQUIRED_BITS = frozenset()
- def __init__(self, **data):
+ def __init__(self, required_bits, **data):
+ self.required_bits = required_bits
self.data = data
def check_available(self, player):
- return player.bits.check_bits(*self.REQUIRED_BITS)
+ return player.bits.check_bits(self.required_bits)
def perform_action(self, player, board):
raise NotImplementedError("TODO")
# Operate on sets of bits
- def check_bits(self, *bits):
+ def check_bits(self, bits):
return all(self.check_bit(bit) for bit in bits)
- def set_bits(self, *bits):
+ def set_bits(self, bits):
for bit in bits:
self.set_bit(bit)
- def clear_bits(self, *bits):
+ def clear_bits(self, bits):
for bit in bits:
self.clear_bit(bit)
- def toggle_bits(self, *bits):
+ def toggle_bits(self, bits):
for bit in bits:
self.toggle_bit(bit)
def test_check_bits(self):
bits = PlayerBits(0x03)
- self.assertEqual(bits.check_bits(BITS.NORTH), True)
- self.assertEqual(bits.check_bits(BITS.NORTH, BITS.SOUTH), True)
- self.assertEqual(bits.check_bits(BITS.CYAN), False)
- self.assertEqual(bits.check_bits(BITS.CYAN, BITS.MSB), False)
+ self.assertEqual(bits.check_bits([BITS.NORTH]), True)
+ self.assertEqual(bits.check_bits([BITS.NORTH, BITS.SOUTH]), True)
+ self.assertEqual(bits.check_bits([BITS.CYAN]), False)
+ self.assertEqual(bits.check_bits([BITS.CYAN, BITS.MSB]), False)
self.assertEqual(
- bits.check_bits(BITS.NORTH, BITS.SOUTH, BITS.CYAN), False)
+ bits.check_bits([BITS.NORTH, BITS.SOUTH, BITS.CYAN]), False)
def test_set_bits(self):
bits = PlayerBits(0x03)
self.assertEqual(bits._bits, 0x03)
- bits.set_bits(BITS.NORTH, BITS.CYAN)
+ bits.set_bits([BITS.NORTH, BITS.CYAN])
self.assertEqual(bits._bits, 0x13)
- bits.set_bits(BITS.NORTH, BITS.CYAN, BITS.MSB)
+ bits.set_bits([BITS.NORTH, BITS.CYAN, BITS.MSB])
self.assertEqual(bits._bits, 0x93)
def test_clear_bits(self):
bits = PlayerBits(0x03)
self.assertEqual(bits._bits, 0x03)
- bits.clear_bits(BITS.NORTH, BITS.CYAN)
+ bits.clear_bits([BITS.NORTH, BITS.CYAN])
self.assertEqual(bits._bits, 0x02)
- bits.clear_bits(BITS.NORTH, BITS.CYAN, BITS.MSB)
+ bits.clear_bits([BITS.NORTH, BITS.CYAN, BITS.MSB])
self.assertEqual(bits._bits, 0x02)
def test_toggle_bits(self):
bits = PlayerBits(0x03)
self.assertEqual(bits._bits, 0x03)
- bits.toggle_bits(BITS.NORTH, BITS.CYAN)
+ bits.toggle_bits([BITS.NORTH, BITS.CYAN])
self.assertEqual(bits._bits, 0x12)
- bits.toggle_bits(BITS.NORTH, BITS.CYAN)
+ bits.toggle_bits([BITS.NORTH, BITS.CYAN])
self.assertEqual(bits._bits, 0x03)
- bits.toggle_bits(BITS.NORTH, BITS.CYAN, BITS.MSB)
+ bits.toggle_bits([BITS.NORTH, BITS.CYAN, BITS.MSB])
self.assertEqual(bits._bits, 0x92)