def test_fountain_fail_to_start_out_of_town(self): """Try to start out of town with Fountain card when we don't have enough Craftsman actions. """ d = TestDeck() game = test_setup.two_player_lead('Craftsman', buildings=[['Fountain'], []], deck=d) p1, p2 = game.players game.in_town_sites = ['Rubble'] game.out_of_town_sites = ['Rubble', 'Wood'] game.library.set_content([d.dock0, d.dock1]) a = message.GameAction(message.USEFOUNTAIN, True) game.handle(a) self.assertEqual(p1.fountain_card, d.dock0) self.assertEqual(game.expected_action, message.FOUNTAIN) mon = Monitor() mon.modified(game) a = message.GameAction(message.FOUNTAIN, d.dock0, None, 'Wood') with self.assertRaises(GTRError): game.handle(a) self.assertFalse(mon.modified(game))
def test_not_enough_cards_and_actions(self): """Lead a role without enough cards. """ d = self.deck a = message.GameAction(message.LEADROLE, 'Laborer', 0, d.latrine0) mon = Monitor() mon.modified(self.game) with self.assertRaises(GTRError) as cm: self.game.handle(a) self.assertFalse(mon.modified(self.game)) a = message.GameAction(message.LEADROLE, 'Laborer', 1) with self.assertRaises(GTRError) as cm: self.game.handle(a) self.assertFalse(mon.modified(self.game)) a = message.GameAction(message.LEADROLE, 'Laborer', 0) with self.assertRaises(GTRError) as cm: self.game.handle(a) self.assertFalse(mon.modified(self.game))
def test_fountain_start_out_of_town(self): """Test using a fountain to look at the top card and then start a building out of town with it. """ d = TestDeck() game = test_setup.two_player_lead('Craftsman', buildings=[['Fountain'], []], clientele=[['Market'], []], deck=d) p1, p2 = game.players game.in_town_sites = ['Rubble'] game.out_of_town_sites = ['Rubble', 'Wood'] game.library.set_content([d.dock0, d.dock1]) a = message.GameAction(message.USEFOUNTAIN, True) game.handle(a) self.assertEqual(p1.fountain_card, d.dock0) self.assertEqual(game.expected_action, message.FOUNTAIN) a = message.GameAction(message.FOUNTAIN, d.dock0, None, 'Wood') game.handle(a) self.assertNotIn(d.dock0, p1.hand) self.assertIsNone(p1.fountain_card) self.assertIn('Dock', p1.building_names) self.assertFalse(game._player_has_active_building(p1, 'Bath')) self.assertEqual(game.expected_action, message.THINKERORLEAD)
def test_fountain_add(self): """Test using a fountain to look at the top card and then add it as a material to a building, completing it. """ bath, atrium, foundry = cm.get_cards(['Bath', 'Atrium', 'Foundry']) self.game.library.cards.insert(0, bath) self.p1.buildings.append(Building(atrium, 'Brick', materials=[foundry])) a = message.GameAction(message.USEFOUNTAIN, True) self.game.handle(a) self.assertEqual(self.p1.fountain_card, bath) self.assertEqual(self.game.expected_action, message.FOUNTAIN) a = message.GameAction(message.FOUNTAIN, atrium, bath, None) self.game.handle(a) self.assertNotIn(bath, self.p1.hand) self.assertIsNone(self.p1.fountain_card) self.assertTrue( self.game._player_has_active_building(self.p1, 'Atrium')) self.assertEqual(self.game.expected_action, message.THINKERORLEAD)
def test_bridge_over_palisade(self): """Palisade does nothing in the face of a Bridge. """ d = self.deck self.p1.hand.set_content([d.road0]) self.p2.hand.set_content([d.bar0]) self.p2.stockpile.set_content([d.latrine0]) self.game.pool.set_content([d.insula0]) a = message.GameAction(message.LEGIONARY, d.road0) self.game.handle(a) a = message.GameAction(message.TAKEPOOLCARDS, d.insula0) self.game.handle(a) self.assertEqual(self.game.expected_action, message.GIVECARDS) a = message.GameAction(message.GIVECARDS, d.bar0, d.latrine0) self.game.handle(a) self.assertIn(d.bar0, self.p1.stockpile) self.assertIn(d.insula0, self.p1.stockpile) self.assertIn(d.latrine0, self.p1.stockpile)
def test_skip_one_legionary_from_pool(self): """Skip taking one card from the pool but do take the other. """ d = self.deck self.p1.hand.set_content([d.atrium0, d.shrine0]) self.game.pool.set_content([d.foundry0, d.bath0]) a = message.GameAction(message.LEGIONARY, d.atrium0, d.shrine0) self.game.handle(a) self.assertEqual(self.game.expected_action, message.TAKEPOOLCARDS) a = message.GameAction(message.TAKEPOOLCARDS, d.bath0) self.game.handle(a) self.assertIn(d.foundry0, self.game.pool) self.assertNotIn(d.foundry0, self.p1.stockpile) self.assertNotIn(d.bath0, self.game.pool) self.assertIn(d.bath0, self.p1.stockpile) self.assertIn(d.atrium0, self.p1.revealed) self.assertIn(d.shrine0, self.p1.revealed) self.assertEqual(self.game.expected_action, message.GIVECARDS)
def test_bath_reveal_same_card_twice(self): d = self.deck a = message.GameAction(message.PATRONFROMPOOL, d.shrine0) self.game.handle(a) a = message.GameAction(message.LEGIONARY, d.dock0) self.game.handle(a) a = message.GameAction(message.TAKEPOOLCARDS) self.game.handle(a) a = message.GameAction(message.GIVECARDS) self.game.handle(a) self.assertIn(d.dock0, self.p1.revealed) a = message.GameAction(message.PATRONFROMPOOL, d.road0) self.game.handle(a) a = message.GameAction(message.LABORER) self.game.handle(a) a = message.GameAction(message.PATRONFROMPOOL, d.shrine1) self.game.handle(a) a = message.GameAction(message.LEGIONARY, d.dock0) mon = Monitor() mon.modified(self.game) with self.assertRaises(GTRError): self.game.handle(a) self.assertFalse(mon.modified(self.game))
def test_expects_givecards(self): """The Game should expect a TAKEPOOLCARDS action. """ d = self.deck self.p1.hand.set_content([d.atrium0]) self.game.pool.set_content([d.foundry0]) a = message.GameAction(message.LEGIONARY, d.atrium0) self.game.handle(a) a = message.GameAction(message.TAKEPOOLCARDS, d.foundry0) self.game.handle(a) self.assertEqual(self.game.expected_action, message.GIVECARDS) self.assertEqual(self.game.active_player, self.p2) self.assertEqual(self.game.legionary_player, self.p1)
def test_handle_do_lead(self): """ Responding with False should expect LEADROLE response. """ a = message.GameAction(message.THINKERORLEAD, False) self.game.handle(a) self.assertEqual(self.game.expected_action, message.LEADROLE)
def setUp(self): """ This is run prior to every test. """ d = self.deck = test_setup.TestDeck() self.game = test_setup.simple_two_player() self.p1, self.p2 = self.game.players # Indicate that p1 will lead a = message.GameAction(message.THINKERORLEAD, False) self.game.handle(a) self.p1.hand.set_content([d.jack0]) # p1 leads Laborer a = message.GameAction(message.LEADROLE, 'Laborer', 1, d.jack0) self.game.handle(a)
def test_handle_do_thinker(self): """ Responding with True should do expect THINKERTYPE response. """ a = message.GameAction(message.THINKERORLEAD, True) self.game.handle(a) self.assertEqual(self.game.expected_action, message.THINKERTYPE)
def test_complete_building(self): """ Complete a building by adding a material. """ statue, temple, fountain, stairway = cm.get_cards( ['Statue', 'Temple', 'Fountain', 'Stairway']) self.p1.hand.set_content([statue]) self.p1.buildings = [ Building(temple, 'Marble', materials=[fountain, stairway]) ] a = message.GameAction(message.CRAFTSMAN, temple, statue, None) self.game.handle(a) self.assertNotIn(statue, self.p1.hand) self.assertIn('Marble', self.p1.influence) self.assertTrue( self.game._player_has_active_building(self.p1, 'Temple')) # The completed building keeps its site. A copy is added to influence. self.assertEqual( self.p1.buildings[0], Building(temple, 'Marble', materials=[fountain, stairway, statue], complete=True))
def test_skip_action(self): """ An action with (None, None, None) skips. """ a = message.GameAction(message.CRAFTSMAN, None, None, None) self.game.handle(a) self.assertEqual(self.game.leader_index, 1) self.assertEqual(self.game.expected_action, message.THINKERORLEAD)
def test_do_thinker(self): """ Responding with True should do expect THINKERTYPE response. """ a = message.GameAction(message.FOLLOWROLE, 0) self.game.handle(a) self.assertEqual(self.game.expected_action, message.THINKERTYPE) self.assertEqual(self.p2.n_camp_actions, 0)
def test_start_and_add(self): """Start a building and add a material. """ wall, tower = cm.get_cards(['Wall', 'Tower']) self.p1.stockpile.set_content([wall]) self.p1.hand.set_content([tower]) a = message.GameAction(message.ARCHITECT, tower, None, 'Concrete') self.game.handle(a) self.assertEqual(self.p1.buildings[0], Building(tower, 'Concrete')) a = message.GameAction(message.ARCHITECT, tower, wall, None) self.game.handle(a) self.assertEqual(self.p1.buildings[0], Building(tower, 'Concrete', materials=[wall]))
def test_laborer_with_storeroom_client(self): d = self.deck self.assertTrue(self.game._player_has_active_building(self.p1, 'Storeroom')) self.game.pool.set_content([d.shrine0, d.foundry0]) a = message.GameAction(message.LABORER, d.shrine0) self.game.handle(a) a = message.GameAction(message.LABORER, d.foundry0) self.game.handle(a) self.assertIn(d.shrine0, self.p1.stockpile) self.assertIn(d.foundry0, self.p1.stockpile) self.assertEqual(self.game.expected_action, message.THINKERORLEAD)
def test_thinker_for_jack_from_empty(self): """Thinker for Jack with empty hand should yield a hand of one Jack. """ a = message.GameAction(message.THINKERTYPE, True) self.game.handle(a) self.assertEqual(len(self.p1.hand), 1) self.assertIn('Jack', self.p1.hand)
def test_thinker_for_five(self): """ Test thinker from empty hand to 5 orders cards. """ a = message.GameAction(message.THINKERTYPE, False) self.game.handle(a) self.assertEqual(len(self.p1.hand), 5)
def test_laborer_one_from_pool(self): d = self.deck self.game.pool.set_content([d.atrium0]) a = message.GameAction(message.LABORER, d.atrium0) self.game.handle(a) self.assertNotIn(d.atrium0, self.game.pool) self.assertIn(d.atrium0, self.p1.stockpile)
def test_thinker_for_one(self): self.p1.hand.set_content(cm.get_cards(['Latrine'] * 5)) self.assertEqual(len(self.p1.hand), 5) a = message.GameAction(message.THINKERTYPE, False) self.game.handle(a) self.assertEqual(len(self.p1.hand), 6) self.assertFalse('Jack' in self.p1.hand)
def test_waiting_for_thinker(self): """ Tests that the game is expecting a THINKERTYPE. """ self.assertEqual(self.game.expected_action, message.THINKERTYPE) a = message.GameAction(message.SKIPTHINKER, False) with self.assertRaises(GTRError): self.game.handle(a)
def test_shrine_hand_limit(self): d = self.deck self.p1.hand.set_content([]) self.p1.buildings.append(Building(d.shrine, 'Brick', complete=True)) a = message.GameAction(message.THINKERTYPE, False) self.game.handle(a) self.assertEqual(len(self.p1.hand), 7)
def test_follow_with_too_few_cards_and_actions(self): """Follow with not enough cards or action specified """ d = self.deck self.p2.hand.set_content([d.latrine0]) a = message.GameAction(message.FOLLOWROLE, 0, d.latrine0) mon = Monitor() mon.modified(self.game) with self.assertRaises(GTRError) as cm: self.game.handle(a) self.assertFalse(mon.modified(self.game)) a = message.GameAction(message.FOLLOWROLE, 1) with self.assertRaises(GTRError) as cm: self.game.handle(a) self.assertFalse(mon.modified(self.game))
def test_legionary_palisade_give_cards_anyway(self): d = self.deck self.assertEqual(self.game.expected_action, message.GIVECARDS) a = message.GameAction(message.GIVECARDS, d.bar0) self.game.handle(a) self.assertIn(d.bar0, self.p1.stockpile) self.assertIn(d.insula0, self.p1.stockpile)
def test_thinker_for_cards_many_times(self): """ Thinker several times in a row for both players. Hands start empty. """ a = message.GameAction(message.THINKERORLEAD, True) b = message.GameAction(message.THINKERTYPE, False) for i in range(10): # Player 1 self.game.handle(a) self.game.handle(b) # Player 2 self.game.handle(a) self.game.handle(b) self.assertEqual(len(self.game.players[0].hand), 14) self.assertEqual(len(self.game.players[1].hand), 14)
def test_fountain_skip(self): """Test using a fountain to look at the top card and then skip the action, drawing the card. """ bath = cm.get_card('Bath') self.game.library.cards.insert(0, bath) a = message.GameAction(message.USEFOUNTAIN, True) self.game.handle(a) self.assertEqual(self.p1.fountain_card, bath) self.assertEqual(self.game.expected_action, message.FOUNTAIN) a = message.GameAction(message.FOUNTAIN, None, None, None) self.game.handle(a) self.assertIn(bath, self.p1.hand) self.assertIsNone(self.p1.fountain_card) self.assertEqual(self.game.expected_action, message.THINKERORLEAD)
def test_thinker_for_four_cards_with_one_jack(self): """ Thinker for cards with 1 card in hand should draw 4. Test with initial card being a Jack or Latrine """ self.p1.hand.set_content(cm.get_cards(['Jack'])) a = message.GameAction(message.THINKERTYPE, False) self.game.handle(a) self.assertEqual(len(self.p1.hand), 5)
def test_thinker_for_jack_from_full(self): """ Thinker for Jack with full hand should draw Jack. """ self.p1.hand.set_content(cm.get_cards(['Latrine'] * 5)) a = message.GameAction(message.THINKERTYPE, True) self.game.handle(a) self.assertEqual(len(self.p1.hand), 6) self.assertIn('Jack', self.p1.hand)
def setUp(self): """ This is run prior to every test. """ self.deck = test_setup.TestDeck() self.game = test_setup.simple_two_player() self.p1, self.p2 = self.game.players # Indicate that we want to lead a = message.GameAction(message.THINKERORLEAD, False) self.game.handle(a)
def setUp(self): self.deck = TestDeck() d = self.deck self.game = test_setup.two_player_lead('Legionary', buildings=[[], ['Wall']], deck=self.deck) self.p1, self.p2 = self.game.players self.p1.hand.set_content([d.road0]) self.game.pool.set_content([d.insula0]) self.p2.hand.set_content([d.bar0]) a = message.GameAction(message.LEGIONARY, d.road0) self.game.handle(a) a = message.GameAction(message.TAKEPOOLCARDS, d.insula0) self.game.handle(a)