/
Mihaham
/
Table-Time
Обзор
Документация
Войти
/
Mihaham
/
Table-Time
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
services/api/app/plugins/shared/scoring.py
59 строк
2 KB
MihahamYT
feat: full game catalog — 46 plugins, docs nav, web UI kit
14 июн 2026, 12:43
14 июн 2026, 12:43
2cd5f50
Код
Авторство
О чём код?
"""Scorecard utilities (Yatzy and similar).""" from app.plugins.shared.dice import count_face YATZY_CATEGORIES = [ "ones", "twos", "threes", "fours", "fives", "sixes", "three_of_kind", "four_of_kind", "full_house", "small_straight", "large_straight", "yatzy", "chance", ] UPPER_CATEGORIES = ["ones", "twos", "threes", "fours", "fives", "sixes"] def empty_yatzy_scorecard() -> dict[str, int | None]: return {c: None for c in YATZY_CATEGORIES} def score_yatzy_category(dice: list[int], category: str) -> int: """Score dice for a Yatzy category.""" if category == "ones": return count_face(dice, 1) * 1 if category == "twos": return count_face(dice, 2) * 2 if category == "threes": return count_face(dice, 3) * 3 if category == "fours": return count_face(dice, 4) * 4 if category == "fives": return count_face(dice, 5) * 5 if category == "sixes": return count_face(dice, 6) * 6 if category == "chance": return sum(dice) counts = [count_face(dice, f) for f in range(1, 7)] if category == "three_of_kind": return sum(dice) if any(c >= 3 for c in counts) else 0 if category == "four_of_kind": return sum(dice) if any(c >= 4 for c in counts) else 0 if category == "full_house": sorted_counts = sorted(counts, reverse=True) return 25 if sorted_counts[0] >= 3 and sorted_counts[1] >= 2 else 0 unique = set(dice) if category == "small_straight": straights = [{1, 2, 3, 4}, {2, 3, 4, 5}, {3, 4, 5, 6}] return 30 if any(s.issubset(unique) for s in straights) else 0 if category == "large_straight": return 40 if unique in ({1, 2, 3, 4, 5}, {2, 3, 4, 5, 6}) else 0 if category == "yatzy": return 50 if len(unique) == 1 else 0 return 0 def total_yatzy_score(card: dict[str, int | None]) -> int: """Total scorecard with upper-section bonus.""" total = sum(v for v in card.values() if v is not None) upper = sum(card.get(k) or 0 for k in UPPER_CATEGORIES) if upper >= 63: total += 35 return total