fix: opravy (načítání csv + ruff)

This commit is contained in:
David Spáčil
2026-06-27 18:38:40 +02:00
parent a9ef19ee52
commit 69b30552cb
+35 -27
View File
@@ -1,10 +1,11 @@
from typing import Any
from random import randint
from os import system, name
import re
from importlib.resources import files
import csv
import re
from collections import Counter
from importlib.resources import files
from os import name, system
from random import randint
from typing import Any
from tabulate import tabulate
score: int = 0
@@ -16,20 +17,19 @@ h_bool: bool = True
aggr: dict[str, int] = {}
final_score: int = 10000
with open("hodnoty.csv", "r") as csv_file:
csv_text = files(__package__).joinpath("hodnoty.csv").read_text(encoding="utf-8")
csv_reader = csv.reader(csv_text.splitlines())
csv_text = files(__package__).joinpath("hodnoty.csv").read_text(encoding="utf-8")
csv_reader = csv.reader(csv_text.splitlines())
for row in csv_reader:
key = str(row[0])
value = int(row[1])
for row in csv_reader:
key = str(row[0])
value = int(row[1])
hodnoty[key] = value
hodnoty[key] = value
def throw(count: int) -> str:
count = int(count)
new_throw: list[str] = []
for dice in range(count):
for _dice in range(count):
new_throw.append(str(randint(1, 6)))
new_throw_str: str = "".join(new_throw)
return new_throw_str
@@ -41,7 +41,7 @@ def show_throw(throw: str) -> str:
pretty_list: str = ", ".join(throw_temp)
pretty_list += "\n"
for i in range(1, len(throw_temp) + 1):
for _i in range(1, len(throw_temp) + 1):
pretty_list += "^ "
pretty_list += "\n"
for i in range(1, len(throw_temp) + 1):
@@ -49,10 +49,7 @@ def show_throw(throw: str) -> str:
return pretty_list
def clear() -> None:
if name == 'nt':
_ = system('cls')
else:
_ = system('clear')
_ = system('cls') if name == 'nt' else system('clear')
def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]:
@@ -80,16 +77,25 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]:
inp = str(inp)
if re.search(r"^\d+$", inp):
if len(inp) > count:
data: tuple[Any, ...] = ("msg", "ER01", "Tolika kostkami nemůžete hodit. Zkuste to znovu: ", count, throw)
data: tuple[Any, ...] = (
"msg",
"ER01",
"Tolika kostkami nemůžete hodit. Zkuste to znovu: ",
count,
throw
)
else:
for x in inp:
x = int(x)
if x > count:
if count == 1:
ran = "1"
else:
ran = f"1{count}"
data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({ran}): ", count, throw)
ran = "1" if count == 1 else f"1{count}"
data = (
"msg",
"ER02",
f"Zvolte prosím kostky v platném rozsahu ({ran}): ",
count,
throw
)
return data
old_throw: list[str] = []
pick: list[str] = []
@@ -205,8 +211,9 @@ 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]] = []
def to_sorted_tuple(d: dict[str, int], s: bool = True) -> (tuple[list[tuple[int, str, int]],
dict[str, int]]):
L: list[tuple[int, str, int]] = []
if s:
d = dict(sorted(d.items(), key=lambda x: x[1], reverse=True))
@@ -278,7 +285,8 @@ def game(data: tuple) -> None:
if count == 0:
count = 6
msg: str = ("Jakou akci chcete provést?\n"
" - Zadejte kombinaci kostek k ponechání (dojde k jejich vyhodnocení): [pozice kostek] (např. 1 nebo 34 nebo 123456).\n"
" - Zadejte kombinaci kostek k ponechání (dojde k jejich vyhodnocení): "
"[pozice kostek] (např. 1 nebo 34 nebo 123456).\n"
" - Hodit znovu: [h].\n"
f" - Ukončit hod a ponechat si skóre z tohoto hodu ({score}): [k].\n"
" - Ukončit hru: [exit].\n"