2026-11-02 18:32:36 +00:00
|
|
|
import random
|
|
|
|
|
from models.constants import CATEGORIES
|
|
|
|
|
from models.ai_profiles import AIEngine
|
2026-11-02 21:43:42 +00:00
|
|
|
from models.player import Player
|
2026-11-02 18:32:36 +00:00
|
|
|
|
|
|
|
|
class GameModel:
|
|
|
|
|
def __init__(self, bot_configs):
|
|
|
|
|
# bot_configs ist eine Liste mit Leveln, z.B. [1, 2]
|
|
|
|
|
self.players = [Player("You")]
|
|
|
|
|
for i, level in enumerate(bot_configs):
|
|
|
|
|
self.players.append(Player(f"Bot {i+1} (Lv{level})", is_bot=True, ai_level=level))
|
|
|
|
|
|
|
|
|
|
self.turn = 1
|
|
|
|
|
self.reset_turn()
|
|
|
|
|
|
|
|
|
|
def reset_turn(self):
|
|
|
|
|
self.dice = [random.randint(1, 6) for _ in range(5)]
|
|
|
|
|
self.held = [False] * 5
|
|
|
|
|
self.rolls_left = 2
|
|
|
|
|
|
|
|
|
|
def roll_unheld(self):
|
|
|
|
|
if self.rolls_left > 0:
|
|
|
|
|
for i in range(5):
|
|
|
|
|
if not self.held[i]:
|
|
|
|
|
self.dice[i] = random.randint(1, 6)
|
|
|
|
|
self.rolls_left -= 1
|
|
|
|
|
|
|
|
|
|
def calculate_score(self, cat_key, dice, is_joker=False):
|
|
|
|
|
counts = {x: dice.count(x) for x in range(1, 7)}
|
|
|
|
|
d_sum = sum(dice)
|
|
|
|
|
s_dice = sorted(list(set(dice)))
|
|
|
|
|
|
|
|
|
|
if cat_key == "1": return dice.count(1) * 1
|
|
|
|
|
if cat_key == "2": return dice.count(2) * 2
|
|
|
|
|
if cat_key == "3": return dice.count(3) * 3
|
|
|
|
|
if cat_key == "4": return dice.count(4) * 4
|
|
|
|
|
if cat_key == "5": return dice.count(5) * 5
|
|
|
|
|
if cat_key == "6": return dice.count(6) * 6
|
|
|
|
|
if cat_key == "3K": return d_sum if (any(c >= 3 for c in counts.values()) or is_joker) else 0
|
|
|
|
|
if cat_key == "4K": return d_sum if (any(c >= 4 for c in counts.values()) or is_joker) else 0
|
|
|
|
|
if cat_key == "FH":
|
|
|
|
|
return 25 if (any(c==3 for c in counts.values()) and any(c==2 for c in counts.values())) or any(c==5 for c in counts.values()) or is_joker else 0
|
|
|
|
|
if cat_key == "SS":
|
|
|
|
|
return 30 if any(s.issubset(set(dice)) for s in [{1,2,3,4}, {2,3,4,5}, {3,4,5,6}]) or is_joker else 0
|
|
|
|
|
if cat_key == "LS":
|
|
|
|
|
return 40 if s_dice in ([1,2,3,4,5], [2,3,4,5,6]) or is_joker else 0
|
|
|
|
|
if cat_key == "Y": return 50 if any(c == 5 for c in counts.values()) else 0
|
|
|
|
|
if cat_key == "CH": return d_sum
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
def get_scoreboard(self):
|
|
|
|
|
return [(p.name, p.total_score) for p in self.players]
|
|
|
|
|
|
|
|
|
|
def execute_bot_turn(self, player):
|
|
|
|
|
# Nutzt nun die AIEngine aus ai_profiles.py basierend auf dem ai_level
|
|
|
|
|
return AIEngine.execute_turn(player.ai_level, self, player)
|