def test_player_removes_cards_on_turn_finish(self):
     self.player.new_game(Identifiers.NORTH, self.initial_hand)
     self.player.finish_turn(TroopCard(number=4, color="color1"),
                             TroopCard(number=2, color="color2"))
     self.assertNotIn(TroopCard(number=4, color="color1"), self.player.hand)
     self.assertIn(TroopCard(number=2, color="color2"), self.player.hand)
     self.assertEquals(7, len(self.player.hand))
 def test_player_can_get_next_action(self):
     self.player.new_game(Identifiers.NORTH, self.initial_hand)
     self.communication.clear()
     self.communication.add_response("play 4 color1,7")
     play = self.player.compute_turn(self.initial_board, True, None)
     self.assertEquals(play.card, TroopCard(number=7, color="color1"))
     self.assertEquals(play.flag, 4)
 def test_playing_card_north_flag_one(self):
     self.output.setup_player_positions('Synergy', Identifiers.NORTH)
     self.output.play_action(Identifiers.NORTH, TroopCard(1, "red"), 1)
     self.assertEqual(
         self.output.games.find({
             '_id': self.output.post_id
         }).next()['actionsTaken'][0], "Synergy plays 1 red 1")
 def test_drawing_card_north(self):
     self.output.setup_player_positions('Synergy', Identifiers.NORTH)
     self.output.draw_action(Identifiers.NORTH, TroopCard(1, "red"))
     self.assertEqual(
         self.output.games.find({
             '_id': self.output.post_id
         }).next()['actionsTaken'][0], "Synergy draws 1 red")
Ejemplo n.º 5
0
 def get_troop_cards(self):
     """
     Get the troop cards
     @return A list of all troop cards
     """
     return [
         TroopCard(number, color)
         for color, number in product(Identifiers.COLORS, range(1, 11))
     ]
Ejemplo n.º 6
0
 def test_send_player_hand_north(self):
     hand = [
         TroopCard(number, Identifiers.COLORS[0]) for number in range(1, 8)
     ]
     self.localCommandGenerator.send_player_hand(hand)
     cardString = "player north hand"
     for card in hand:
         cardString += " " + card.color + "," + str(card.number)
     self.assertEqual(self.mockCommunication.messages_received.pop(),
                      cardString)
Ejemplo n.º 7
0
 def test_send_flag_cards_one_card_south(self):
     flagList = [Flag() for _ in xrange(9)]
     flagList[8].add_card("south", TroopCard(1, Identifiers.COLORS[0]))
     self.localCommandGenerator.send_flag_cards(flagList)
     expectedStringListNorth, expectedStringListSouth = create_list_of_expected_flag_send_strings(
         flagList)
     for i, _ in enumerate(flagList):
         self.assertEqual(self.mockCommunication.messages_received.pop(0),
                          expectedStringListNorth[i])
         self.assertEqual(self.mockCommunication.messages_received.pop(0),
                          expectedStringListSouth[i])
 def setUp(self):
     self.communication = MockPlayerCommunication()
     self.player = SubprocessPlayer(self.communication)
     self.initial_hand = [
         TroopCard(number=1, color="color1"),
         TroopCard(number=2, color="color1"),
         TroopCard(number=3, color="color1"),
         TroopCard(number=4, color="color1"),
         TroopCard(number=5, color="color1"),
         TroopCard(number=6, color="color1"),
         TroopCard(number=7, color="color1")
     ]
     self.initial_board = Board()
    def test_player_receives_game_state_with_last_move(self):
        self.player.new_game(Identifiers.NORTH, self.initial_hand)
        self.communication.clear()
        self.player.compute_turn(
            self.initial_board, True,
            Play(card=TroopCard(number=3, color="color4"), flag=4))

        self.assertEquals(self.communication.messages_received, [
            "player north hand color1,1 color1,2 color1,3 color1,4 color1,5 color1,6 color1,7",
            "flag claim-status unclaimed unclaimed unclaimed unclaimed unclaimed unclaimed unclaimed unclaimed unclaimed",
            "flag 1 cards north", "flag 1 cards south", "flag 2 cards north",
            "flag 2 cards south", "flag 3 cards north", "flag 3 cards south",
            "flag 4 cards north", "flag 4 cards south", "flag 5 cards north",
            "flag 5 cards south", "flag 6 cards north", "flag 6 cards south",
            "flag 7 cards north", "flag 7 cards south", "flag 8 cards north",
            "flag 8 cards south", "flag 9 cards north", "flag 9 cards south",
            "opponent play 4 color4,3", "go play-card"
        ])
 def test_player_hand_diminishes_with_empty_deck(self):
     self.player.new_game(Identifiers.NORTH, self.initial_hand)
     self.player.finish_turn(TroopCard(number=4, color="color1"), None)
     self.assertNotIn(TroopCard(number=4, color="color1"), self.player.hand)
     self.assertEquals(6, len(self.player.hand))
Ejemplo n.º 11
0
 def test_constructor(self):
     play = Play(1, TroopCard(number=1,color="color1"))
     self.assertEquals(play.flag, 1)
     self.assertEquals(play.card, TroopCard(number=1,color="color1"))
Ejemplo n.º 12
0
 def test_from_tuple(self):
     play = Play.from_tuple((2, TroopCard(number=3,color="color4")))
     self.assertEquals(play.flag, 2)
     self.assertEquals(play.card, TroopCard(number=3,color="color4"))
Ejemplo n.º 13
0
 def test_keyword_constructor(self):
     play = Play(flag=2,card=TroopCard(number=3,color="color4"))
     self.assertEquals(play.flag, 2)
     self.assertEquals(play.card, TroopCard(number=3,color="color4"))
Ejemplo n.º 14
0
def make_troop_card_list(color_number_tuples):
    return [TroopCard(number, color) for color, number in color_number_tuples]
Ejemplo n.º 15
0
 def test_send_opponent_play(self):
     self.localCommandGenerator.send_opponent_play(
         2, TroopCard(2, Identifiers.COLORS[0]))
     self.assertEqual(self.mockCommunication.messages_received.pop(),
                      "opponent play 2 " + Identifiers.COLORS[0] + ",2")
Ejemplo n.º 16
0
 def test_output_play_card(self):
     self.output.play_action(Identifiers.NORTH, TroopCard(1, "puce"), 1)
     self.assertEqual(self.output.outputstring.rstrip(),
                      "player1 plays 1 puce 1")
Ejemplo n.º 17
0
 def test_output_draw_card(self):
     self.output.draw_action(Identifiers.NORTH, TroopCard(1, "puce"))
     self.assertEqual(self.output.outputstring.rstrip(),
                      "player1 draws 1 puce")
Ejemplo n.º 18
0
 def test_changing_player_name(self):
     self.output.setup_player_positions('A_POLAR_BEAR', Identifiers.NORTH)
     self.output.draw_action(Identifiers.NORTH, TroopCard(1, "magenta"))
     self.assertEqual(self.output.outputstring.rstrip(),
                      "A_POLAR_BEAR draws 1 magenta")
Ejemplo n.º 19
0
 def __get_minimum_strength_formation(self):
     return [TroopCard(1, Identifiers.COLORS[0]), TroopCard(1, Identifiers.COLORS[1]), TroopCard(0, Identifiers.COLORS[0])]