From 16d940253d419bae151179d25b638ed020fe8746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Thu, 18 Jun 2026 20:51:07 +0200 Subject: [PATCH 01/13] =?UTF-8?q?feature:=20v=C3=BDb=C4=9Br=20kostek:=20od?= =?UTF-8?q?e=C4=8D=C3=ADt=C3=A1n=C3=AD=20vybran=C3=BDch=20kostek=20z=20nov?= =?UTF-8?q?=C3=A9ho=20hodu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index b24ba74..106525d 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,6 @@ from random import randint from os import system, name +import re def throw(count): count = int(count) @@ -24,17 +25,25 @@ def clear(): else: _ = system('clear') -def game(): - new_throw = throw(6) +def evaluate(inp, count): + inp = str(inp) + if re.search("^\d+$", inp): + count = len(inp) + return count + +def game(count): + new_throw = throw(count) clear() print(show_throw(new_throw)) - input("Prosím, stiskněte enter pro další hod:") - game() + inp = input("Vyberte, kterými kostkami chcete hodit znovu (např. 135):") + count = evaluate(inp, count) + game(count) def main(): print("Vítejte ve hře v kostky!") input("Prosím, stiskněte enter pro první hod:") - game() + count = 6 + game(count) if __name__ == "__main__": main() From c1e94faf9896efbc68b9e42390c865f8761043e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Fri, 19 Jun 2026 17:05:19 +0200 Subject: [PATCH 02/13] =?UTF-8?q?feature:=20funkce=20game=20nyn=C3=AD=20do?= =?UTF-8?q?st=C3=A1v=C3=A1=20jako=20argument=20tuple:=20na=20prvn=C3=ADm?= =?UTF-8?q?=20m=C3=ADst=C4=9B=20je=20v=C5=BEdy=20typ=20p=C5=99ed=C3=A1van?= =?UTF-8?q?=C3=BDch=20dat=20(zat=C3=ADm=20"count"/"msg")=20funkce=20evalua?= =?UTF-8?q?te=20kontroluje=20maxim=C3=A1ln=C3=AD=20mo=C5=BEn=C3=BD=20po?= =?UTF-8?q?=C4=8Det=20hozen=C3=BDch=20kostek?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index 106525d..cc6ff48 100644 --- a/main.py +++ b/main.py @@ -28,22 +28,36 @@ def clear(): def evaluate(inp, count): inp = str(inp) if re.search("^\d+$", inp): - count = len(inp) - return count + if len(inp) > count: + data = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count) + return data + else: + count = len(inp) + data = ("count", count) + return data -def game(count): - new_throw = throw(count) - clear() - print(show_throw(new_throw)) - inp = input("Vyberte, kterými kostkami chcete hodit znovu (např. 135):") - count = evaluate(inp, count) - game(count) +def game(data: tuple): + if data[0] == "count": + count = data[1] + new_throw = throw(count) + clear() + print(show_throw(new_throw)) + inp = input("Vyberte, kterými kostkami chcete hodit znovu (např. 135):") + data = evaluate(inp, count) + game(data) + elif data[0] == "msg": + if data[1] == "ER01": + msg = data[2] + count = data[3] + inp = input(msg) + data = evaluate(inp, count) + game(data) def main(): print("Vítejte ve hře v kostky!") input("Prosím, stiskněte enter pro první hod:") - count = 6 - game(count) + data = ("count", 6) + game(data) if __name__ == "__main__": main() From a668a4d7b3053b5b570cca1a3ae5d0e957bc7dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Fri, 19 Jun 2026 19:52:24 +0200 Subject: [PATCH 03/13] =?UTF-8?q?feature/hod:=20implementov=C3=A1n=20error?= =?UTF-8?q?=20pro=20=C4=8D=C3=ADslo=20kostky=20mimo=20platn=C3=BD=20rozsah?= =?UTF-8?q?=20(zb=C3=BDvaj=C3=ADc=C3=AD=20po=C4=8Det=20kostek=20+=20n)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index cc6ff48..7ff30e6 100644 --- a/main.py +++ b/main.py @@ -31,7 +31,15 @@ def evaluate(inp, count): if len(inp) > count: data = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count) return data - else: + else: + for x in inp: + if int(x) > count: + if count == 1: + range = "1" + else: + range = f"1–{count}" + data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({range}):", count) + return data count = len(inp) data = ("count", count) return data @@ -46,7 +54,7 @@ def game(data: tuple): data = evaluate(inp, count) game(data) elif data[0] == "msg": - if data[1] == "ER01": + if data[1] == "ER01" or data[1] == "ER02": msg = data[2] count = data[3] inp = input(msg) From 6952c7c9648ba2e68c54bba57f9f566ebc05b4e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Fri, 19 Jun 2026 20:20:19 +0200 Subject: [PATCH 04/13] =?UTF-8?q?feature/hod:=20z=C3=A1klady=20logiky=20pr?= =?UTF-8?q?o=20vyhodnocov=C3=A1n=C3=AD=20hodnoty=20kostek:=20na=C4=8Dten?= =?UTF-8?q?=C3=AD=20hodnot=20odlo=C5=BEen=C3=BDch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 7ff30e6..b413e39 100644 --- a/main.py +++ b/main.py @@ -25,33 +25,43 @@ def clear(): else: _ = system('clear') -def evaluate(inp, count): +def evaluate(inp, count, throw): inp = str(inp) if re.search("^\d+$", inp): if len(inp) > count: data = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count) return data - else: + else: for x in inp: - if int(x) > count: + x = int(x) + if x > count: if count == 1: - range = "1" + ran = "1" else: - range = f"1–{count}" - data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({range}):", count) + ran = f"1–{count}" + data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({ran}):", count) return data + old_throw = [] + for y in range(count): + if str(y) in inp: + old_throw.append(throw[y]) + count = len(inp) - data = ("count", count) + data = ("count", count, old_throw) return data def game(data: tuple): if data[0] == "count": count = data[1] + old_throw = data[2] new_throw = throw(count) clear() print(show_throw(new_throw)) - inp = input("Vyberte, kterými kostkami chcete hodit znovu (např. 135):") - data = evaluate(inp, count) + msg = "Vyberte, kterými kostkami chcete hodit znovu (např. 135):" + if old_throw != "": + msg += f"\nHodnoty odložených kostek: {old_throw}" + inp = input(msg) + data = evaluate(inp, count, new_throw) game(data) elif data[0] == "msg": if data[1] == "ER01" or data[1] == "ER02": @@ -60,11 +70,14 @@ def game(data: tuple): inp = input(msg) data = evaluate(inp, count) game(data) + else: + msg = data[1] + print(msg) def main(): print("Vítejte ve hře v kostky!") input("Prosím, stiskněte enter pro první hod:") - data = ("count", 6) + data = ("count", 6, "") game(data) if __name__ == "__main__": From d796c6012b98d5e78b941b1396ed7a983bfc2e35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Fri, 19 Jun 2026 20:40:31 +0200 Subject: [PATCH 05/13] feature/hod: csv s hodnotami --- hodnoty.csv | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 hodnoty.csv diff --git a/hodnoty.csv b/hodnoty.csv new file mode 100644 index 0000000..bcccc97 --- /dev/null +++ b/hodnoty.csv @@ -0,0 +1,30 @@ +111111,8000 +666666,4800 +11111,4000 +555555,4000 +444444,3200 +66666,2400 +333333,2400 +1111,2000 +55555,2000 +44444,1600 +222222,1600 +123456,1500 +6666,1200 +33333,1200 +111,1000 +5555,1000 +23456,1000 +4444,800 +22222,800 +12345,750 +666,600 +3333,600 +555,500 +444,400 +2222,400 +333,300 +11,200 +222,200 +1,100 +5,50 \ No newline at end of file From ac6d8d918221fea216250f2b6fe00e2824cc20a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sun, 21 Jun 2026 15:02:45 +0200 Subject: [PATCH 06/13] feature/hod: import csv s hodnotami --- main.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.py b/main.py index b413e39..709f2b3 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,18 @@ from random import randint from os import system, name import re +import csv + +hodnoty = {} + +with open("hodnoty.csv", "r") as csv_file: + csv_reader = csv.reader(csv_file) + + for row in csv_reader: + key = str(row[0]) + value = str(row[1]) + + hodnoty[key] = value def throw(count): count = int(count) From d854190480411d6b35720e81fa59dbb68ad71346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sun, 21 Jun 2026 15:52:03 +0200 Subject: [PATCH 07/13] =?UTF-8?q?feature/hod:=20=C3=BAvodn=C3=AD=20kontrol?= =?UTF-8?q?a=20kombinace=20v=20hodu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 709f2b3..b4f6b60 100644 --- a/main.py +++ b/main.py @@ -62,6 +62,17 @@ def evaluate(inp, count, throw): data = ("count", count, old_throw) return data +def check_value(throw): + throw.sort() + throw_str = "".join(throw) + hodnota = False + for h in hodnoty: + if h in throw_str: + hodnota = True + break + + return hodnota + def game(data: tuple): if data[0] == "count": count = data[1] @@ -69,12 +80,15 @@ def game(data: tuple): new_throw = throw(count) clear() print(show_throw(new_throw)) - msg = "Vyberte, kterými kostkami chcete hodit znovu (např. 135):" - if old_throw != "": - msg += f"\nHodnoty odložených kostek: {old_throw}" - inp = input(msg) - data = evaluate(inp, count, new_throw) - game(data) + if check_value(new_throw): + msg = "Vyberte, kterými kostkami chcete hodit znovu (např. 135):" + if old_throw != "": + msg += f"\nHodnoty odložených kostek: {old_throw}" + inp = input(msg) + data = evaluate(inp, count, new_throw) + game(data) + else: + print("Smůla, třeba příště.") elif data[0] == "msg": if data[1] == "ER01" or data[1] == "ER02": msg = data[2] From e4fc41a65632db97593b4d53e4c38b523b63a998 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sun, 21 Jun 2026 16:08:04 +0200 Subject: [PATCH 08/13] feature/hod: oprava check_value --- main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index b4f6b60..a1a577a 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ from os import system, name import re import csv +score = 0 hodnoty = {} with open("hodnoty.csv", "r") as csv_file: @@ -55,7 +56,7 @@ def evaluate(inp, count, throw): return data old_throw = [] for y in range(count): - if str(y) in inp: + if str(y+1) in inp: old_throw.append(throw[y]) count = len(inp) @@ -63,8 +64,9 @@ def evaluate(inp, count, throw): return data def check_value(throw): - throw.sort() - throw_str = "".join(throw) + throw_s = throw.copy() + throw_s.sort() + throw_str = "".join(throw_s) hodnota = False for h in hodnoty: if h in throw_str: From b7ec4eb17f522b2c8989a383045028f4729a44fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sun, 21 Jun 2026 16:31:23 +0200 Subject: [PATCH 09/13] =?UTF-8?q?feature/hod:=20nahrazen=C3=AD=20throw=20l?= =?UTF-8?q?istu=20stringem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index a1a577a..d6e531a 100644 --- a/main.py +++ b/main.py @@ -15,20 +15,25 @@ with open("hodnoty.csv", "r") as csv_file: hodnoty[key] = value -def throw(count): +def throw(count: int) -> str: count = int(count) new_throw = [] for dice in range(count): new_throw.append(str(randint(1, 6))) + new_throw = "".join(new_throw) return new_throw def show_throw(throw): - pretty_list = ", ".join(throw) + throw_temp = [] + for x in throw: + throw_temp.append(x) + + pretty_list = ", ".join(throw_temp) pretty_list += "\n" - for i in range(1, len(throw) + 1): + for i in range(1, len(throw_temp) + 1): pretty_list += "^ " pretty_list += "\n" - for i in range(1, len(throw) + 1): + for i in range(1, len(throw_temp) + 1): pretty_list += f"{i} " return pretty_list @@ -64,8 +69,7 @@ def evaluate(inp, count, throw): return data def check_value(throw): - throw_s = throw.copy() - throw_s.sort() + throw_s = sorted(throw) throw_str = "".join(throw_s) hodnota = False for h in hodnoty: From 1997f96232470b26e4d5729a519c2288989b75ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sun, 21 Jun 2026 16:37:52 +0200 Subject: [PATCH 10/13] =?UTF-8?q?refactor:=20definice=20typ=C5=AF=20u=20fu?= =?UTF-8?q?nkc=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index d6e531a..327e079 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +from typing import Any from random import randint from os import system, name import re @@ -23,7 +24,7 @@ def throw(count: int) -> str: new_throw = "".join(new_throw) return new_throw -def show_throw(throw): +def show_throw(throw: str) -> str: throw_temp = [] for x in throw: throw_temp.append(x) @@ -43,7 +44,7 @@ def clear(): else: _ = system('clear') -def evaluate(inp, count, throw): +def evaluate(inp: Any, count: int, throw: str) -> tuple: inp = str(inp) if re.search("^\d+$", inp): if len(inp) > count: @@ -68,7 +69,7 @@ def evaluate(inp, count, throw): data = ("count", count, old_throw) return data -def check_value(throw): +def check_value(throw: str) -> bool: throw_s = sorted(throw) throw_str = "".join(throw_s) hodnota = False From f91f7c874ab912879352bad89ed7c14988921ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sun, 21 Jun 2026 17:09:25 +0200 Subject: [PATCH 11/13] =?UTF-8?q?feature/hod:=20vyhodnocov=C3=A1n=C3=AD=20?= =?UTF-8?q?hodu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 51 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index 327e079..c6c5ae4 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,7 @@ with open("hodnoty.csv", "r") as csv_file: for row in csv_reader: key = str(row[0]) - value = str(row[1]) + value = int(row[1]) hodnoty[key] = value @@ -45,6 +45,14 @@ def clear(): _ = system('clear') def evaluate(inp: Any, count: int, throw: str) -> tuple: + def eval_score(pick: str) -> bool: + if(pick in hodnoty): + global score + score += hodnoty[pick] + return True + else: + return False + inp = str(inp) if re.search("^\d+$", inp): if len(inp) > count: @@ -61,12 +69,24 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple: data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({ran}):", count) return data old_throw = [] + pick = [] for y in range(count): - if str(y+1) in inp: + if str(y+1) not in inp: old_throw.append(throw[y]) + if str(y+1) in inp: + pick.append(throw[y]) - count = len(inp) - data = ("count", count, old_throw) + old_throw = "".join(old_throw) + pick.sort() + pick = "".join(pick) + + new_count = len(old_throw) + + if eval_score(pick) == False: + new_count = count + old_throw = throw + + data = ("count", new_count, old_throw) return data def check_value(throw: str) -> bool: @@ -83,16 +103,21 @@ def check_value(throw: str) -> bool: def game(data: tuple): if data[0] == "count": count = data[1] - old_throw = data[2] - new_throw = throw(count) - clear() - print(show_throw(new_throw)) - if check_value(new_throw): - msg = "Vyberte, kterými kostkami chcete hodit znovu (např. 135):" - if old_throw != "": - msg += f"\nHodnoty odložených kostek: {old_throw}" + th = data[2] + if(th == ""): + th = throw(count) + # clear() + print(show_throw(th)) + if check_value(th) or (check_value(th) == False and th != ""): + msg = ("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" + ) + # if old_throw != "": + # msg += f"\nHodnoty odložených kostek: {old_throw}" inp = input(msg) - data = evaluate(inp, count, new_throw) + data = evaluate(inp, count, th) game(data) else: print("Smůla, třeba příště.") From eb5603bca30af1956f340cc448682f42d0cc3f4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Sun, 21 Jun 2026 17:13:23 +0200 Subject: [PATCH 12/13] =?UTF-8?q?fix:=20oprava=20p=C5=99ed=C3=A1v=C3=A1n?= =?UTF-8?q?=C3=AD=20dat=20do=20funkce=20evaluate=20z=20chybov=C3=BDch=20hl?= =?UTF-8?q?=C3=A1=C5=A1ek?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index c6c5ae4..027e4b9 100644 --- a/main.py +++ b/main.py @@ -56,7 +56,7 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple: inp = str(inp) if re.search("^\d+$", inp): if len(inp) > count: - data = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count) + data = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu:", count, throw) return data else: for x in inp: @@ -66,7 +66,7 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple: ran = "1" else: ran = f"1–{count}" - data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({ran}):", count) + data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({ran}):", count, throw) return data old_throw = [] pick = [] @@ -125,8 +125,9 @@ def game(data: tuple): if data[1] == "ER01" or data[1] == "ER02": msg = data[2] count = data[3] + th = data[4] inp = input(msg) - data = evaluate(inp, count) + data = evaluate(inp, count, th) game(data) else: msg = data[1] From 1849c1c05b2e900e446acb2e8542100d22b5a5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sp=C3=A1=C4=8Dil?= Date: Mon, 22 Jun 2026 18:46:13 +0200 Subject: [PATCH 13/13] hotfix: check_value(th) == False na not check_value(th) --- main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 027e4b9..2e1c01d 100644 --- a/main.py +++ b/main.py @@ -106,9 +106,9 @@ def game(data: tuple): th = data[2] if(th == ""): th = throw(count) - # clear() + clear() print(show_throw(th)) - if check_value(th) or (check_value(th) == False and th != ""): + if check_value(th) or (not check_value(th) and th != ""): msg = ("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"