Esempio n. 1
0
 def __init__(self, name, source, rp):
     PlayingMode.__init__(self, name)
     self.repeat_pattern = rp
     self.name = "ShowMode " + str(name)
     self.priority = 1
     self.queue = Queue.Queue()
     self.content_provider = RandomFileProvider(False, source)
Esempio n. 2
0
 def __init__(self, data):
     source = data.get('source', '')
     PlayingMode.__init__(self, "NewsMode")
     self.repeat_pattern = HourlyRepeat()
     self.name = "NewsMode"
     self.content_provider = NewsFileProvider(source)
     self.priority = 1
     self.time_counter = 0
Esempio n. 3
0
 def __init__(self, data):
     source = data.get('source', '')
     PlayingMode.__init__(self, "NewsMode")
     self.repeat_pattern = HourlyRepeat()
     self.name = "NewsMode"
     self.content_provider = NewsFileProvider(source)
     self.priority = 1
     self.time_counter = 0
Esempio n. 4
0
 def next(self):
     PlayingMode.next(self)
     if DefaultMode.last_speech >= Properties.DEFAULT_SPEECH_COUNT:
         next_song = self.speech_provider.next()
         DefaultMode.last_speech = 0
     else:
         next_song = self.content_provider.next()
         DefaultMode.last_speech += 1
     return next_song
Esempio n. 5
0
 def next(self):
     PlayingMode.next(self)
     if DefaultMode.last_speech >= Properties.DEFAULT_SPEECH_COUNT:
         next_song = self.speech_provider.next()
         DefaultMode.last_speech = 0
     else:
         next_song = self.content_provider.next()
         DefaultMode.last_speech += 1
     return next_song
Esempio n. 6
0
 def __init__(self, data):
     PlayingMode.__init__(self, data.get('name'))
     self.repeat_pattern = DefaultRepeat()
     self.name = "DefaultMode " + data.get('name')
     self.content_provider = RandomFileProvider(False, data.get('musicSource'))
     self.speech_provider = RandomFileProvider(True, data.get('speechSource'))
     self.priority = 1
     self.time_counter = 0
     self._playing_time = 0
     self.start_time = 0
     self.is_playing = False
Esempio n. 7
0
 def __init__(self, data):
     PlayingMode.__init__(self, data.get('name'))
     self.repeat_pattern = DefaultRepeat()
     self.name = "DefaultMode " + data.get('name')
     self.content_provider = RandomFileProvider(False,
                                                data.get('musicSource'))
     self.speech_provider = RandomFileProvider(True,
                                               data.get('speechSource'))
     self.priority = 1
     self.time_counter = 0
     self._playing_time = 0
     self.start_time = 0
     self.is_playing = False
def compare(decks):
    table = TranspositionTable()
    with open('ismcts_vs_ismcts__200.txt', 'w') as out:

        for iterations in (50, 100, 200, 500, 1000, 2000, 4000):
            winner_counter = defaultdict(int)
            game_number = 1

            for plays in range(game_number):
                state = LoveLetterState(2, decks)
                state.start_new_round()
                mode = PlayingMode(state, "compare_bots", show_logs=False)

                while not state.game_over:
                    try:
                        assert len(state.playerHands[state.playerToMove]) == 2
                    except:
                        import pdb
                        pdb.set_trace()
                    move, victim, guess = mode.get_move(iterations)
                    # table.write(state, move, victim, guess)
                    state.do_move(
                        move,
                        verbose=False,
                        global_game=True,
                        victim=victim,
                        guess=guess,
                        real_player=state.playerToMove == mode.real_player,
                        vanilla=False)

                # determine a winner
                for player in state.user_ctl.users:
                    if state.tricksTaken[player] == state.tricks_taken_limit:
                        # print("Player " + str(player) + " wins the game!")
                        winner_counter[player.algorithm] += 1

            assert (sum(winner_counter.values()) == game_number)

            out.write("{} iterations\n".format(iterations))

            for algorithm, won_count in winner_counter.items():
                out.write("{} - {}\n".format(algorithm, won_count))
            out.write("\n")

            print("Iterations - {}".format(iterations, ))
            print(winner_counter)

    print("Done")
Esempio n. 9
0
 def next(self):
     PlayingMode.next(self)
     next_song = self.content_provider.next()
     return next_song
Esempio n. 10
0
    def run(self):
        decks = []

        with open('decks.txt') as f:
            for line in f:
                splitted = line.split()
                decks.append([card_dict[card] for card in splitted])

        state = LoveLetterState(2, decks)
        state.start_new_round()

        mode = PlayingMode(state, "real_player")
        while not state.game_over:
            if state.playerToMove == state.real_players[0]:
                self.show_turn.emit(True)
                self.update_field.emit()
                victim, guess = None, None

                self.update_info.emit("You are {}".format(
                    state.real_players[0]))

                self.show_card.emit()

                self.card_label_signal.emit(
                    0, state.playerHands[state.playerToMove][0].name)
                self.card_label_signal.emit(
                    1, state.playerHands[state.playerToMove][1].name)

                self.history_signal.emit("Your cards are {} and {}".format(
                    state.playerHands[state.playerToMove][0],
                    state.playerHands[state.playerToMove][1]))

                while not self.form.is_selected:
                    QApplication.processEvents()

                if state.playerHands[
                        state.playerToMove][0].name == self.form.card_name:
                    move = state.playerHands[state.playerToMove][0]
                else:
                    move = state.playerHands[state.playerToMove][1]

                if move.name == "Guard":
                    for buttom in self.form.select_victim.findChildren(
                            QRadioButton):
                        if buttom.isChecked():
                            guess = card_dict[str(buttom.text())]
                            break

                self.history_signal.emit("You played with {}".format(move))
                self.update_field.emit()

            else:
                self.show_turn.emit(False)
                self.hide_card.emit()
                move, victim, guess = mode.get_move(0)
                self.card_label_signal.emit(
                    0, state.playerHands[state.playerToMove][0].name)
                self.history_signal.emit(
                    "Opponent played with {}".format(move))

            messages = state.do_move(
                move,
                verbose=True,
                global_game=False,
                victim=victim,
                guess=guess,
                real_player=state.playerToMove == mode.real_player,
                vanilla=False)

            for message in messages:
                self.history_signal.emit(message)

            self.deck_signal.emit("{} cards in deck".format(len(state.deck)))

            if state.round_over:
                self.history_signal.emit("#" * 40)
                self.history_signal.emit("# " * 15 + "ROUND " +
                                         str(state.round) + " " + "#" * 15)
                self.history_signal.emit("#" * 40)
                winner = [
                    user for user in state.user_ctl.users if user.won_round
                ][0]
                if winner == state.real_players[0]:
                    self.update_count.emit("You: {}".format(
                        state.tricksTaken[winner]))
                else:
                    self.update_count.emit("Opponent: {}".format(
                        state.tricksTaken[winner]))
                state.start_new_round(first_player=winner)
Esempio n. 11
0
 def next(self):
     PlayingMode.next(self)
     next_song = self.content_provider.next()
     return next_song