def __init__(self): self.player = Player() cards_storage = CardsStorage() stack_level1 = CardsStack(CardLevel.ONE, cards_storage.cards_storage) stack_level2 = CardsStack(CardLevel.TWO, cards_storage.cards_storage) stack_level3 = CardsStack(CardLevel.THREE, cards_storage.cards_storage) self.cards_table = CardsTable(stack_level1, stack_level2, stack_level3) self.coins_table = CoinsTable() self.turn_validator = GameTurnValidator() self.turns_enumerator = GameTurnsEnumerator(self.coins_table, self.cards_table) self.current_turns_sequence = [] self.best_turns_sequences = [] self.best_turns_sequence_points = 0 self.current_first_turns_sequence = [] self.all_first_turns_sequences = []
def testGameTurn(self): coins_table = CoinsTable() turn = GameTurn((), self.cards_db[0]) player = Player() coins_table.takeCoins(CoinTypes.BLUE, 3) player.receiveCoins(CoinTypes.BLUE, 3) turn.payForPurchasedCard(player, coins_table) self.assertEqual(0, player.getCoinsCount(CoinTypes.BLUE)) self.assertEqual(3, turn.getPaidCoinsCount(CoinTypes.BLUE)) turn.returnPaymentForPurchasedCard(player, coins_table) self.assertEqual(3, player.getCoinsCount(CoinTypes.BLUE)) self.assertEqual(0, turn.getPaidCoinsCount(CoinTypes.BLUE)) turn = GameTurn((), self.cards_db[8]) coins_table.takeCoins(CoinTypes.GREEN, 3) player.receiveCoins(CoinTypes.GREEN, 3) player.receivePurchasedCard(self.cards_db[1]) player.receivePurchasedCard(self.cards_db[3]) player.receivePurchasedCard(self.cards_db[4]) turn.payForPurchasedCard(player, coins_table) self.assertEqual(3, player.getCoinsCount(CoinTypes.BLUE)) self.assertEqual(2, player.getCoinsCount(CoinTypes.GREEN)) self.assertEqual(0, turn.getPaidCoinsCount(CoinTypes.BLUE)) self.assertEqual(1, turn.getPaidCoinsCount(CoinTypes.GREEN)) turn.returnPaymentForPurchasedCard(player, coins_table) self.assertEqual(3, player.getCoinsCount(CoinTypes.BLUE)) self.assertEqual(3, player.getCoinsCount(CoinTypes.GREEN)) self.assertEqual(0, turn.getPaidCoinsCount(CoinTypes.BLUE)) self.assertEqual(0, turn.getPaidCoinsCount(CoinTypes.GREEN)) turn = GameTurn((), self.cards_db[8]) player.receivePurchasedCard(self.cards_db[9]) turn.payForPurchasedCard(player, coins_table) self.assertEqual(3, player.getCoinsCount(CoinTypes.BLUE)) self.assertEqual(2, player.getCoinsCount(CoinTypes.GREEN)) self.assertEqual(0, turn.getPaidCoinsCount(CoinTypes.BLUE)) self.assertEqual(1, turn.getPaidCoinsCount(CoinTypes.GREEN)) turn.returnPaymentForPurchasedCard(player, coins_table) self.assertEqual(3, player.getCoinsCount(CoinTypes.BLUE)) self.assertEqual(3, player.getCoinsCount(CoinTypes.GREEN)) self.assertEqual(0, turn.getPaidCoinsCount(CoinTypes.BLUE)) self.assertEqual(0, turn.getPaidCoinsCount(CoinTypes.GREEN))
def test_coins_table(self): coins_table = CoinsTable() self.assertEqual(CoinsTable.max_coins_count, coins_table.getCoinsCount(CoinTypes.BLACK)) coins_table.takeCoins(CoinTypes.RED) coins_table.takeCoins(CoinTypes.RED) self.assertEqual(CoinsTable.max_coins_count - 2, coins_table.getCoinsCount(CoinTypes.RED)) coins_table.returnCoins(CoinTypes.RED) coins_table.returnCoins(CoinTypes.RED) with self.assertRaises(AssertionError): coins_table.returnCoins(CoinTypes.RED) i = CoinsTable.max_coins_count while(i > 0): coins_table.takeCoins(CoinTypes.GREEN) i -= 1 with self.assertRaises(AssertionError): coins_table.takeCoins(CoinTypes.GREEN) self.assertEqual(0, coins_table.getCoinsCount(CoinTypes.GREEN))
def test_game_turns_enumerator(self): coins_table = CoinsTable() level1_stack = CardsStack(CardLevel.ONE, self.cards_db) level2_stack = CardsStack(CardLevel.TWO, self.cards_db) level3_stack = CardsStack(CardLevel.THREE, self.cards_db) cards_table = CardsTable(level1_stack, level2_stack, level3_stack) turns_enumerator = GameTurnsEnumerator(coins_table, cards_table) turns = turns_enumerator.enumerateAllPossibleTurns() self.assertEqual(10 + 12, len(turns)) self.assertEqual(GameTurn((CoinTypes.WHITE, CoinTypes.BLUE, CoinTypes.GREEN), None), turns[0]) self.assertEqual(GameTurn((CoinTypes.WHITE, CoinTypes.BLUE, CoinTypes.RED), None), turns[1]) self.assertEqual(GameTurn((CoinTypes.BLUE, CoinTypes.GREEN, CoinTypes.RED), None), turns[6]) self.assertEqual(GameTurn((CoinTypes.GREEN, CoinTypes.RED, CoinTypes.BLACK), None), turns[9]) self.assertEqual(GameTurn((), self.cards_db[0]), turns[10]) self.assertEqual(GameTurn((), self.cards_db[8]), turns[14]) self.assertEqual(GameTurn((), self.cards_db[16]), turns[18]) coins_table.takeCoins(CoinTypes.WHITE, CoinsTable.max_coins_count) coins_table.takeCoins(CoinTypes.BLUE, CoinsTable.max_coins_count) coins_table.takeCoins(CoinTypes.GREEN, CoinsTable.max_coins_count) turns = turns_enumerator.enumerateAllPossibleTurns() self.assertEqual(1 + 12, len(turns)) self.assertEqual(GameTurn((CoinTypes.RED, CoinTypes.BLACK), None), turns[0]) self.assertEqual(GameTurn((), self.cards_db[0]), turns[1]) coins_table.takeCoins(CoinTypes.RED, CoinsTable.max_coins_count) cards_table.takeCardByIndex(CardLevel.ONE, 0) cards_table.takeCardByIndex(CardLevel.ONE, 0) cards_table.takeCardByIndex(CardLevel.ONE, 0) cards_table.takeCardByIndex(CardLevel.ONE, 0) cards_table.takeCardByIndex(CardLevel.ONE, 0) turns = turns_enumerator.enumerateAllPossibleTurns() self.assertEqual(1 + 11, len(turns)) self.assertEqual(GameTurn((CoinTypes.BLACK, ), None), turns[0]) self.assertEqual(GameTurn((), self.cards_db[1]), turns[1])