More tile juggling.
[naja.git] / naja / gameboard.py
index edda43c702c146211ec0fca2f016e44c89f5c626..367a9e15118b4cbd6b9fe3248a691c141f66831d 100644 (file)
@@ -130,6 +130,9 @@ class GameBoard(object):
         elif BITS[direction] == BITS.WEST:
             self.shift_location_row(-1, is_vertical=False)
 
+    def allow_chess_move(self, chesspiece):
+        self.player.allow_chess_move(chesspiece)
+
     def change_mode(self, new_mode):
         """Advance to the next mode"""
         if new_mode == self.player_mode:
@@ -170,17 +173,26 @@ class LocationCard(object):
     @classmethod
     def build_action(cls, definition):
         action_class = getattr(actions, definition['action_class'])
-        required_bits = definition['required_bits']
+        required_bits = cls.parse_bits(definition['required_bits'])
         data = definition.get('data', {})
         return action_class(required_bits, **data)
 
     @classmethod
     def new_location(cls, definition):
+        if 'bits' in definition:
+            bits = cls.parse_bits(definition['bits'])
+        else:
+            bits = cls.generate_bitwise_operand()
         return cls.import_location({
-            'bitwise_operand': cls.generate_bitwise_operand(),
+            'bitwise_operand': bits,
             'actions': definition['actions'],
         })
 
+    @classmethod
+    def parse_bits(self, bit_list):
+        # Convert names to numbers if applicable.
+        return frozenset(BITS.get(bit, bit) for bit in bit_list)
+
     def export(self):
         return {
             'bitwise_operand': self.bitwise_operand,