Exemple #1
0
def play(seed, previous_actions):
    """Play a game"""
    game = Game.new(4, seed)
    previous_actions = np.array([], dtype=np.uint8) if len(previous_actions) < 1 else \
        np.array([int(i) for i in previous_actions.split(",")], dtype=np.uint8)
    previous_actions = PlayerActionTools.from_np_many(previous_actions)[::-1]
    actions = []
    while game.active():
        if not game.is_current_player_playing():
            game = game.skip_eliminated_player()
            continue

        display(game, actions)

        try:
            if len(previous_actions) > 0:
                action = previous_actions.pop()
            else:
                print("  What card to play?")
                action = get_action()
            actions.append(action)
            game, _ = game.move(action)
        except ValueError:
            print("Invalid move - Exit with Ctrl-C")

    display(game, actions)
    print("Game Over : Player {} Wins!".format(game.winner()))
Exemple #2
0
 def test_from_np_many(self):
     """Action from a numpy array"""
     actions = [
         PlayerAction(1, 3, 5, 1),
         PlayerAction(4, 0, 5, 1),
         PlayerAction(8, 0, 0, 1),
         PlayerAction(5, 0, 0, 1)
     ]
     arr = np.array([1, 3, 5, 1, 4, 0, 5, 1, 8, 0, 0, 1, 5, 0, 0, 1],
                    dtype=np.uint8)
     self.assertListEqual(PlayerActionTools.from_np_many(arr), actions)
Exemple #3
0
    def replay(seed, action_sequence=None):
        """Generate a game from a recorded set of actions"""
        action_sequence = action_sequence if action_sequence is not None else []
        action_sequence = np.array(action_sequence, dtype=np.uint8)
        action_sequence = PlayerActionTools.from_np_many(action_sequence)[::-1]
        game = Game.new(4, seed)

        while len(action_sequence) > 0:
            if not game.is_current_player_playing():
                game = game.skip_eliminated_player()
            else:
                action = action_sequence.pop()
                game = game._move(action)

        return game