Bit shifts!
authorStefano Rivera <stefano@rivera.za.net>
Sat, 17 May 2014 12:26:17 +0000 (14:26 +0200)
committerStefano Rivera <stefano@rivera.za.net>
Sat, 17 May 2014 12:26:17 +0000 (14:26 +0200)
data/location_decks/standard.yaml
naja/actions.py
naja/player.py

index d0d4056a04f957f9d2d7fc90e6b01792edd523fc..0ff3bc6c7ec732e2e32aed90777c6cd46fad9118 100644 (file)
@@ -75,6 +75,21 @@ _action_definitions:
     action_class: 'GainHealth'
     required_bits: [RED, BLUE]
 
+  - &BITSHIFT-L
+    action_class: 'ShiftBits'
+    required_bits: [RED, BLUE]
+    data: {
+      'direction': 'left',
+      'shift': 1,
+    }
+  - &BITSHIFT-R
+    action_class: 'ShiftBits'
+    required_bits: [GREEN, BLUE]
+    data: {
+      'direction': 'right',
+      'shift': 1,
+    }
+
   # Three-colour actions.
   - &ACQUIRE-WIN-TOKEN
     action_class: 'AcquireWinToken'
@@ -161,6 +176,15 @@ _card_definitions:
       - *ROT-CCW
       - *SET-BITS-G
 
+  - &SHIFT-E-BITSHIFT
+    actions:
+      - *SHIFT-E
+      - *BITSHIFT-R
+  - &SHIFT-W-BITSHIFT
+    actions:
+      - *SHIFT-W
+      - *BITSHIFT-L
+
 cards:
   - *WIN-CARD-1
   - *WIN-CARD-2
@@ -174,5 +198,7 @@ cards:
   - *SHIFT-S-AND-HEAL
   - *SHIFT-E-AND-HEAL
   - *SHIFT-W-AND-HEAL
+  - *SHIFT-E-BITSHIFT
+  - *SHIFT-W-BITSHIFT
   - *ROT-CW-AND-SET
   - *ROT-CCW-AND-SET
index 7ed4c6b7fae55a7d49d2ec2d229ff0a05d36c422..0ada21be372024131d2175ce54b92fce58933ddb 100644 (file)
@@ -19,7 +19,10 @@ class LocationAction(object):
     def get_text(self, location=None):
         substitutions = self.data.copy()
 
-        if 'direction' in self.data:
+        if 'shift' in self.data:
+            substitutions['shift'] = self.data['shift']
+            substitutions['direction'] = self.data['direction']
+        elif 'direction' in self.data:
             substitutions['rowcol'] = {
                 'NORTH': 'column',
                 'SOUTH': 'column',
@@ -97,6 +100,18 @@ class ToggleBits(LocationAction):
         board.player.bits.toggle_bits(location.bitwise_operand)
 
 
+class ShiftBits(LocationAction):
+    TEXT = "Barrel-shift player %(shift)s bits %(direction)s."
+    GLYPHS = (ACTION_GLYPHS.CHANGE_BOARD,)
+
+    def perform_action(self, board, location):
+        shift = self.data['shift']
+        if self.data['direction'] == 'left':
+            board.player.bits.shift_bits_left(shift)
+        else:
+            board.player.bits.shift_bits_right(shift)
+
+
 class LoseHealthOrMSBAndSetBits(LocationAction):
     TEXT = "Lose {HEALTH} or {MSB}, then set %(location_bits)s."
     GLYPHS = (ACTION_GLYPHS.SET_BITS,)
index 2aad55b029a4c323cd4582f42727496a0215d4d2..b471c625135d4aea0d58af975a86e0a59e81c2a8 100644 (file)
@@ -49,6 +49,12 @@ class PlayerBits(object):
         for bit in bits:
             self.toggle_bit(bit)
 
+    def shift_bits_left(self, shift):
+        self.bits <<= shift
+
+    def shift_bits_right(self, shift):
+        self.bits >>= shift
+
 
 class Player(object):
     """