From c56b1ffc5ce58be37ae4644327c7a6d4a92b1102 Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 11 May 2014 23:30:07 +0200 Subject: [PATCH 1/1] Unshift the world --- naja/constants.py | 16 ++++++++-------- naja/player.py | 8 ++++---- naja/tests/test_actions.py | 5 ++++- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/naja/constants.py b/naja/constants.py index 7442eb6..7a968d0 100644 --- a/naja/constants.py +++ b/naja/constants.py @@ -23,15 +23,15 @@ DEFAULT_MUSIC_VOLUME = 0.3 # music volume # 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) diff --git a/naja/player.py b/naja/player.py index c53c698..97422b8 100644 --- a/naja/player.py +++ b/naja/player.py @@ -20,16 +20,16 @@ class PlayerBits(object): # 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 diff --git a/naja/tests/test_actions.py b/naja/tests/test_actions.py index d2c723a..69ed881 100644 --- a/naja/tests/test_actions.py +++ b/naja/tests/test_actions.py @@ -8,7 +8,10 @@ from naja import actions 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: -- 2.34.1