release: v0.2.0 #28
+35
-27
@@ -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 csv
|
||||||
|
import re
|
||||||
from collections import Counter
|
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
|
from tabulate import tabulate
|
||||||
|
|
||||||
score: int = 0
|
score: int = 0
|
||||||
@@ -16,20 +17,19 @@ h_bool: bool = True
|
|||||||
aggr: dict[str, int] = {}
|
aggr: dict[str, int] = {}
|
||||||
final_score: int = 10000
|
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_text = files(__package__).joinpath("hodnoty.csv").read_text(encoding="utf-8")
|
csv_reader = csv.reader(csv_text.splitlines())
|
||||||
csv_reader = csv.reader(csv_text.splitlines())
|
|
||||||
|
|
||||||
for row in csv_reader:
|
for row in csv_reader:
|
||||||
key = str(row[0])
|
key = str(row[0])
|
||||||
value = int(row[1])
|
value = int(row[1])
|
||||||
|
|
||||||
hodnoty[key] = value
|
hodnoty[key] = value
|
||||||
|
|
||||||
def throw(count: int) -> str:
|
def throw(count: int) -> str:
|
||||||
count = int(count)
|
count = int(count)
|
||||||
new_throw: list[str] = []
|
new_throw: list[str] = []
|
||||||
for dice in range(count):
|
for _dice in range(count):
|
||||||
new_throw.append(str(randint(1, 6)))
|
new_throw.append(str(randint(1, 6)))
|
||||||
new_throw_str: str = "".join(new_throw)
|
new_throw_str: str = "".join(new_throw)
|
||||||
return new_throw_str
|
return new_throw_str
|
||||||
@@ -41,7 +41,7 @@ def show_throw(throw: str) -> str:
|
|||||||
|
|
||||||
pretty_list: str = ", ".join(throw_temp)
|
pretty_list: str = ", ".join(throw_temp)
|
||||||
pretty_list += "\n"
|
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 += "^ "
|
||||||
pretty_list += "\n"
|
pretty_list += "\n"
|
||||||
for i in range(1, len(throw_temp) + 1):
|
for i in range(1, len(throw_temp) + 1):
|
||||||
@@ -49,10 +49,7 @@ def show_throw(throw: str) -> str:
|
|||||||
return pretty_list
|
return pretty_list
|
||||||
|
|
||||||
def clear() -> None:
|
def clear() -> None:
|
||||||
if name == 'nt':
|
_ = system('cls') if name == 'nt' else system('clear')
|
||||||
_ = system('cls')
|
|
||||||
else:
|
|
||||||
_ = system('clear')
|
|
||||||
|
|
||||||
def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]:
|
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)
|
inp = str(inp)
|
||||||
if re.search(r"^\d+$", inp):
|
if re.search(r"^\d+$", inp):
|
||||||
if len(inp) > count:
|
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:
|
else:
|
||||||
for x in inp:
|
for x in inp:
|
||||||
x = int(x)
|
x = int(x)
|
||||||
if x > count:
|
if x > count:
|
||||||
if count == 1:
|
ran = "1" if count == 1 else f"1–{count}"
|
||||||
ran = "1"
|
data = (
|
||||||
else:
|
"msg",
|
||||||
ran = f"1–{count}"
|
"ER02",
|
||||||
data = ("msg", "ER02", f"Zvolte prosím kostky v platném rozsahu ({ran}): ", count, throw)
|
f"Zvolte prosím kostky v platném rozsahu ({ran}): ",
|
||||||
|
count,
|
||||||
|
throw
|
||||||
|
)
|
||||||
return data
|
return data
|
||||||
old_throw: list[str] = []
|
old_throw: list[str] = []
|
||||||
pick: list[str] = []
|
pick: list[str] = []
|
||||||
@@ -205,8 +211,9 @@ 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]]:
|
def to_sorted_tuple(d: dict[str, int], s: bool = True) -> (tuple[list[tuple[int, str, int]],
|
||||||
L: list[tuple[str, int]] = []
|
dict[str, int]]):
|
||||||
|
L: list[tuple[int, str, int]] = []
|
||||||
|
|
||||||
if s:
|
if s:
|
||||||
d = dict(sorted(d.items(), key=lambda x: x[1], reverse=True))
|
d = dict(sorted(d.items(), key=lambda x: x[1], reverse=True))
|
||||||
@@ -278,7 +285,8 @@ def game(data: tuple) -> None:
|
|||||||
if count == 0:
|
if count == 0:
|
||||||
count = 6
|
count = 6
|
||||||
msg: str = ("Jakou akci chcete provést?\n"
|
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"
|
" - Hodit znovu: [h].\n"
|
||||||
f" - Ukončit hod a ponechat si skóre z tohoto hodu ({score}): [k].\n"
|
f" - Ukončit hod a ponechat si skóre z tohoto hodu ({score}): [k].\n"
|
||||||
" - Ukončit hru: [exit].\n"
|
" - Ukončit hru: [exit].\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user