Merge pull request 'feature: výsledková tabulka na konci hry' (#24) from feature/vysledky into version/v0.2.0
Reviewed-on: david/kostky#24
This commit was merged in pull request #24.
This commit is contained in:
@@ -4,6 +4,7 @@ from os import system, name
|
||||
import re
|
||||
import csv
|
||||
from collections import Counter
|
||||
from tabulate import tabulate
|
||||
|
||||
score: int = 0
|
||||
hodnoty: dict[str, int] = {}
|
||||
@@ -202,6 +203,17 @@ def add_players() -> None:
|
||||
else:
|
||||
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:
|
||||
over_limit: dict[str, int] = {}
|
||||
for p in aggr:
|
||||
@@ -211,21 +223,28 @@ def check_win() -> str:
|
||||
winner: str = ""
|
||||
|
||||
if over_limit:
|
||||
over_limit_sorted: dict[str, int] = dict(sorted(over_limit.items(), key=lambda x: x[1], reverse=True))
|
||||
over_limit_sorted_list: list[tuple[str, int]] = []
|
||||
for ols in over_limit_sorted:
|
||||
over_limit_sorted_list.append((ols, over_limit_sorted[ols]))
|
||||
L, d = to_sorted_tuple(over_limit)
|
||||
|
||||
|
||||
count: Counter = Counter(list(over_limit_sorted.values()))
|
||||
count: Counter = Counter(list(d.values()))
|
||||
|
||||
for c in count:
|
||||
if count[c] == 1:
|
||||
winner = over_limit_sorted_list[0][0]
|
||||
winner = L[0][1]
|
||||
break
|
||||
|
||||
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:
|
||||
while True:
|
||||
if data[0] == "count":
|
||||
@@ -282,8 +301,7 @@ def game(data: tuple) -> None:
|
||||
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ě.")
|
||||
win(winner, score)
|
||||
break
|
||||
|
||||
elif data[0] == "exit":
|
||||
|
||||
Reference in New Issue
Block a user