Example #1
0
 def __request_next_move(self):
     """
     Request the next move from the subprocess
     :return: A (flag,card) tuple
     """
     self.generator.send_go_play()
     return Play.from_tuple(self.__get_response_or_default((1, None)))
Example #2
0
 def compute_real_play(self, player, play):
     """
     Compute the "real" play based on an attempted play by player. In the case of
     an invalid move taken by a player, a move will be chosen at random from the set
     of valid moves.
     :param player: The player who is attempting to play
     :param play: The play attempted by the player
     :return: A valid play
     """
     flag = self.compute_played_flag(play.flag, player.direction)
     card = self.compute_played_card(play.card, player.hand)
     return Play(flag=flag, card=card)
Example #3
0
 def compute_turn(self, board, are_flags_open, last_move):
     """
     Provide the current game state to the supprocess and then ask the
     subprocess for its next move. See Player.compute_turn for more information.
     :param board: The current game board state.
     :param are_flags_open: if there are flags open to play
     :param last_move: The last move taken by the opponent.
     :return: The next Play taken by the subprocess.
     """
     self.__send_game_state(board, last_move)
     return self.__request_next_move(
     ) if are_flags_open else Play.from_tuple((1, None))
    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"
        ])
Example #5
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"))
Example #6
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"))
Example #7
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"))
 def compute_turn(self, board, are_flags_open, last_move):
     return Play(card=self.next_card, flag=self.next_flag)