Пример #1
0
    def test_decrement_jail_card_count(self):
        state = GameState(1)
        player = state.players[0]

        # Test both decks
        dict_card_types = {
            CHANCE_CARD: 'Chance',
            COMMUNITY_CHEST_CARD: 'Community Chest'
        }
        for card_type, card_str in dict_card_types.iteritems():
            deck = state.decks[card_type]

            # Set up a player to have a 'Get out of jail free' card
            while deck.peek() != LMBDA_GET_OUT_OF_JAIL_FREE:
                state.apply(
                    GroupOfChanges([GameStateChange.draw_card(deck, player)]))
            state.apply(
                GroupOfChanges([GameStateChange.draw_card(deck, player)
                                ]))  # draw Jail Free card

            # Test difference in jail card count by looking at the difference in
            # GameStates' string encodings. Ensure that only the jail card count was
            # changed.
            str_before = str(state)
            state.apply(
                GroupOfChanges(
                    [GameStateChange.decrement_jail_card_count(player, deck)]))
            str_after = str(state)
            expected_diff = [('Jail free count: 1', 'Jail free count: 0')]
            self.assertDiffGameStates(
                str_before,
                str_after,
                expected_diff,
                msg='Jail free count was not decremented correctly')

            # Test that the Jail Free card was placed back on the bottom of the deck,
            # and that no additional copies of the Jail Free card are in the deck
            count = 0
            for i in range(0, deck.size() - 1):
                card = deck.draw()  # draw all cards except last one
                if card == LMBDA_GET_OUT_OF_JAIL_FREE:
                    count += 1
            self.assertEqual(
                count,
                0,
                msg=
                'Another Get out of jail free card is in the middle of the %s deck'
                % card_str)
            self.assertEqual(
                deck.peek(),
                LMBDA_GET_OUT_OF_JAIL_FREE,
                msg='Get out of jail free card was not replaced into %s deck' %
                card_str)
	def respond_to_state(self, player, new_state):
		if player.jail_moves > 0 and player.jail_free_count > 0:
			# Pick a Deck to return the jail free card to randomly
			# TODO: Need a better way of picking a Deck to return the jail free card to
			if (randint(0, 1) == 0):
				deck = new_state.decks[CHANCE_CARD]
			else:
				deck = new_state.decks[COMMUNITY_CHEST_CARD]
			use_card 		= GameStateChange.decrement_jail_card_count(player, deck)
			leave_jail 	= GameStateChange.leave_jail(player)
			return NotificationChanges(non_building_changes=[use_card, leave_jail])
		else:
			return NotificationChanges()
 def respond_to_state(self, player, new_state):
     if player.jail_moves > 0 and player.jail_free_count > 0:
         # Pick a Deck to return the jail free card to randomly
         # TODO: Need a better way of picking a Deck to return the jail free card to
         if (randint(0, 1) == 0):
             deck = new_state.decks[CHANCE_CARD]
         else:
             deck = new_state.decks[COMMUNITY_CHEST_CARD]
         use_card = GameStateChange.decrement_jail_card_count(player, deck)
         leave_jail = GameStateChange.leave_jail(player)
         return NotificationChanges(
             non_building_changes=[use_card, leave_jail])
     else:
         return NotificationChanges()
Пример #4
0
	def test_decrement_jail_card_count(self):
		state = GameState(1)
		player = state.players[0]

		# Test both decks
		dict_card_types = { CHANCE_CARD: 'Chance', COMMUNITY_CHEST_CARD: 'Community Chest' }
		for card_type, card_str in dict_card_types.iteritems():
			deck = state.decks[card_type]

			# Set up a player to have a 'Get out of jail free' card
			while deck.peek() != LMBDA_GET_OUT_OF_JAIL_FREE:
				state.apply(GroupOfChanges([
					GameStateChange.draw_card(deck, player)]))
			state.apply(GroupOfChanges([
				GameStateChange.draw_card(deck, player)])) # draw Jail Free card

			# Test difference in jail card count by looking at the difference in
			# GameStates' string encodings. Ensure that only the jail card count was
			# changed.
			str_before = str(state)
			state.apply(GroupOfChanges([
				GameStateChange.decrement_jail_card_count(player, deck)]))
			str_after = str(state)
			expected_diff = [
				('Jail free count: 1', 'Jail free count: 0')
			]
			self.assertDiffGameStates(str_before, str_after, expected_diff,
				msg='Jail free count was not decremented correctly')

			# Test that the Jail Free card was placed back on the bottom of the deck,
			# and that no additional copies of the Jail Free card are in the deck
			count = 0
			for i in range(0, deck.size() - 1):
				card = deck.draw()  # draw all cards except last one
				if card == LMBDA_GET_OUT_OF_JAIL_FREE:
					count += 1
			self.assertEqual(count, 0,
				msg='Another Get out of jail free card is in the middle of the %s deck' % card_str)
			self.assertEqual(deck.peek(), LMBDA_GET_OUT_OF_JAIL_FREE,
				msg='Get out of jail free card was not replaced into %s deck' % card_str)