feat: automatické vyhodnocení a nová dynamika kola
Jedno vyhodnocení kostek = jeden hod; poté nový hod (h), ukončení tahu (k), nebo exit (x). Přepis game() a evaluate() na použití eval_wrapper, odstranění globálů score a h_bool. Zahrnuje správné chování smůly (ztráta bodů z tahu), potvrzení výběru a opravu zobrazení strikes.
This commit is contained in:
1 parent
e9cf875192
commit
b070e22f33
1 file changed
+47
-55
+47
-55
@@ -8,12 +8,10 @@ from typing import Any
|
|||||||
|
|
||||||
from tabulate import tabulate
|
from tabulate import tabulate
|
||||||
|
|
||||||
score: int = 0
|
|
||||||
hodnoty: dict[str, int] = {}
|
hodnoty: dict[str, int] = {}
|
||||||
players: dict[str, list[int]] = {}
|
players: dict[str, list[int]] = {}
|
||||||
pointer: str = ""
|
pointer: str = ""
|
||||||
first: str = ""
|
first: str = ""
|
||||||
h_bool: bool = True
|
|
||||||
aggr: dict[str, int] = {}
|
aggr: dict[str, int] = {}
|
||||||
final_score: int = 10000
|
final_score: int = 10000
|
||||||
|
|
||||||
@@ -154,9 +152,7 @@ def eval_wrapper(count: int, throw: str, inp_hod: str) -> tuple[bool, int, int,
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]:
|
def evaluate(inp_akce: str, count: int, score: int) -> tuple[Any, ...]:
|
||||||
|
|
||||||
global h_bool
|
|
||||||
|
|
||||||
def next_player() -> None:
|
def next_player() -> None:
|
||||||
global pointer
|
global pointer
|
||||||
@@ -169,20 +165,10 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]:
|
|||||||
|
|
||||||
pointer = nxt_key
|
pointer = nxt_key
|
||||||
|
|
||||||
inp = str(inp)
|
if inp_akce == "h":
|
||||||
|
data = ("count", count, score)
|
||||||
if inp == "h":
|
|
||||||
if h_bool:
|
|
||||||
clear()
|
|
||||||
input("Nemůžete házet znovu, dokud nevyhodnotíte některé kostky.")
|
|
||||||
data = ("count", count, throw)
|
|
||||||
else:
|
|
||||||
h_bool = True
|
|
||||||
data = ("count", count, "")
|
|
||||||
|
|
||||||
elif inp == "k":
|
|
||||||
global score
|
|
||||||
|
|
||||||
|
elif inp_akce == "k" or not inp_akce:
|
||||||
if score == 0:
|
if score == 0:
|
||||||
last_two = players[pointer][-2:]
|
last_two = players[pointer][-2:]
|
||||||
if len(last_two) > 1:
|
if len(last_two) > 1:
|
||||||
@@ -194,21 +180,16 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]:
|
|||||||
|
|
||||||
players[pointer].append(score)
|
players[pointer].append(score)
|
||||||
aggr[pointer] = sum(players[pointer])
|
aggr[pointer] = sum(players[pointer])
|
||||||
score = 0
|
|
||||||
h_bool = True
|
|
||||||
next_player()
|
next_player()
|
||||||
data = ("count", 6, "")
|
data = ("count", 6, 0)
|
||||||
if pointer == first:
|
if pointer == first:
|
||||||
winner: str = check_win()
|
winner: str = check_win()
|
||||||
if winner:
|
if winner:
|
||||||
data = ("win", winner, aggr[winner])
|
data = ("win", winner, aggr[winner])
|
||||||
|
|
||||||
elif inp == "exit":
|
elif inp_akce == "x":
|
||||||
data = ("exit",)
|
data = ("exit",)
|
||||||
|
|
||||||
else:
|
|
||||||
data = ("msg", "ER03", "Zadejte prosím platnou hodnotu:", count, throw)
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def check_value(throw: str) -> bool:
|
def check_value(throw: str) -> bool:
|
||||||
@@ -310,54 +291,65 @@ def game(data: tuple) -> None:
|
|||||||
while True:
|
while True:
|
||||||
if data[0] == "count":
|
if data[0] == "count":
|
||||||
count: int = data[1]
|
count: int = data[1]
|
||||||
th: str = data[2]
|
score: int = data[2]
|
||||||
if(th == ""):
|
if not count:
|
||||||
th = throw(count)
|
count = 6
|
||||||
|
th = throw(count)
|
||||||
clear()
|
clear()
|
||||||
# print(f"Vítězné skóre: {final_score}.")
|
|
||||||
|
|
||||||
strikes: str = ""
|
strikes: str = ""
|
||||||
|
|
||||||
if len(players[pointer]) > 0:
|
if len(players[pointer]) > 0:
|
||||||
if players[pointer][-1:][0] == 0:
|
if players[pointer][-1:][0] == 0:
|
||||||
strikes = "x"
|
strikes = "x"
|
||||||
if players[pointer][-2:][0] == 0:
|
if players[pointer][-2:][0] == 0 and len(players[pointer]) > 1:
|
||||||
strikes += "x"
|
strikes += "x"
|
||||||
else:
|
else:
|
||||||
strikes = ""
|
strikes = ""
|
||||||
|
|
||||||
print(f"Na tahu je {pointer} ({aggr[pointer]}{strikes}/{final_score}).")
|
print(f"Na tahu je {pointer} ({aggr[pointer]}{strikes}/{final_score}).")
|
||||||
print(show_throw(th))
|
print(show_throw(th))
|
||||||
if not check_value(th) and data[2] == "" and count != 0:
|
if not check_value(th) and count != 0:
|
||||||
global score
|
|
||||||
score = 0
|
score = 0
|
||||||
input("Oh no... anyway.")
|
input("Oh no... anyway.")
|
||||||
data = evaluate("k", count, th)
|
data = evaluate("k", count, score)
|
||||||
else:
|
else:
|
||||||
if count == 0:
|
if count == 0:
|
||||||
count = 6
|
count = 6
|
||||||
msg: str = ("Jakou akci chcete provést?\n"
|
inp_hod: str = input("Vyberte kostky k vyhodnocení: ")
|
||||||
" - Zadejte kombinaci kostek k ponechání (dojde k jejich vyhodnocení): "
|
while True:
|
||||||
"[pozice kostek] (např. a nebo cd nebo abcdef).\n"
|
data = eval_wrapper(count, th, inp_hod)
|
||||||
" - Hodit znovu: [h].\n"
|
if not data[0]:
|
||||||
f" - Ukončit hod a ponechat si skóre z tohoto hodu ({score}): [k].\n"
|
inp_hod = input(data[3])
|
||||||
" - Ukončit hru: [exit].\n"
|
continue
|
||||||
)
|
score_temp = data[1]
|
||||||
inp: str = input(msg)
|
print("Hodnota hodu:", score_temp)
|
||||||
data = evaluate(inp, count, th)
|
add = ("Hodnota je nulová. Ukončit kolo a přičíst "
|
||||||
|
f"{score} bodů? ") if not score_temp else ""
|
||||||
|
while True:
|
||||||
|
inp = input(f"Potvrdit výběr? {add}[a]no/[n]e: ")
|
||||||
|
if inp in ["a", "y", "n"]:
|
||||||
|
break
|
||||||
|
if inp in ["a", "y"]:
|
||||||
|
count = data[2]
|
||||||
|
score += score_temp
|
||||||
|
break
|
||||||
|
inp_hod = input("Vyberte kostky k vyhodnocení: ")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if not score_temp:
|
||||||
|
inp_akce: str = "k"
|
||||||
|
else:
|
||||||
|
inp_akce = input(
|
||||||
|
f"[h]odit znovu\nu[k]ončit tah a přičíst {score} bodů\ne[x]it?\n"
|
||||||
|
)
|
||||||
|
if inp_akce in ["h", "k", "x"]:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Zadejte prosím platnou hodnotu [h/k/x]. ")
|
||||||
|
|
||||||
|
data = evaluate(inp_akce, count, score)
|
||||||
|
|
||||||
elif data[0] == "msg":
|
|
||||||
if data[1] == "ER01" or data[1] == "ER02" or data[1] == "ER03":
|
|
||||||
msg = data[2]
|
|
||||||
count = data[3]
|
|
||||||
th = data[4]
|
|
||||||
inp = input(msg)
|
|
||||||
data = evaluate(inp, count, th)
|
|
||||||
else:
|
|
||||||
msg = data[1]
|
|
||||||
print(msg)
|
|
||||||
break
|
|
||||||
|
|
||||||
elif data[0] == "win":
|
elif data[0] == "win":
|
||||||
winner: str = data[1]
|
winner: str = data[1]
|
||||||
score = data[2]
|
score = data[2]
|
||||||
@@ -375,7 +367,7 @@ def main() -> None:
|
|||||||
clear()
|
clear()
|
||||||
print("Vítejte ve hře v kostky!")
|
print("Vítejte ve hře v kostky!")
|
||||||
add_players()
|
add_players()
|
||||||
data = ("count", 6, "")
|
data = ("count", 6, 0)
|
||||||
game(data)
|
game(data)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in new issue
Block a user