add tournament data model #31
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "feature/add-tournament-data-model"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds the internal data model and core logic for tournaments.
@ -0,0 +5,4 @@class Game:def __init__(self, id_: tuple[int, int], match_id: int, game_number: int, winner_id: Optional[int], score: Optional[tuple[int, int]], game_done: bool) -> None:self._id = id_Wieso "id_"?
id() gibts schon
@ -0,0 +101,4 @@def assign_participant(self, participant_id: int, slot: Literal[1, 2]) -> None:new_participant = MatchParticipant(participant_id, slot)if len(self._participants) < 2 and not any(p.participant_id == participant_id for p in self._participants):Wäre es sinnvoll die Bedingung der If-Anweisung in eine extra Funktion zu extrahieren, um diese verständlicher zu machen?
Für eine Zeile Code die bisher nur einmal genutzt wird würde ich sagen eher nicht.
YAGNI
@ -0,0 +102,4 @@def assign_participant(self, participant_id: int, slot: Literal[1, 2]) -> None:new_participant = MatchParticipant(participant_id, slot)if len(self._participants) < 2 and not any(p.participant_id == participant_id for p in self._participants):if len(self._participants) == 1 and self._participants[-1].slot_number == new_participant.slot_number:Hier das gleiche
Selbe Antwort
@ -0,0 +22,4 @@self._id = id_self._name = nameself._game_title = game_titleself._format = format_Wieso "format_"?
format() gibts schon
@ -0,0 +86,4 @@next_match.assign_participant(winner, 1)except TournamentError:next_match.assign_participant(winner, 2)else: # No next match = final roundIst das "else" nicht überflüssig?
Logisch absolut. Code Style-technisch soll das den Intend signalisieren. Also das hier gezielt auf das zuweißen weiterer matches verzichtet wird.
@ -0,0 +97,4 @@next_match.assign_participant(loser.participant_id, 1)except TournamentError:next_match.assign_participant(loser.participant_id, 2)else: # No next match = final roundGleiche
Gleiche
@ -0,0 +215,4 @@num_rounds_lower = 2 * (num_rounds_upper - 1)lower_rounds: list[list[Match]] = []for round_number in range(1, num_rounds_lower + 1):num_matches = 2 ** (num_rounds_lower - round_number - 1) if round_number != 1 else 2 ** (num_rounds_upper - 1)Hier könnte man auch noch eine Funktion draus erstellen
Also sowas?
Würde es das für dich denn besser machen?
1a0573cba9toff5d715a4e