From 9967682373c697ce9ee0e1edc43ecfe6c512c64c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sat, 27 Jun 2026 09:24:56 +0200 Subject: [PATCH 1/5] =?UTF-8?q?refactoring:=20ve=20funkci=20evaluate=20slo?= =?UTF-8?q?u=C4=8Deny=20p=C5=99ebyte=C4=8Dn=C3=A9=20returny?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index ce7fa5b..c63029c 100644 --- a/main.py +++ b/main.py @@ -78,7 +78,6 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple: if re.search(r"^\d+$", inp): if len(inp) > count: data = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count, throw) - return data else: for x in inp: x = int(x) @@ -110,7 +109,7 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple: h_bool = False data = ("count", new_count, old_throw) - return data + elif inp == "h": if h_bool: clear() @@ -119,7 +118,7 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple: else: h_bool = True data = ("count", count, "") - return data + elif inp == "k": global score @@ -142,13 +141,14 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple: winner = check_win() if winner: data = ("win", winner, aggr[winner]) - return data + elif inp == "exit": data = ("exit",) - return data + else: data = ("msg", "ER03", "Zadejte prosím platnou hodnotu:", count, throw) - return data + + return data def check_value(throw: str) -> bool: throw_s = sorted(throw) From a58487e9a6d40288b527d7935fd5c6d558552cb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sat, 27 Jun 2026 12:23:28 +0200 Subject: [PATCH 2/5] refactoring: type annotation --- main.py | 90 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/main.py b/main.py index c63029c..db7f25e 100644 --- a/main.py +++ b/main.py @@ -5,14 +5,14 @@ import re import csv from collections import Counter -score = 0 -hodnoty = {} -players = {} -pointer = "" -first = "" -h_bool = True -aggr = {} -final_score = 10000 +score: int = 0 +hodnoty: dict[str, int] = {} +players: dict[str, list[int]] = {} +pointer: str = "" +first: str = "" +h_bool: bool = True +aggr: dict[str, int] = {} +final_score: int = 10000 with open("hodnoty.csv", "r") as csv_file: csv_reader = csv.reader(csv_file) @@ -25,18 +25,18 @@ with open("hodnoty.csv", "r") as csv_file: def throw(count: int) -> str: count = int(count) - new_throw = [] + new_throw: list[str] = [] for dice in range(count): new_throw.append(str(randint(1, 6))) - new_throw = "".join(new_throw) - return new_throw + new_throw_str: str = "".join(new_throw) + return new_throw_str def show_throw(throw: str) -> str: - throw_temp = [] + throw_temp: list[str] = [] for x in throw: throw_temp.append(x) - pretty_list = ", ".join(throw_temp) + pretty_list: str = ", ".join(throw_temp) pretty_list += "\n" for i in range(1, len(throw_temp) + 1): pretty_list += "^ " @@ -45,13 +45,13 @@ def show_throw(throw: str) -> str: pretty_list += f"{i} " return pretty_list -def clear(): +def clear() -> None: if name == 'nt': _ = system('cls') else: _ = system('clear') -def evaluate(inp: Any, count: int, throw: str) -> tuple: +def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, Any, Any, Any, Any]: global h_bool @@ -77,7 +77,7 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple: inp = str(inp) if re.search(r"^\d+$", inp): if len(inp) > count: - data = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count, throw) + data: tuple[Any, Any, Any, Any, Any] = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count, throw) else: for x in inp: x = int(x) @@ -88,27 +88,27 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple: ran = f"1–{count}" data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({ran}):", count, throw) return data - old_throw = [] - pick = [] + old_throw: list[str] = [] + pick: list[str] = [] for y in range(count): if str(y+1) not in inp: old_throw.append(throw[y]) if str(y+1) in inp: pick.append(throw[y]) - old_throw = "".join(old_throw) + old_throw_str: str = "".join(old_throw) pick.sort() - pick = "".join(pick) + pick_str: str = "".join(pick) - new_count = len(old_throw) + new_count: int = len(old_throw_str) - if not eval_score(pick): + if not eval_score(pick_str): new_count = count - old_throw = throw + old_throw_str = throw else: h_bool = False - data = ("count", new_count, old_throw) + data = ("count", new_count, old_throw_str) elif inp == "h": if h_bool: @@ -138,7 +138,7 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple: next_player() data = ("count", 6, "") if pointer == first: - winner = check_win() + winner: str = check_win() if winner: data = ("win", winner, aggr[winner]) @@ -151,9 +151,9 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple: return data def check_value(throw: str) -> bool: - throw_s = sorted(throw) - throw_str = "".join(throw_s) - hodnota = False + throw_s: list[str] = sorted(throw) + throw_str: str = "".join(throw_s) + hodnota: bool = False for h in hodnoty: if h in throw_str: hodnota = True @@ -161,11 +161,11 @@ def check_value(throw: str) -> bool: return hodnota -def add_players(): +def add_players() -> None: global pointer, first, final_score while True: - inp = input("Zadejte jméno prvního hráče: ") + inp: str = input("Zadejte jméno prvního hráče: ") if inp == "": print("Jméno nemůže být prázdné.") else: @@ -193,8 +193,8 @@ def add_players(): inp = input("Zadejte finální skóre (nechte prázdné pro výchozích 10 000): ") if inp != "": try: - inp = int(inp) - final_score = inp + inp_int: int = int(inp) + final_score = inp_int except ValueError: print("Zadejte prosím platnou číselnou hodnotu.") else: @@ -203,21 +203,21 @@ def add_players(): break def check_win() -> str: - over_limit = {} + over_limit: dict[str, int] = {} for p in aggr: if aggr[p] >= final_score: over_limit[p] = aggr[p] - winner = "" + winner: str = "" if over_limit: - over_limit_sorted = dict(sorted(over_limit.items(), key=lambda x: x[1], reverse=True)) - over_limit_sorted_list = [] + 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])) - count = Counter(list(over_limit_sorted.values())) + count: Counter = Counter(list(over_limit_sorted.values())) for c in count: if count[c] == 1: @@ -226,17 +226,17 @@ def check_win() -> str: return winner -def game(data: tuple): +def game(data: tuple) -> None: while True: if data[0] == "count": - count = data[1] - th = data[2] + count: int = data[1] + th: str = data[2] if(th == ""): th = throw(count) clear() print(f"Vítězné skóre: {final_score}.") - strikes = "" + strikes: str = "" if len(players[pointer]) > 0: if players[pointer][-1:][0] == 0: @@ -256,13 +256,13 @@ def game(data: tuple): else: if count == 0: count = 6 - msg = ("Jakou akci chcete provést?\n" + msg: str = ("Jakou akci chcete provést?\n" " - Zadejte kombinaci kostek k ponechání (dojde k jejich vyhodnocení): [pozice kostek] (např. 1 nebo 34 nebo 123456).\n" " - Hodit znovu: [h].\n" f" - Ukončit hod a ponechat si skóre z tohoto hodu ({score}): [k].\n" " - Ukončit hru: [exit].\n" ) - inp = input(msg) + inp: str = input(msg) data = evaluate(inp, count, th) elif data[0] == "msg": @@ -279,7 +279,7 @@ def game(data: tuple): break elif data[0] == "win": - winner = data[1] + winner: str = data[1] score = data[2] clear() @@ -292,7 +292,7 @@ def game(data: tuple): print("Hra byla předčasně ukončena. Snad se zase brzy uvidíme.") break -def main(): +def main() -> None: clear() print("Vítejte ve hře v kostky!") add_players() From 5aa5beff69e535997100ee0b4a962ae1526a2b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sat, 27 Jun 2026 12:30:47 +0200 Subject: [PATCH 3/5] refactoring: oprava tuple[Any, ...] anotace --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index db7f25e..828daf1 100644 --- a/main.py +++ b/main.py @@ -51,7 +51,7 @@ def clear() -> None: else: _ = system('clear') -def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, Any, Any, Any, Any]: +def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]: global h_bool @@ -77,7 +77,7 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, Any, Any, Any, Any] inp = str(inp) if re.search(r"^\d+$", inp): if len(inp) > count: - data: tuple[Any, Any, Any, Any, Any] = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count, throw) + data: tuple[Any, ...] = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count, throw) else: for x in inp: x = int(x) From 2f8d5b12c2a98c64415fe9947d5bef9b2e8541dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sat, 27 Jun 2026 12:34:04 +0200 Subject: [PATCH 4/5] =?UTF-8?q?refactoring:=20=C4=8Di=C5=A1t=C4=9Bn=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.py b/main.py index 828daf1..4a32b1d 100644 --- a/main.py +++ b/main.py @@ -270,7 +270,6 @@ def game(data: tuple) -> None: msg = data[2] count = data[3] th = data[4] - # clear() inp = input(msg) data = evaluate(inp, count, th) else: @@ -296,7 +295,6 @@ def main() -> None: clear() print("Vítejte ve hře v kostky!") add_players() - input("Prosím, stiskněte enter pro první hod:") data = ("count", 6, "") game(data) From 26ad8508b5b3035860e33f3d829a888562922975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sat, 27 Jun 2026 12:55:51 +0200 Subject: [PATCH 5/5] =?UTF-8?q?refactoring:=20drobn=C3=A9=20=C3=BApravy=20?= =?UTF-8?q?UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 4a32b1d..a21b9ee 100644 --- a/main.py +++ b/main.py @@ -77,7 +77,7 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]: inp = str(inp) if re.search(r"^\d+$", inp): if len(inp) > count: - data: tuple[Any, ...] = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count, throw) + data: tuple[Any, ...] = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu: ", count, throw) else: for x in inp: x = int(x) @@ -86,7 +86,7 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]: ran = "1" else: ran = f"1–{count}" - data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({ran}):", count, throw) + data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({ran}): ", count, throw) return data old_throw: list[str] = [] pick: list[str] = [] @@ -234,7 +234,7 @@ def game(data: tuple) -> None: if(th == ""): th = throw(count) clear() - print(f"Vítězné skóre: {final_score}.") + # print(f"Vítězné skóre: {final_score}.") strikes: str = "" @@ -246,7 +246,7 @@ def game(data: tuple) -> None: else: strikes = "" - print(f"Na tahu je {pointer} ({aggr[pointer]}{strikes}).") + print(f"Na tahu je {pointer} ({aggr[pointer]}{strikes}/{final_score}).") print(show_throw(th)) if not check_value(th) and data[2] == "" and count != 0: global score