Ejemplo n.º 1
0
    def get_new_word_for_match(self, match_id):
        excluded_word_ids = TurnsService.get_instance().get_used_word_ids(match_id)
        valid_ids = self.get_all_active_ids()
        word = None

        while word is None and len(valid_ids) > 0:
            valid_ids = list(set(valid_ids) - set(excluded_word_ids))
            word_id = random.choice(valid_ids)
            word = self.get(word_id)
            excluded_word_ids = [word_id]
Ejemplo n.º 2
0
    def get_next_selector_for_match(self, match):
        # Get players in order
        player_ids = [player.get_id() for player in match.get_players()]

        # Get the last selector
        last_selector_id = TurnsService.get_instance().get_last_selector_id_for_match(match.get_id())
        last_selector_index = player_ids.index(last_selector_id)

        if not last_selector_index:
            return None

        # Get the next selector in order
        return self.get(
            player_ids[(last_selector_index + 1) % len(player_ids)]
        )
Ejemplo n.º 3
0
def show(match_id):
    # Get the current turn
    turn, errors = TurnsService.get_instance().get_player_turn(match_id, get_current_user().get_id())

    if not errors:
        turn_player = TurnPlayersService.get_instance().get_for_turn_by_player(
            turn.get_id(), get_current_user().get_id()
        )

        # Get the turn_definition_fillers for this turn
        turn_definition_fillers = TurnDefinitionFillersService.get_instance().get_list_by_turn(turn.get_id())

        # If this player is the selector for this turn
        if turn_player.get_is_selector():
            # TODO Test SQL for turn.get_match().get_game().get_definition_filler_count() vs turn.match.game.get_definition_filler_count()
            if turn.get_match().get_game().get_definition_filler_count() > len(turn_definition_fillers):
                pass

        return render_view('matches/show', 200, match=match.serialized)

    return render_view('422', 422, errors=errors, inputs={'id': match_id})