# This field is ignored, but it's a useful place to put some action definitions
# we can reference later.
_standard_actions:
+ bad_default: &SET-BITS-DEFAULT
+ action_class: 'LoseHealthOrMSBAndSetBits'
+ required_bits: []
bad_default: &BAD-DEFAULT
action_class: 'LoseHealthOrMSB'
required_bits: []
required_bits: [YELLOW, MAGENTA]
cards:
- - actions: []
+ - actions:
+ - *SET-BITS-DEFAULT
- actions:
- *BAD-DEFAULT
- *TOGGLE-BITS-C
"""
TEXT = None
+ USES_MSB = False
def __init__(self, required_bits, **data):
bits = set()
class LoseHealthOrMSB(LocationAction):
- TEXT = "Lose health. If MSB is set, it will be cleared instead."
+ TEXT = "Lose health or MSB."
+ USES_MSB = True
def perform_action(self, board, location):
if not self.check_and_clear_MSB(board.player):
def perform_action(self, board, location):
board.player.bits.toggle_bits(location.bitwise_operand)
+
+
+class LoseHealthOrMSBAndSetBits(LocationAction):
+ TEXT = "Lose health or MSB, then set bits specified by this location."
+ USES_MSB = True
+
+ def perform_action(self, board, location):
+ if not self.check_and_clear_MSB(board.player):
+ board.lose_health()
+ board.player.bits.set_bits(location.bitwise_operand)
# Player bits
BITS = AttrDict({
# Direction bits
- 'NORTH': 1,
- 'SOUTH': 2,
- 'EAST': 4,
- 'WEST': 8,
+ 'NORTH': 0,
+ 'SOUTH': 1,
+ 'EAST': 2,
+ 'WEST': 3,
# Condition bits
- 'CYAN': 16,
- 'MAGENTA': 32,
- 'YELLOW': 64,
- 'MSB': 128,
+ 'CYAN': 4,
+ 'MAGENTA': 5,
+ 'YELLOW': 6,
+ 'MSB': 7,
})
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)
# Player defaults
PLAYER_DEFAULTS = AttrDict({
- 'INITIAL_BITS': BITS.NORTH | BITS.SOUTH | BITS.EAST | BITS.WEST,
+ 'INITIAL_BITS': 0x0f,
'INITIAL_POS': (2, 2),
'MAX_HEALTH': 4,
'WINS_REQUIRED': 4,
# Operate on individual bits
def check_bit(self, bit):
- return bool(self.bits & bit)
+ return bool(self.bits & (1 << bit))
def set_bit(self, bit):
- self.bits |= bit
+ self.bits |= (1 << bit)
def clear_bit(self, bit):
- self.bits &= (0xff ^ bit)
+ self.bits &= (0xff ^ (1 << bit))
def toggle_bit(self, bit):
- self.bits ^= bit
+ self.bits ^= (1 << bit)
# Operate on sets of bits