From c3a2e94cabccc65e15ffb53b2a944d9e8c433ee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sat, 27 Jun 2026 16:58:10 +0200 Subject: [PATCH 1/4] =?UTF-8?q?feature/vysledky:=20funkce=20pro=20=C5=99az?= =?UTF-8?q?en=C3=AD=20v=C3=BDsledku=20na=20z=C3=A1klad=C4=9B=20k=C3=B3du?= =?UTF-8?q?=20v=20check=5Fwin();=20k=C3=B3d=20v=20check=5Fwin()=20nahrazen?= =?UTF-8?q?=20funkc=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index a21b9ee..c3ed018 100644 --- a/main.py +++ b/main.py @@ -202,6 +202,17 @@ def add_players() -> None: else: break +def to_sorted_tuple(d: dict[str, int], s: bool = True) -> tuple[list[tuple[str, int]], dict[str, int]]: + L: list[tuple[str, int]] = [] + + if s: + d = dict(sorted(d.items(), key=lambda x: x[1], reverse=True)) + + for k in d: + L.append((k, d[k])) + + return L, d + def check_win() -> str: over_limit: dict[str, int] = {} for p in aggr: @@ -211,17 +222,13 @@ def check_win() -> str: winner: str = "" if over_limit: - over_limit_sorted: dict[str, int] = dict(sorted(over_limit.items(), key=lambda x: x[1], reverse=True)) - over_limit_sorted_list: list[tuple[str, int]] = [] - for ols in over_limit_sorted: - over_limit_sorted_list.append((ols, over_limit_sorted[ols])) + L, d = to_sorted_tuple(over_limit) - - count: Counter = Counter(list(over_limit_sorted.values())) + count: Counter = Counter(list(d.values())) for c in count: if count[c] == 1: - winner = over_limit_sorted_list[0][0] + winner = L[0][0] break return winner -- 2.47.3 From bdd66379f74d3c21fb19d793940e88a8e050ef8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sat, 27 Jun 2026 17:11:10 +0200 Subject: [PATCH 2/4] =?UTF-8?q?feature/vysledky:=20list=20z=20to=5Fsorted?= =?UTF-8?q?=5Ftuple()=20se=20vrac=C3=AD=20s=20=C4=8D=C3=ADslov=C3=A1n?= =?UTF-8?q?=C3=ADm=20po=C5=99ad=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index c3ed018..fc87b63 100644 --- a/main.py +++ b/main.py @@ -208,8 +208,8 @@ def to_sorted_tuple(d: dict[str, int], s: bool = True) -> tuple[list[tuple[str, if s: d = dict(sorted(d.items(), key=lambda x: x[1], reverse=True)) - for k in d: - L.append((k, d[k])) + for i, (k, v) in enumerate(d.items()): + L.append((i+1, k, v)) return L, d @@ -228,7 +228,7 @@ def check_win() -> str: for c in count: if count[c] == 1: - winner = L[0][0] + winner = L[0][1] break return winner -- 2.47.3 From 7b0c9cadbbfccea316b46d8859311d1470e3ab40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sat, 27 Jun 2026 17:15:47 +0200 Subject: [PATCH 3/4] =?UTF-8?q?feature/vysledky:=20definice=20funkce=20win?= =?UTF-8?q?()=20a=20jej=C3=AD=20vol=C3=A1n=C3=AD=20z=20bloku=20win=20ve=20?= =?UTF-8?q?funkci=20game()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index fc87b63..ff64593 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ from os import system, name import re import csv from collections import Counter +from tabulate import tabulate score: int = 0 hodnoty: dict[str, int] = {} @@ -233,6 +234,17 @@ def check_win() -> str: return winner +def win(winner: str, score: int) -> None: + results, d = to_sorted_tuple(aggr) + + headers = ["Pořadí", "Hráč", "Skóre"] + table = tabulate(results, headers=headers, tablefmt="fancy_grid") + + print(f"Vítězem se stává {winner} s {score} body!") + print("Díky za hru a zase příště.\n") + + print(table) + def game(data: tuple) -> None: while True: if data[0] == "count": @@ -289,8 +301,7 @@ def game(data: tuple) -> None: score = data[2] clear() - print(f"Vítězem se stává {winner} s {score} body!") - print("Díky za hru a zase příště.") + win(winner, score) break elif data[0] == "exit": -- 2.47.3 From c8a31ac6beb2575cc33e291ceaa66bc3e55c9338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sat, 27 Jun 2026 17:29:41 +0200 Subject: [PATCH 4/4] fix: oprava anotace --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index ff64593..d103c9d 100644 --- a/main.py +++ b/main.py @@ -203,7 +203,7 @@ def add_players() -> None: else: break -def to_sorted_tuple(d: dict[str, int], s: bool = True) -> tuple[list[tuple[str, int]], dict[str, int]]: +def to_sorted_tuple(d: dict[str, int], s: bool = True) -> tuple[list[tuple[int, str, int]], dict[str, int]]: L: list[tuple[str, int]] = [] if s: -- 2.47.3