From: Stefano Rivera Date: Sat, 17 May 2014 12:26:17 +0000 (+0200) Subject: Bit shifts! X-Git-Tag: 0.1~114 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=653d96206e72f07934d6d562e2680ee8b3fb7db9;p=naja.git Bit shifts! --- diff --git a/data/location_decks/standard.yaml b/data/location_decks/standard.yaml index d0d4056..0ff3bc6 100644 --- a/data/location_decks/standard.yaml +++ b/data/location_decks/standard.yaml @@ -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 diff --git a/naja/actions.py b/naja/actions.py index 7ed4c6b..0ada21b 100644 --- a/naja/actions.py +++ b/naja/actions.py @@ -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,) diff --git a/naja/player.py b/naja/player.py index 2aad55b..b471c62 100644 --- a/naja/player.py +++ b/naja/player.py @@ -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): """