feature/konec-hry: vyhodnocení vítěze včetně případu stejného počtu bodů
This commit is contained in:
1 parent
e1450a1d30
commit
4ec5a15e32
1 file changed
+37
@@ -3,6 +3,7 @@ from random import randint
|
|||||||
from os import system, name
|
from os import system, name
|
||||||
import re
|
import re
|
||||||
import csv
|
import csv
|
||||||
|
from collections import Counter
|
||||||
|
|
||||||
score = 0
|
score = 0
|
||||||
hodnoty = {}
|
hodnoty = {}
|
||||||
@@ -127,6 +128,10 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple:
|
|||||||
h_bool = True
|
h_bool = True
|
||||||
next_player()
|
next_player()
|
||||||
data = ("count", 6, "")
|
data = ("count", 6, "")
|
||||||
|
if pointer == first:
|
||||||
|
winner = check_win()
|
||||||
|
if winner:
|
||||||
|
data = ("win", winner, aggr[winner])
|
||||||
return data
|
return data
|
||||||
else:
|
else:
|
||||||
data = ("msg", "ER03", "Zadejte prosím platnou hodnotu:", count, throw)
|
data = ("msg", "ER03", "Zadejte prosím platnou hodnotu:", count, throw)
|
||||||
@@ -179,6 +184,30 @@ def add_players(iter=False):
|
|||||||
first = inp
|
first = inp
|
||||||
add_players(True)
|
add_players(True)
|
||||||
|
|
||||||
|
def check_win() -> str:
|
||||||
|
over_limit = {}
|
||||||
|
for p in aggr:
|
||||||
|
if aggr[p] >= final_score:
|
||||||
|
over_limit[p] = aggr[p]
|
||||||
|
|
||||||
|
i = 1
|
||||||
|
winner = ""
|
||||||
|
|
||||||
|
if over_limit:
|
||||||
|
over_limit_sorted = dict(sorted(over_limit.items(), key=lambda x: x[1], reverse=True))
|
||||||
|
over_limit_sorted_list = []
|
||||||
|
for ols in over_limit_sorted:
|
||||||
|
over_limit_sorted_list.append((ols, over_limit_sorted[ols]))
|
||||||
|
|
||||||
|
|
||||||
|
count = Counter(list(over_limit_sorted.values()))
|
||||||
|
|
||||||
|
for c in count:
|
||||||
|
if i == 1:
|
||||||
|
if count[c] == 1:
|
||||||
|
winner = over_limit_sorted_list[0][0]
|
||||||
|
return winner
|
||||||
|
|
||||||
def game(data: tuple):
|
def game(data: tuple):
|
||||||
if data[0] == "count":
|
if data[0] == "count":
|
||||||
count = data[1]
|
count = data[1]
|
||||||
@@ -219,6 +248,14 @@ def game(data: tuple):
|
|||||||
else:
|
else:
|
||||||
msg = data[1]
|
msg = data[1]
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
|
elif data[0] == "win":
|
||||||
|
winner = data[1]
|
||||||
|
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ě.")
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
clear()
|
clear()
|
||||||
|
|||||||
Reference in new issue
Block a user