예제 #1
0
    def simulate(
        self,
        teams: List[Team],
        gambits: List[Gambit],
        logs: List[TurnLog],
        max_turn: int = 1000,
    ) -> int:
        logger.debug("## Battle No.%d" % self.id)

        # バトルのシミュレーション
        for team in teams:
            team.reset()

        for gambit in gambits:
            gambit.reset(teams)

        # 上限までターンを進める
        for turn_id in range(1, max_turn):
            logger.debug("### Turn No.%d" % turn_id)

            turn = Turn(turn_id)
            result, win_team = turn.proceed(teams, gambits, logs)
            if win_team:
                return win_team.id

        return -1
예제 #2
0
    def test_constructor(self):
        pe = Player(name='Explanee')
        pg = Player(name='Guessee')
        t = Turn(explaining=pe, guessing=pg)

        assert t.guessing == pg
        assert t.explaining == pe
        assert type(t.missed_words) == list
        assert len(t.missed_words) == 0
        assert t.result() == 0
        assert t.word is None
예제 #3
0
 def choose_starting_villages(self):
   playerTurn = []
   steps_this_turn = 0
   for idx, agent in enumerate(self.agents):
     playerTurn.append(agent.choose_starting_village(self.players[idx], steps_this_turn))
     steps_this_turn += 2
   for idx, agent in reversed(list(enumerate(self.agents))):
     playerTurn.append(agent.choose_starting_village(self.players[idx], steps_this_turn))
     steps_this_turn += 2
   self.turn_data.append(Turn(0, self.players[self.current_turn], [item for sublist in playerTurn for item in sublist], []))
   if self.use_db:
     db.next_turn(self.game_id)
예제 #4
0
    def start_game(self):
        fmt = logging.Formatter('[ Start game ] %(message)s ', '%p')
        logger.handlers[0].setFormatter(fmt)

        self.game_engine.start_game(game_name=self.game_config.name)

        # Shuffle the decks
        if self.game_config.shuffle_decks:
            self.player_1.deck.shuffle_deck()
            self.player_2.deck.shuffle_deck()

        # Each player draws the first hand
        self.player_1.draw_card(self.game_config.draw_initial)
        self.player_2.draw_card(self.game_config.draw_initial)

        while not self.game_engine.game_ended:
            turn = Turn(game_engine=self.game_engine,
                        game_config=self.game_config)
            turn.start()

            self.game_engine.change_player_focus()
            self.game_engine.turns_count += 1
예제 #5
0
 def turn(self):
   self.num_turns += 1
   if self.num_turns != 1:
     self.current_turn = (self.current_turn + 1) % len(self.players)
   self.dice_roll = self.roll_dice()
   self.distribute_cards()
   # print('Turns:', self.num_turns, 'Points:', [a.player.get_points() for a in self.agents], 'Actions:', len(self.agents[self.current_turn].player.get_actions()), 'Cards:', self.agents[self.current_turn].player.cards_to_string())
   playerTurn = self.agents[self.current_turn].turn(self.players[self.current_turn], self.num_turns)
   self.turn_data.append(Turn(self.num_turns, self.players[self.current_turn], playerTurn, self.dice_roll))
   if self.use_db:
     db.set_dice_trow(game_id=self.game_id, dice_one=self.dice_roll[0], dice_two=self.dice_roll[1])
     db.next_turn(self.game_id)
   if self.check_winner():
     self.finished = True
     if self.use_db:
       db.game_finished(self.game_id)
예제 #6
0
 def test_guessed(self):
     t = Turn(explaining=Player(name='Explanee'), guessing=Player(name='Guessee'))
     w1 = 'someword'
     w2 = 'anotherword'
     w3 = 'thirdword'
     t.word = w1
     assert t.result() == 0
     t.guessed(False)
     assert t.result() == 0
     assert t.missed_words == [w1]
     t.word = w2
     t.guessed(True)
     assert t.result() == 1
     assert t.missed_words == [w1]
     t.word = w2
     t.guessed(True)
     assert t.result() == 2
     assert t.missed_words == [w1]
     t.word = w3
     t.guessed(False)
     assert t.result() == 2
     assert t.missed_words == [w1, w3]
예제 #7
0
 def test_set_words(self):
     t = Turn(explaining=Player(name='Explanee'), guessing=Player(name='Guessee'))
     w = 'someword'
     t.word = w
     assert t.word == w
예제 #8
0
def all_turns(role: int) -> list:
    all_turns_info = list()  # type: list
    subturn_counter = 0
    question = Question(None)
    data = read_file(f'{role}/infos.txt')
    turns = data.split('**************************\n')
    turns.pop(0)
    for big_turn in turns:
        turn_meta = big_turn.split('\n', 2)
        turn_data = Turn(*parse_events(turn_meta[0]))
        suspects = turn_meta[1].split()
        sub_turns = big_turn.split('****\n')
        sub_turns.pop(0)
        for sub_turn in sub_turns:
            turn_info = dict()  # type: typing.Dict[str, typing.Any]
            turn_info['tour'] = turn_data.tour
            turn_info['score'] = turn_data.score
            turn_info['ombre'] = turn_data.ombre
            turn_info['bloqué'] = turn_data.bloque
            turn_info['suspects'] = suspects.copy()
            turn_info['cri'] = 0  # Using int not bool for later learning
            turn_info['pouvoir action'] = None
            if subturn_counter > 3:
                all_turns_info[
                    subturn_counter - 4]['score fin'] = turn_data.score
            for line in sub_turn.split('\n'):
                if line.startswith("  Tour de l'"):
                    turn_info['joueur'] = 0
                if line.startswith("  Tour de le"):
                    turn_info['joueur'] = 1
                if line.startswith('QUESTION : '):
                    question.parse_question(line[11:])
                if line.startswith('REPONSE INTERPRETEE : '):
                    if question.type == Type.POSITION:
                        turn_info['déplacement'] = int(line[22:])
                    elif question.type == Type.DRAW:
                        turn_info['tuiles'] = question.args
                        turn_info['perso joué'] = line[22:]
                    elif question.type == Type.POWER:
                        turn_info['pouvoir utilisé'] = 0 if (
                            line[22:] == "False") else 1
                    else:
                        turn_info['pouvoir action'] = line[22:]
                if line.startswith('NOUVEAU PLACEMENT : '):
                    nouveau_placement = line[20:]
                    for i, suspect in enumerate(suspects):
                        if suspect.startswith(nouveau_placement[
                                :nouveau_placement.find('-')]):
                            suspects[i] = nouveau_placement
                if line.startswith('le fantome frappe'):
                    turn_info['cri'] = 1
                if line.startswith('Score final :'):
                    turn_info['score fin'] = int(line[14:])
                    for i in range(subturn_counter - 3, subturn_counter):
                        all_turns_info[i]['score fin'] = turn_info['score fin']
            all_turns_info.append(turn_info)
            if turn_info['cri']:
                for i in range(subturn_counter - 3, subturn_counter):
                    all_turns_info[i]['cri'] = 1
            subturn_counter += 1
            # fin parsing tour joueur
        # fin parsing tour global
    return all_turns_info