A particular set of options available on a location.
"""
- def __init__(self, bitwise_operand, location_actions):
+ def __init__(self, card_name, bitwise_operand, location_actions):
+ self.card_name = card_name
self.bitwise_operand = bitwise_operand
self.actions = location_actions
self.check_actions()
def import_location(cls, state):
location_actions = [
cls.build_action(definition) for definition in state['actions']]
- return cls(state['bitwise_operand'], location_actions)
+ return cls(state['card_name'], state['bitwise_operand'],
+ location_actions)
@classmethod
def build_action(cls, definition):
bits = cls.parse_bits(definition['bits'])
else:
bits = cls.generate_bitwise_operand()
+ card_name = definition['card_name']
return cls.import_location({
'bitwise_operand': bits,
'actions': definition['actions'],
+ 'card_name': card_name,
})
@classmethod
return {
'bitwise_operand': sorted(self.bitwise_operand),
'actions': [action.export() for action in self.actions],
+ 'card_name': self.card_name,
}
def check_actions(self):
def make_board(self, player_bits=None, locations=None):
if locations is None:
- locations = [{'actions': []}]
+ locations = [{'card_name': 'card', 'actions': []}]
board = GameBoard.new_game({'cards': locations})
if player_bits is not None:
board.player.bits.bits = 0
def test_SetBits(self):
board = self.make_board()
state_before = board.export()
- card = LocationCard(set([BITS.MSB, BITS.NORTH]), [])
+ card = LocationCard('card', set([BITS.MSB, BITS.NORTH]), [])
actions.SetBits(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(
def test_ToggleBits(self):
board = self.make_board(player_bits=[BITS.NORTH])
state_before = board.export()
- card = LocationCard(set([BITS.MSB, BITS.NORTH]), [])
+ card = LocationCard('card', set([BITS.MSB, BITS.NORTH]), [])
actions.ToggleBits(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(board.player.bits.check_bit(BITS.MSB), True)
def test_LoseHealthOrMSBAndSetBits_MSB_clear(self):
board = self.make_board(player_bits=[])
state_before = board.export()
- card = LocationCard(set([BITS.BLUE, BITS.NORTH]), [])
+ card = LocationCard('card', set([BITS.BLUE, BITS.NORTH]), [])
actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(state_after['health'], state_before['health'] - 1)
def test_LoseHealthOrMSBAndSetBits_MSB_set(self):
board = self.make_board(player_bits=[BITS.MSB])
state_before = board.export()
- card = LocationCard(set([BITS.BLUE, BITS.NORTH]), [])
+ card = LocationCard('card', set([BITS.BLUE, BITS.NORTH]), [])
actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card)
state_after = board.export()
self.assert_player_bits(board, BITS.BLUE, BITS.NORTH)
def test_LoseHealthOrMSBAndSetBits_MSB_set_and_on_card(self):
board = self.make_board(player_bits=[BITS.MSB])
state_before = board.export()
- card = LocationCard(set([BITS.MSB, BITS.NORTH]), [])
+ card = LocationCard('card', set([BITS.MSB, BITS.NORTH]), [])
actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card)
state_after = board.export()
self.assert_player_bits(board, BITS.MSB, BITS.NORTH)
board = self.make_board(player_bits=[BITS.NORTH])
board.lose_health()
state_before = board.export()
- card = LocationCard(set([BITS.BLUE, BITS.NORTH]), [])
+ card = LocationCard('card', set([BITS.BLUE, BITS.NORTH]), [])
actions.GainHealthAndClearBitsOrMSB(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(state_after['health'], state_before['health'] + 1)
board = self.make_board(player_bits=[BITS.MSB, BITS.NORTH])
board.lose_health()
state_before = board.export()
- card = LocationCard(set([BITS.BLUE, BITS.NORTH]), [])
+ card = LocationCard('card', set([BITS.BLUE, BITS.NORTH]), [])
actions.GainHealthAndClearBitsOrMSB(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(state_after['health'], state_before['health'] + 1)
def make_deck(self, cards=None):
if cards is None:
- cards = [{'actions': []}]
+ cards = [{'card_name': 'card', 'actions': []}]
return {'cards': cards}
def assert_state(self, state1, state2, exclude=(), player_exclude=()):
self.assertEqual(state1, state2)
def test_export_new_board(self):
- board = GameBoard.new_game({'cards': [{'actions': [
+ board = GameBoard.new_game({'cards': [
+ {'card_name' : 'card1', 'actions': [
{
'action_class': 'LoseHealthOrMSB',
'required_bits': [],
'health': 4,
'wins_required': 4,
'wins': 0,
- 'locations': [{'actions': [
+ 'locations': [{'card_name' : 'card1', 'actions': [
{
'action_class': 'LoseHealthOrMSB',
'required_bits': [],
for position, location_state in board_locations:
positions.append(position)
self.assertEqual(
- sorted(location_state.keys()), ['actions', 'bitwise_operand'])
+ sorted(location_state.keys()), ['actions', 'bitwise_operand',
+ 'card_name'])
self.assertEqual(location_state['actions'], [
{
'action_class': 'LoseHealthOrMSB',
self.assertEqual(bits, set(BITS.values()))
def test_new_location_no_actions(self):
- location = LocationCard.new_location({'actions': []})
+ location = LocationCard.new_location({'card_name': 'card',
+ 'actions': []})
[action] = location.actions
self.assertEqual(type(action), actions.DoNothing)
self.assertEqual(action.required_bits, set())
def test_new_location_one_action(self):
- location = LocationCard.new_location({'actions': [
- {'required_bits': [], 'action_class': 'DoNothing'},
+ location = LocationCard.new_location({'card_name': 'card1',
+ 'actions': [{'required_bits': [], 'action_class': 'DoNothing'},
]})
[action] = location.actions
self.assertEqual(type(action), actions.DoNothing)