feature: výsledková tabulka na konci hry #24
@@ -4,6 +4,7 @@ from os import system, name
|
|||||||
import re
|
import re
|
||||||
import csv
|
import csv
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
from tabulate import tabulate
|
||||||
|
|
||||||
score: int = 0
|
score: int = 0
|
||||||
hodnoty: dict[str, int] = {}
|
hodnoty: dict[str, int] = {}
|
||||||
@@ -202,6 +203,17 @@ def add_players() -> None:
|
|||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
def to_sorted_tuple(d: dict[str, int], s: bool = True) -> tuple[list[tuple[int, str, int]], dict[str, int]]:
|
||||||
|
L: list[tuple[str, int]] = []
|
||||||
|
|
||||||
|
if s:
|
||||||
|
d = dict(sorted(d.items(), key=lambda x: x[1], reverse=True))
|
||||||
|
|
||||||
|
for i, (k, v) in enumerate(d.items()):
|
||||||
|
L.append((i+1, k, v))
|
||||||
|
|
||||||
|
return L, d
|
||||||
|
|
||||||
def check_win() -> str:
|
def check_win() -> str:
|
||||||
over_limit: dict[str, int] = {}
|
over_limit: dict[str, int] = {}
|
||||||
for p in aggr:
|
for p in aggr:
|
||||||
@@ -211,21 +223,28 @@ def check_win() -> str:
|
|||||||
winner: str = ""
|
winner: str = ""
|
||||||
|
|
||||||
if over_limit:
|
if over_limit:
|
||||||
over_limit_sorted: dict[str, int] = dict(sorted(over_limit.items(), key=lambda x: x[1], reverse=True))
|
L, d = to_sorted_tuple(over_limit)
|
||||||
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 = Counter(list(d.values()))
|
||||||
count: Counter = Counter(list(over_limit_sorted.values()))
|
|
||||||
|
|
||||||
for c in count:
|
for c in count:
|
||||||
if count[c] == 1:
|
if count[c] == 1:
|
||||||
winner = over_limit_sorted_list[0][0]
|
winner = L[0][1]
|
||||||
break
|
break
|
||||||
|
|
||||||
return winner
|
return winner
|
||||||
|
|
||||||
|
def win(winner: str, score: int) -> None:
|
||||||
|
results, d = to_sorted_tuple(aggr)
|
||||||
|
|
||||||
|
headers = ["Pořadí", "Hráč", "Skóre"]
|
||||||
|
table = tabulate(results, headers=headers, tablefmt="fancy_grid")
|
||||||
|
|
||||||
|
print(f"Vítězem se stává {winner} s {score} body!")
|
||||||
|
print("Díky za hru a zase příště.\n")
|
||||||
|
|
||||||
|
print(table)
|
||||||
|
|
||||||
def game(data: tuple) -> None:
|
def game(data: tuple) -> None:
|
||||||
while True:
|
while True:
|
||||||
if data[0] == "count":
|
if data[0] == "count":
|
||||||
@@ -282,8 +301,7 @@ def game(data: tuple) -> None:
|
|||||||
score = data[2]
|
score = data[2]
|
||||||
|
|
||||||
clear()
|
clear()
|
||||||
print(f"Vítězem se stává {winner} s {score} body!")
|
win(winner, score)
|
||||||
print("Díky za hru a zase příště.")
|
|
||||||
break
|
break
|
||||||
|
|
||||||
elif data[0] == "exit":
|
elif data[0] == "exit":
|
||||||
|
|||||||
Reference in New Issue
Block a user