board.player.bits.set_bits(player_bits)
return board
+ def make_location_card(self, bits=(), name='card', actions=()):
+ return LocationCard(name, set(bits), list(actions), None)
+
def assert_player_bits(self, board, *bits):
self.assertEqual(sum(1 << bit for bit in bits), board.player.bits.bits)
def test_SetBits(self):
board = self.make_board()
state_before = board.export()
- card = LocationCard('card', set([BITS.MSB, BITS.NORTH]), [])
+ card = self.make_location_card([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('card', set([BITS.MSB, BITS.NORTH]), [])
+ card = self.make_location_card([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('card', set([BITS.BLUE, BITS.NORTH]), [])
+ card = self.make_location_card([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('card', set([BITS.BLUE, BITS.NORTH]), [])
+ card = self.make_location_card([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('card', set([BITS.MSB, BITS.NORTH]), [])
+ card = self.make_location_card([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('card', set([BITS.BLUE, BITS.NORTH]), [])
+ card = self.make_location_card([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('card', set([BITS.BLUE, BITS.NORTH]), [])
+ card = self.make_location_card([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 test_export_new_board(self):
board = GameBoard.new_game({'cards': [
{'card_name': 'card1', 'actions': [
- {
- 'action_class': 'LoseHealthOrMSB',
- 'required_bits': [],
- }, {
- 'action_class': 'GainHealth',
- 'required_bits': [BITS.RED],
- },
- ]}]})
+ {
+ 'action_class': 'LoseHealthOrMSB',
+ 'required_bits': [],
+ }, {
+ 'action_class': 'GainHealth',
+ 'required_bits': [BITS.RED],
+ },
+ ]}]})
exported_state = board.export()
board_locations = exported_state.pop('board_locations')
self.assertEqual(exported_state, {
'player': board.player.export(),
'puzzle': False,
'player_mode': EXAMINE,
+ 'replacement_params': None,
+ 'clock_count': 0,
})
positions = []
for position, location_state in board_locations:
positions.append(position)
- self.assertEqual(
- sorted(location_state.keys()), ['actions', 'bitwise_operand',
- 'card_name', 'max_number'])
+ self.assertEqual(sorted(location_state.keys()), [
+ 'actions', 'bitwise_operand', 'card_name', 'max_number',
+ 'replacement_time'])
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({'card_name': 'card',
- 'actions': []})
+ location = LocationCard.new_location(
+ {'card_name': 'card', 'actions': []}, None)
+ [action] = location.actions
+ self.assertEqual(type(action), actions.DoNothing)
+ self.assertEqual(action.required_bits, set())
+ self.assertEqual(location.replacement_time, None)
+
+ def test_new_location_replacement_params(self):
+ location = LocationCard.new_location(
+ {'card_name': 'card', 'actions': []},
+ {'chance': 1, 'min': 2, 'max': 2})
[action] = location.actions
self.assertEqual(type(action), actions.DoNothing)
self.assertEqual(action.required_bits, set())
+ self.assertEqual(location.replacement_time, 2)
def test_new_location_one_action(self):
- location = LocationCard.new_location({'card_name': 'card1',
- 'actions': [{'required_bits': [], 'action_class': 'DoNothing'},
- ]})
+ location = LocationCard.new_location({
+ 'card_name': 'card1',
+ 'actions': [
+ {'required_bits': [], 'action_class': 'DoNothing'},
+ ]}, None)
[action] = location.actions
self.assertEqual(type(action), actions.DoNothing)
self.assertEqual(action.required_bits, set())
+ self.assertEqual(location.replacement_time, None)
def test_parse_bits(self):
self.assertEqual(