feature/konec-hry: vyhodnocení vítěze včetně případu stejného počtu bodů
This commit is contained in:
@@ -3,6 +3,7 @@ from random import randint
|
||||
from os import system, name
|
||||
import re
|
||||
import csv
|
||||
from collections import Counter
|
||||
|
||||
score = 0
|
||||
hodnoty = {}
|
||||
@@ -127,6 +128,10 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple:
|
||||
h_bool = True
|
||||
next_player()
|
||||
data = ("count", 6, "")
|
||||
if pointer == first:
|
||||
winner = check_win()
|
||||
if winner:
|
||||
data = ("win", winner, aggr[winner])
|
||||
return data
|
||||
else:
|
||||
data = ("msg", "ER03", "Zadejte prosím platnou hodnotu:", count, throw)
|
||||
@@ -179,6 +184,30 @@ def add_players(iter=False):
|
||||
first = inp
|
||||
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):
|
||||
if data[0] == "count":
|
||||
count = data[1]
|
||||
@@ -219,6 +248,14 @@ def game(data: tuple):
|
||||
else:
|
||||
msg = data[1]
|
||||
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():
|
||||
clear()
|
||||
|
||||
Reference in New Issue
Block a user