6 Commits
Author SHA1 Message Date
david-spacil caa743fcc9 update .gitignore 2026-07-11 22:46:25 +02:00
david-spacil 26f53761a7 enhancement: řazení hodnot
po načtení hodnot kombinací z csv dojde pro jistotu ještě k seřazení podle hodnoty
2026-07-11 16:30:33 +02:00
david-spacil d420664fde feat: upravena funkce eval_score()
Došlo k úpravě funkce eval_score() tak, aby přijímala input s více kombinacemi najednou. V případě vstupu, který kromě platných kombinací obsahuje i hodnoty navíc, vrátí False a uživatel má možnost vybrat kostky k vyhodnocení znovu
2026-07-11 16:16:39 +02:00
david-spacilandClaude Sonnet 5 5dee428752 docs: přidat CLAUDE.md s přehledem architektury a příkazů
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-06-30 22:25:43 +02:00
david-spacil e2d689a618 Merge pull request 'hotfix: odstranění hodnoty pro 2×1 – redundantní' (#29) from hotfix/oprava-hodnoty into main
Reviewed-on: david/kostky#29
2026-06-28 07:49:53 +02:00
David Spáčil c53a58c8e4 hotfix: odstranění hodnoty pro 2×1 – redundantní 2026-06-28 07:48:08 +02:00
5 changed files with 73 additions and 9 deletions

No files matched your search

+2 -1
View File
@@ -2,4 +2,5 @@ __pycache__/
*.pyc *.pyc
dist/ dist/
build/ build/
*.egg-info/ *.egg-info/
test.py
+44
View File
@@ -0,0 +1,44 @@
# CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project
`kostky` is a Czech-language terminal CLI game — a Farkle/"tisícovky" dice game variant for multiple players. Single runtime dependency: `tabulate` (for the final results table).
## Commands
```bash
pip install -e ".[dev]" # editable install with mypy + ruff
kostky # run the game (after install)
python -m kostky # run without installing (requires tabulate)
mypy # type-check (strict mode, see pyproject.toml)
ruff check . # lint
```
There are no tests in this repository.
## Architecture
The entire game lives in `kostky/kostky.py` as a single module with module-level mutable state (no classes):
- `hodnoty: dict[str, int]` — scoring table, loaded at import time from `kostky/hodnoty.csv` via `importlib.resources`. Keys are sorted-digit strings representing dice combos (e.g. `"111"` = three ones), values are point totals.
- `players: dict[str, list[int]]` — per-player history of per-turn scores (insertion order == turn order).
- `aggr: dict[str, int]` — per-player running total, used for win checks and the results table.
- `pointer` / `first` — current player's name / the player who started the round (used to detect when a full round has completed in `next_player`/`check_win`).
- `score` — points accumulated *within the current turn*, reset on bust or on banking (`k`).
- `h_bool` — guards re-rolling: you can't roll again until you've banked at least one scoring combination in the current roll sequence.
Control flow is a manual state machine driven by tuples, not exceptions or return codes:
- `evaluate(inp, count, throw)` parses a single line of user input against the current dice state and returns a `data` tuple whose first element is a tag: `"count"` (continue turn with N remaining dice and a throw string), `"msg"` (show an error/message, possibly re-prompting), `"win"`, or `"exit"`.
- `game(data)` is the main loop: it pattern-matches on `data[0]`, prints state, prompts for input, and calls `evaluate` again to get the next `data` tuple. This loop is how every turn — and the whole game — progresses.
- Dice picks are entered as letters (`a`-`f` mapped to position 1-6 via `ord(x)-96`), not digit values; `evaluate` converts letters to positions internally before checking the picked dice values against `hodnoty`.
- Bust detection (`check_value`) checks whether *any* key in `hodnoty` is a substring of the sorted current throw — not a full combinatorial scoring check, so this is the single source of truth for "is this throw dead."
- Win condition (`check_win`) only fires once `pointer` cycles back to `first`, i.e. checked once per full round rather than once per turn, and only declares a winner if exactly one player is alone at/above `final_score`.
`kostky/__main__.py` and the `kostky` console-script entry point (in `pyproject.toml`) both call `kostky.kostky.main()`.
## Scoring data
`kostky/hodnoty.csv` (digit-string-of-dice-values → points) is the single source of truth for scoring and is also documented in tables in `README.md`. If you change one, update the other.
+1 -1
View File
@@ -82,7 +82,7 @@ nezáleží.
| **2** | – | – | 200 | 400 | 800 | 1600 | | **2** | – | – | 200 | 400 | 800 | 1600 |
| **3** | – | – | 300 | 600 | 1200 | 2400 | | **3** | – | – | 300 | 600 | 1200 | 2400 |
| **4** | – | – | 400 | 800 | 1600 | 3200 | | **4** | – | – | 400 | 800 | 1600 | 3200 |
| **5** | 50 | – | 500 | 1000 | 2000 | 4000 | | **5** | 50 | 100 | 500 | 1000 | 2000 | 4000 |
| **6** | – | – | 600 | 1200 | 2400 | 4800 | | **6** | – | – | 600 | 1200 | 2400 | 4800 |
(„–“ = daná kombinace samostatně neboduje.) („–“ = daná kombinace samostatně neboduje.)
-1
View File
@@ -24,7 +24,6 @@
444,400 444,400
2222,400 2222,400
333,300 333,300
11,200
222,200 222,200
1,100 1,100
5,50 5,50
1 111111 8000
24 444 400
25 2222 400
26 333 300
11 200
27 222 200
28 1 100
29 5 50
+26 -6
View File
@@ -26,6 +26,8 @@ for row in csv_reader:
hodnoty[key] = value hodnoty[key] = value
hodnoty = dict(sorted(hodnoty.items(), key=lambda x: x[1], reverse=True))
def throw(count: int) -> str: def throw(count: int) -> str:
count = int(count) count = int(count)
new_throw: list[str] = [] new_throw: list[str] = []
@@ -56,12 +58,30 @@ def evaluate(inp: Any, count: int, throw: str) -> tuple[Any, ...]:
global h_bool global h_bool
def eval_score(pick: str) -> bool: def eval_score(pick: str) -> bool:
if(pick in hodnoty): global score
global score score_temp = 0
score += hodnoty[pick] pick_ok = False
return True pick_counter = Counter(pick)
else: while pick_counter:
return False bool_temp = False
for k in hodnoty:
k_counter = Counter(k)
if k_counter <= pick_counter:
pick_counter = pick_counter - k_counter
score_temp += hodnoty[k]
pick_ok = True
bool_temp = True
if not bool_temp:
break
print(pick_counter)
if pick_counter:
pick_ok = False
else:
score += score_temp
return pick_ok
def next_player() -> None: def next_player() -> None:
global pointer global pointer