feat(blackjack): implement 3-step Devil's Gambit auto-showdown, Deity AI & UI overhaul
This commit is contained in:
parent
163a3665d2
commit
8c9db3631e
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -19,6 +19,7 @@ class BlackjackEngine:
|
|||
self.pot: int = 0
|
||||
self.highest_bet: int = 0
|
||||
self.raises_in_round: int = 0
|
||||
self.cycle_card_drawn: bool = False
|
||||
self.state: str = "PRE_DEAL"
|
||||
|
||||
@property
|
||||
|
|
@ -46,6 +47,7 @@ class BlackjackEngine:
|
|||
"pot": self.pot,
|
||||
"highest_bet": self.highest_bet,
|
||||
"raises_in_round": self.raises_in_round,
|
||||
"cycle_card_drawn": self.cycle_card_drawn,
|
||||
"state": self.state,
|
||||
"player_hands": [
|
||||
{
|
||||
|
|
@ -87,6 +89,7 @@ class BlackjackEngine:
|
|||
self.pot = data["pot"]
|
||||
self.highest_bet = data["highest_bet"]
|
||||
self.raises_in_round = data.get("raises_in_round", 0)
|
||||
self.cycle_card_drawn = bool(data.get("cycle_card_drawn", False))
|
||||
self.state = data["state"]
|
||||
|
||||
self.player_hands = [
|
||||
|
|
@ -112,7 +115,7 @@ class BlackjackEngine:
|
|||
gold=bd["gold"],
|
||||
hand=self._list_to_cards(bd["hand"]),
|
||||
bet_in_pot=bd["bet_in_pot"],
|
||||
cards_locked=bd.get("cards_locked", bd.get("ready", False)),
|
||||
cards_locked=bd.get("cards_locked", False),
|
||||
busted=bd["busted"],
|
||||
folded=bd["folded"],
|
||||
doubled=bd.get("doubled", False),
|
||||
|
|
@ -137,6 +140,7 @@ class BlackjackEngine:
|
|||
self.pot = p_ante
|
||||
self.highest_bet = p_ante
|
||||
self.raises_in_round = 0
|
||||
self.cycle_card_drawn = False
|
||||
|
||||
p_cards = [self.deck.draw(), self.deck.draw()]
|
||||
p_val, _ = HandEvaluator.evaluate(p_cards)
|
||||
|
|
@ -182,7 +186,6 @@ class BlackjackEngine:
|
|||
return wallet_gold >= self.highest_bet
|
||||
|
||||
def split_player_hand(self) -> int:
|
||||
"""Teilt das Paar in 2 separate Hände auf und platziert den zweiten Einsatz in den Pot."""
|
||||
orig = self.player_hands[0]
|
||||
second_bet = self.highest_bet
|
||||
c1, c2 = orig.cards[0], orig.cards[1]
|
||||
|
|
@ -208,6 +211,7 @@ class BlackjackEngine:
|
|||
)
|
||||
self.player_hands = [h1, h2]
|
||||
self.pot += second_bet
|
||||
self.cycle_card_drawn = True
|
||||
return second_bet
|
||||
|
||||
def get_double_down_cost(self, hand_idx: int) -> int:
|
||||
|
|
@ -215,9 +219,9 @@ class BlackjackEngine:
|
|||
target_bet = max(self.highest_bet, h.bet_in_pot) * 2
|
||||
return max(0, target_bet - h.bet_in_pot)
|
||||
|
||||
def can_double_down(self, hand_idx: int, wallet_gold: int, already_drew_this_turn: bool) -> bool:
|
||||
def can_double_down(self, hand_idx: int, wallet_gold: int, already_drew_this_turn: bool = False) -> bool:
|
||||
h = self.player_hands[hand_idx]
|
||||
if not h.is_active_in_pot or h.cards_locked or already_drew_this_turn or len(h.cards) != 2:
|
||||
if not h.is_active_in_pot or h.cards_locked or h.doubled or already_drew_this_turn or len(h.cards) != 2:
|
||||
return False
|
||||
val, _ = HandEvaluator.evaluate(h.cards)
|
||||
if val >= BJ_TARGET_SCORE:
|
||||
|
|
@ -226,14 +230,12 @@ class BlackjackEngine:
|
|||
return cost > 0 and wallet_gold >= cost
|
||||
|
||||
def double_down_player_hand(self, hand_idx: int) -> tuple[int, Card]:
|
||||
"""Verdoppelt den Einsatz, zieht genau 1 Karte und sperrt die Hand."""
|
||||
cost = self.get_double_down_cost(hand_idx)
|
||||
paid = self.player_add_gold_to_pot(hand_idx, cost)
|
||||
h = self.player_hands[hand_idx]
|
||||
card = self.player_draw_card(hand_idx)
|
||||
h.doubled = True
|
||||
h.cards_locked = True
|
||||
h.acted_once = True
|
||||
return paid, card
|
||||
|
||||
def player_add_gold_to_pot(self, hand_idx: int, amount: int) -> int:
|
||||
|
|
@ -252,11 +254,11 @@ class BlackjackEngine:
|
|||
h = self.player_hands[hand_idx]
|
||||
card = self.deck.draw()
|
||||
h.cards.append(card)
|
||||
self.cycle_card_drawn = True
|
||||
val, _ = HandEvaluator.evaluate(h.cards)
|
||||
if val > BJ_TARGET_SCORE:
|
||||
h.busted = True
|
||||
h.cards_locked = True
|
||||
h.acted_once = True
|
||||
elif val == BJ_TARGET_SCORE:
|
||||
h.cards_locked = True
|
||||
return card
|
||||
|
|
@ -277,38 +279,25 @@ class BlackjackEngine:
|
|||
def bot_draw_card(self, bot: BlackjackBotSeat) -> Card:
|
||||
card = self.deck.draw()
|
||||
bot.hand.append(card)
|
||||
self.cycle_card_drawn = True
|
||||
val, _ = HandEvaluator.evaluate(bot.hand)
|
||||
if val > BJ_TARGET_SCORE:
|
||||
bot.busted = True
|
||||
bot.cards_locked = True
|
||||
bot.acted_once = True
|
||||
elif val == BJ_TARGET_SCORE:
|
||||
bot.cards_locked = True
|
||||
return card
|
||||
|
||||
# --- Zug- & Abschluss-Prüfungen ---
|
||||
def player_hand_needs_turn(self, hand: PlayerHand, wallet_gold: int) -> bool:
|
||||
if not hand.is_active_in_pot:
|
||||
return False
|
||||
needs_call = (hand.bet_in_pot < self.highest_bet and wallet_gold > 0)
|
||||
return (not hand.acted_once) or (not hand.cards_locked) or needs_call
|
||||
|
||||
def bot_needs_turn(self, bot: BlackjackBotSeat) -> bool:
|
||||
if not bot.is_active_in_pot:
|
||||
return False
|
||||
needs_call = (bot.bet_in_pot < self.highest_bet and bot.gold > 0)
|
||||
return (not bot.acted_once) or (not bot.cards_locked) or needs_call
|
||||
|
||||
def is_everyone_finished(self, bots: list[BlackjackBotSeat], player_wallet_gold: int) -> bool:
|
||||
if not self.any_contender_alive(bots):
|
||||
return True
|
||||
# --- Umlauf- & Ausgleichs-Prüfungen ---
|
||||
def has_unsettled_bets(self, bots: list[BlackjackBotSeat], player_wallet_gold: int) -> bool:
|
||||
if player_wallet_gold > 0:
|
||||
for h in self.player_hands:
|
||||
if self.player_hand_needs_turn(h, player_wallet_gold):
|
||||
return False
|
||||
for b in bots:
|
||||
if self.bot_needs_turn(b):
|
||||
return False
|
||||
if h.is_active_in_pot and h.bet_in_pot < self.highest_bet:
|
||||
return True
|
||||
for b in bots:
|
||||
if b.is_active_in_pot and b.gold > 0 and b.bet_in_pot < self.highest_bet:
|
||||
return True
|
||||
return False
|
||||
|
||||
def any_contender_alive(self, bots: list[BlackjackBotSeat]) -> bool:
|
||||
return self.any_player_hand_active or any(b.is_active_in_pot for b in bots)
|
||||
|
|
@ -327,7 +316,6 @@ class BlackjackEngine:
|
|||
@staticmethod
|
||||
def _hand_rank(cards: list[Card], is_split: bool = False) -> tuple[int, int]:
|
||||
rank = HandEvaluator.showdown_rank(cards)
|
||||
# Gesplittete 2-Karten-21 zählt regulär als 21 statt Natural Blackjack
|
||||
if is_split and rank == (2, 21):
|
||||
return (1, 21)
|
||||
return rank
|
||||
|
|
@ -336,7 +324,6 @@ class BlackjackEngine:
|
|||
self.state = "SHOWDOWN"
|
||||
total_p_bet = self.total_player_bet
|
||||
|
||||
# Solo-Modus ohne Bots (Spielerhände direkt gegen die Bank)
|
||||
if not bots:
|
||||
active_p_hands = [h for h in self.player_hands if h.is_active_in_pot]
|
||||
if not active_p_hands:
|
||||
|
|
@ -367,7 +354,6 @@ class BlackjackEngine:
|
|||
"bot_gains": [],
|
||||
}
|
||||
|
||||
# Multi-Player Vegas-Pot Modus
|
||||
contenders: list[tuple[str, object, tuple[int, int]]] = []
|
||||
for h in self.player_hands:
|
||||
if h.is_active_in_pot:
|
||||
|
|
|
|||
|
|
@ -5,16 +5,15 @@ from games.blackjack.models.bot_seat import BlackjackBotSeat
|
|||
from games.blackjack.models.hand_evaluator import HandEvaluator
|
||||
from models.card import Card
|
||||
from resources.code_res.game_constants import (
|
||||
ACE_RANK, BJ_MAX_RAISES_PER_ROUND, BJ_STARTING_GOLD,
|
||||
BOT_DEITY_LEVEL, FACE_RANKS, SEVEN_RANK
|
||||
ACE_RANK, BJ_STARTING_GOLD, BOT_DEITY_LEVEL, FACE_RANKS, SEVEN_RANK
|
||||
)
|
||||
|
||||
|
||||
class BlackjackBotAI:
|
||||
"""
|
||||
4-Stufen-Ablaufbaum KI:
|
||||
- Stufe 0..5: Abgestufte Offline-Gegner
|
||||
- Stufe 6 (BOT_DEITY_LEVEL): Entfesselte Gottheit-KI (Online-Standard, kein Kindergarten!)
|
||||
3-Stufen-Ablaufbaum KI (ohne Endlos-Bieten):
|
||||
1. Mitgehen? (falls Erhöhung offen) -> 2. Karte ziehen / Keine Karte -> 3. Erhöhen?
|
||||
Zieht im gesamten Tisch-Umlauf niemand eine Karte, wird automatisch aufgedeckt!
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
|
|
@ -22,7 +21,6 @@ class BlackjackBotAI:
|
|||
|
||||
@staticmethod
|
||||
def enforce_online_deity_bots(bot_configs: list[tuple[int, str]]) -> list[tuple[int, str]]:
|
||||
"""Zwingt im Online-Modus ausnahmslos alle Bots auf Gottheit-Niveau (Stufe 6)."""
|
||||
return [(BOT_DEITY_LEVEL, name) for _lvl, name in bot_configs]
|
||||
|
||||
def reset_count(self):
|
||||
|
|
@ -45,25 +43,25 @@ class BlackjackBotAI:
|
|||
else:
|
||||
bot.rebought = False
|
||||
|
||||
# --- KNOTEN 1: Mitgehen? ---
|
||||
# --- KNOTEN 1: Offene Erhöhung mitgehen oder austreten? ---
|
||||
def decide_step1_mitgehen(
|
||||
self, bot: BlackjackBotSeat, highest_bet: int, dealer_upcard: Card | None = None, remaining_cards: int = 52
|
||||
) -> bool:
|
||||
val, is_soft = HandEvaluator.evaluate(bot.hand)
|
||||
to_call = max(0, highest_bet - bot.bet_in_pot)
|
||||
if to_call <= 0 or bot.gold <= 0:
|
||||
return True
|
||||
|
||||
val, is_soft = HandEvaluator.evaluate(bot.hand)
|
||||
lvl = bot.ai_level
|
||||
|
||||
if to_call > 0 and bot.gold > 0:
|
||||
if lvl == 0:
|
||||
return random.random() < 0.75
|
||||
|
||||
# Gottheit-Stufe (6): Rechnet Pot-Odds + Dealer-Upcard + True Count knallhart gegen!
|
||||
if lvl >= BOT_DEITY_LEVEL:
|
||||
if val >= 19 or (not is_soft and val in (10, 11)) or is_soft:
|
||||
return True
|
||||
up = dealer_upcard.blackjack_value if dealer_upcard else 10
|
||||
tc = self.get_true_count(remaining_cards)
|
||||
# Gegen starke Dealer-Upcard (9, 10, A) mit steifer 14-16 und teurem Raise -> eiskalter Fold
|
||||
if 13 <= val <= 16 and up >= 8 and to_call >= max(10, highest_bet // 4):
|
||||
return False
|
||||
if val == 17 and up >= 10 and to_call >= max(15, highest_bet // 2) and tc < 1.0:
|
||||
|
|
@ -76,27 +74,11 @@ class BlackjackBotAI:
|
|||
return random.random() < 0.30
|
||||
return True
|
||||
|
||||
if bot.cards_locked:
|
||||
# Gottheit bleibt mit 20/21 im Zug, falls noch Raisedruck aufgebaut werden kann!
|
||||
if lvl >= BOT_DEITY_LEVEL and val >= 20:
|
||||
return True
|
||||
return False
|
||||
if not is_soft and val >= 19 and 1 <= lvl < BOT_DEITY_LEVEL and random.random() < 0.65:
|
||||
return False
|
||||
return True
|
||||
|
||||
# --- KNOTEN 2: Ziehen? (inkl. Double Down Option) ---
|
||||
# --- KNOTEN 2: Karte ziehen oder keine neue Karte? ---
|
||||
def wants_double_down(
|
||||
self,
|
||||
bot: BlackjackBotSeat,
|
||||
dealer_upcard: Card,
|
||||
highest_bet: int,
|
||||
raises_in_round: int,
|
||||
remaining_cards: int = 52,
|
||||
self, bot: BlackjackBotSeat, dealer_upcard: Card, highest_bet: int, remaining_cards: int = 52
|
||||
) -> bool:
|
||||
if bot.cards_locked or len(bot.hand) != 2 or bot.ai_level < 2:
|
||||
return False
|
||||
if raises_in_round >= BJ_MAX_RAISES_PER_ROUND:
|
||||
if bot.cards_locked or bot.doubled or len(bot.hand) != 2 or bot.ai_level < 2:
|
||||
return False
|
||||
double_cost = max(highest_bet, bot.bet_in_pot) * 2 - bot.bet_in_pot
|
||||
if bot.gold < double_cost or double_cost <= 0:
|
||||
|
|
@ -126,22 +108,21 @@ class BlackjackBotAI:
|
|||
def decide_step2_ziehen(
|
||||
self, bot: BlackjackBotSeat, dealer_upcard: Card, remaining_cards: int
|
||||
) -> bool:
|
||||
if bot.cards_locked:
|
||||
if bot.cards_locked or bot.doubled:
|
||||
return False
|
||||
val, is_soft = HandEvaluator.evaluate(bot.hand)
|
||||
up = dealer_upcard.blackjack_value
|
||||
return self._wants_hit(bot.ai_level, bot.hand, val, is_soft, up, remaining_cards)
|
||||
|
||||
# --- KNOTEN 3: Erhöhen? ---
|
||||
# --- KNOTEN 3: Einsatz erhöhen? (nur im regulären Zug, nicht im reinen Ausgleich!) ---
|
||||
def decide_step3_erhoehen(
|
||||
self,
|
||||
bot: BlackjackBotSeat,
|
||||
chips: tuple[int, ...],
|
||||
remaining_cards: int,
|
||||
raises_in_round: int,
|
||||
dealer_upcard: Card | None = None,
|
||||
) -> int:
|
||||
if raises_in_round >= BJ_MAX_RAISES_PER_ROUND or bot.gold < chips[0]:
|
||||
if bot.gold < chips[0]:
|
||||
return 0
|
||||
val, is_soft = HandEvaluator.evaluate(bot.hand)
|
||||
lvl = bot.ai_level
|
||||
|
|
@ -168,38 +149,22 @@ class BlackjackBotAI:
|
|||
return min(bot.gold, chips[0])
|
||||
return 0
|
||||
|
||||
# --- STUFE 6: GOTTHEIT (Gnadenloser Druck bei Edge!) ---
|
||||
# Stufe 6: Gottheit
|
||||
up = dealer_upcard.blackjack_value if dealer_upcard else 10
|
||||
affordable = [c for c in chips if c <= bot.gold]
|
||||
if not affordable:
|
||||
return 0
|
||||
|
||||
if val == 21:
|
||||
# Mit 21 feuert Gottheit fast immer den höchsten bezahlbaren Chip rein!
|
||||
return affordable[-1] if tc >= 0.0 else affordable[min(2, len(affordable) - 1)]
|
||||
if val == 20:
|
||||
if up <= 9 or tc >= 1.0:
|
||||
return affordable[min(2, len(affordable) - 1)]
|
||||
return affordable[0]
|
||||
return affordable[min(2, len(affordable) - 1)] if (up <= 9 or tc >= 1.0) else affordable[0]
|
||||
if val == 19 and (2 <= up <= 6) and not is_soft:
|
||||
# Dealer zeigt Bust-Karte (2-6) und Gottheit hält 19 -> Gegner bluten lassen
|
||||
return affordable[min(1, len(affordable) - 1)]
|
||||
if (2 <= up <= 6) and val >= 18 and tc >= 2.0:
|
||||
return affordable[0]
|
||||
return 0
|
||||
|
||||
# --- KNOTEN 4: Fertig? ---
|
||||
def decide_step4_fertig(
|
||||
self, bot: BlackjackBotSeat, dealer_upcard: Card, remaining_cards: int
|
||||
) -> bool:
|
||||
if bot.cards_locked:
|
||||
return True
|
||||
val, is_soft = HandEvaluator.evaluate(bot.hand)
|
||||
if val >= 21:
|
||||
return True
|
||||
up = dealer_upcard.blackjack_value
|
||||
return not self._wants_hit(bot.ai_level, bot.hand, val, is_soft, up, remaining_cards)
|
||||
|
||||
def _wants_hit(
|
||||
self, lvl: int, hand: list[Card], val: int, is_soft: bool, up: int, remaining_cards: int
|
||||
) -> bool:
|
||||
|
|
@ -230,7 +195,7 @@ class BlackjackBotAI:
|
|||
return False
|
||||
return self._basic_strategy_hit(val, is_soft, up)
|
||||
|
||||
# --- STUFE 6: GOTTHEIT (Volle Illustrious-18 Index-Abweichungen) ---
|
||||
# Stufe 6: Gottheit (Illustrious-18)
|
||||
if not is_soft:
|
||||
if val == 16 and up == 10:
|
||||
return tc < 0.0
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -14,10 +14,10 @@ from models.database import Database
|
|||
from models.progression import Progression
|
||||
from resources.code_res.game_constants import (
|
||||
ACCENT_GOLD, ACCENT_GOTH, BJ_BOT_CARD_SIZE, BJ_BOT_TURN_DELAY_MS,
|
||||
BJ_DEALER_DELAY_MS, BJ_INITIAL_ANTE, BJ_MAX_RAISES_PER_ROUND,
|
||||
BJ_SPLIT_CARD_SIZE, BJ_STARTING_GOLD, BJ_VARIANTS, BORDER_COLOR,
|
||||
CELL_BG, ERROR_FG, FG_COLOR, GOLD_MIN_TABLE_ENTRY, MUTED_FG,
|
||||
PANEL_BG, PLAYING_CARD_SIZE, SUBTLE_BORDER, TABLE_BG, XP_TO_GOLD_AMOUNT
|
||||
BJ_DEALER_DELAY_MS, BJ_INITIAL_ANTE, BJ_SPLIT_CARD_SIZE,
|
||||
BJ_STARTING_GOLD, BJ_VARIANTS, BORDER_COLOR, CELL_BG, ERROR_FG,
|
||||
FG_COLOR, GOLD_MIN_TABLE_ENTRY, MUTED_FG, PANEL_BG,
|
||||
PLAYING_CARD_SIZE, SUBTLE_BORDER, TABLE_BG, XP_TO_GOLD_AMOUNT
|
||||
)
|
||||
from resources.code_res.i18n import t
|
||||
from view.widgets.image_button import ImageButton
|
||||
|
|
@ -27,7 +27,6 @@ GAME_FOLDER_ID = "blackjack"
|
|||
STEP_MITGEHEN = "MITGEHEN"
|
||||
STEP_ZIEHEN = "ZIEHEN"
|
||||
STEP_ERHOEHEN = "ERHOEHEN"
|
||||
STEP_FERTIG = "FERTIG"
|
||||
|
||||
|
||||
class BlackjackTableView:
|
||||
|
|
@ -48,7 +47,8 @@ class BlackjackTableView:
|
|||
self.bot_ai = BlackjackBotAI()
|
||||
|
||||
self.active_hand_idx: int = 0
|
||||
self.turn_step: str = STEP_MITGEHEN
|
||||
self.turn_step: str = STEP_ZIEHEN
|
||||
self.settle_only_mode: bool = False
|
||||
self.active_bot_idx: int = -1
|
||||
self.round_start_time: float = time.time()
|
||||
self._last_popup_payload: dict | None = None
|
||||
|
|
@ -74,7 +74,7 @@ class BlackjackTableView:
|
|||
self._start_new_round()
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# AUTO-SAVE & RESUME (speichert auch den exakten Baum-Knoten!)
|
||||
# AUTO-SAVE & RESUME (nur aktiv während The Devil's Deal!)
|
||||
# ---------------------------------------------------------
|
||||
def _persist_state(self):
|
||||
if not self.devils_locked:
|
||||
|
|
@ -84,6 +84,7 @@ class BlackjackTableView:
|
|||
"devils_locked": self.devils_locked,
|
||||
"active_hand_idx": self.active_hand_idx,
|
||||
"turn_step": self.turn_step,
|
||||
"settle_only_mode": self.settle_only_mode,
|
||||
"active_bot_idx": self.active_bot_idx,
|
||||
"elapsed_sec": max(0.0, time.time() - self.round_start_time),
|
||||
"running_count": self.bot_ai.running_count,
|
||||
|
|
@ -106,7 +107,8 @@ class BlackjackTableView:
|
|||
self.bj_account = Database.get_blackjack_account(data["bj_account_id"])
|
||||
self.devils_locked = bool(data.get("devils_locked", False) or self.bj_account.get("devils_deal_active", 0))
|
||||
self.active_hand_idx = int(data.get("active_hand_idx", 0))
|
||||
self.turn_step = data.get("turn_step", STEP_MITGEHEN)
|
||||
self.turn_step = data.get("turn_step", STEP_ZIEHEN)
|
||||
self.settle_only_mode = bool(data.get("settle_only_mode", False))
|
||||
self.active_bot_idx = int(data.get("active_bot_idx", -1))
|
||||
self.round_start_time = time.time() - float(data.get("elapsed_sec", 0.0))
|
||||
self.bot_ai.running_count = int(data.get("running_count", 0))
|
||||
|
|
@ -126,17 +128,13 @@ class BlackjackTableView:
|
|||
self._build_ui()
|
||||
|
||||
if self.engine.state == "ACTION_LOOP":
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
if self.active_bot_idx >= 0:
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
self._step_next_bot()
|
||||
else:
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
if 0 <= self.active_hand_idx < len(self.engine.player_hands) and self.engine.player_hand_needs_turn(
|
||||
self.engine.player_hands[self.active_hand_idx], self.bj_account["gold"]
|
||||
):
|
||||
elif 0 <= self.active_hand_idx < len(self.engine.player_hands):
|
||||
self._render_current_tree_step()
|
||||
else:
|
||||
self._begin_next_turn_cycle()
|
||||
self._begin_new_table_cycle()
|
||||
elif self.engine.state == "DEALER_TURN":
|
||||
self._render_table(reveal_opponents=True, reveal_dealer=True)
|
||||
self.status_lbl.configure(text=t("bj_dealer_reveals"))
|
||||
|
|
@ -249,7 +247,7 @@ class BlackjackTableView:
|
|||
self.pot_lbl.configure(text=t("bj_pot_banner", self.engine.pot, self.engine.highest_bet))
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# ROUND START (10 Gold Grundeinsatz -> Karten verteilen)
|
||||
# ROUND START
|
||||
# ---------------------------------------------------------
|
||||
def _start_new_round(self):
|
||||
if self._result_dialog:
|
||||
|
|
@ -275,7 +273,7 @@ class BlackjackTableView:
|
|||
|
||||
self._last_popup_payload = None
|
||||
self.active_hand_idx = 0
|
||||
self.turn_step = STEP_MITGEHEN
|
||||
self.settle_only_mode = False
|
||||
self.active_bot_idx = -1
|
||||
self.round_start_time = time.time()
|
||||
self.ctx.sounds.play("deal")
|
||||
|
|
@ -297,7 +295,7 @@ class BlackjackTableView:
|
|||
|
||||
self._build_ui()
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
self._begin_next_turn_cycle()
|
||||
self._begin_new_table_cycle()
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# RENDERING TISCH & HÄNDE
|
||||
|
|
@ -308,7 +306,7 @@ class BlackjackTableView:
|
|||
return t("bj_state_busted")
|
||||
if hand.folded:
|
||||
return t("bj_state_folded")
|
||||
if hand.cards_locked:
|
||||
if hand.doubled or hand.cards_locked:
|
||||
return t("bj_state_locked")
|
||||
return ""
|
||||
|
||||
|
|
@ -446,38 +444,114 @@ class BlackjackTableView:
|
|||
self._refresh_header()
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# STUFENWEISER ABLAUFBAUM FÜR DEN SPIELER
|
||||
# TISCH-UMLAUF LOGIK (Keine Karte gezogen -> Auto-Showdown!)
|
||||
# ---------------------------------------------------------
|
||||
def _begin_next_turn_cycle(self):
|
||||
self.bj_account = Database.get_blackjack_account(self.bj_account["id"])
|
||||
if self.engine.is_everyone_finished(self.bots, self.bj_account["gold"]):
|
||||
def _begin_new_table_cycle(self):
|
||||
"""Startet einen neuen Tisch-Umlauf mit cycle_card_drawn = False."""
|
||||
if not self.engine.any_contender_alive(self.bots):
|
||||
self._start_showdown_and_dealer()
|
||||
return
|
||||
|
||||
self.engine.cycle_card_drawn = False
|
||||
self.settle_only_mode = False
|
||||
self.active_bot_idx = -1
|
||||
self.active_hand_idx = 0
|
||||
self._step_next_player_hand()
|
||||
|
||||
def _begin_settle_bets_pass(self):
|
||||
"""
|
||||
Niemand hat im Umlauf eine Karte gezogen, aber ein letzter Raise ist noch offen:
|
||||
Jeder mit Rückstand darf nur noch Mitgehen oder Austreten, danach sofort Aufdecken!
|
||||
"""
|
||||
self.settle_only_mode = True
|
||||
self.active_bot_idx = -1
|
||||
self.active_hand_idx = 0
|
||||
self._step_next_player_hand()
|
||||
|
||||
def _on_table_pass_completed(self):
|
||||
"""Wird am Ende jedes Tisch-Umlaufs (Spieler + alle Bots) aufgerufen."""
|
||||
if not self.engine.any_contender_alive(self.bots):
|
||||
self._start_showdown_and_dealer()
|
||||
return
|
||||
|
||||
self.bj_account = Database.get_blackjack_account(self.bj_account["id"])
|
||||
wallet = self.bj_account["gold"]
|
||||
|
||||
if self.settle_only_mode:
|
||||
# Alle offenen Einsätze beglichen -> sofort aufdecken!
|
||||
self._start_showdown_and_dealer()
|
||||
return
|
||||
|
||||
if not self.engine.cycle_card_drawn:
|
||||
# KEINER hat in dieser Runde eine Karte gezogen!
|
||||
if self.engine.has_unsettled_bets(self.bots, wallet):
|
||||
self._begin_settle_bets_pass()
|
||||
else:
|
||||
self._start_showdown_and_dealer()
|
||||
return
|
||||
|
||||
# Mindestens einer hat eine Karte gezogen -> nächster regulärer Umlauf!
|
||||
self._begin_new_table_cycle()
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# SPIELER-SCHRITTE IM UMLAUF
|
||||
# ---------------------------------------------------------
|
||||
def _step_next_player_hand(self):
|
||||
self.bj_account = Database.get_blackjack_account(self.bj_account["id"])
|
||||
wallet = self.bj_account["gold"]
|
||||
|
||||
while self.active_hand_idx < len(self.engine.player_hands):
|
||||
h = self.engine.player_hands[self.active_hand_idx]
|
||||
if self.engine.player_hand_needs_turn(h, wallet):
|
||||
if not h.is_active_in_pot:
|
||||
self.active_hand_idx += 1
|
||||
continue
|
||||
|
||||
raw_deficit = max(0, self.engine.highest_bet - h.bet_in_pot)
|
||||
to_call = min(wallet, raw_deficit)
|
||||
|
||||
if self.settle_only_mode:
|
||||
if to_call > 0:
|
||||
self.turn_step = STEP_MITGEHEN
|
||||
self._persist_state()
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
self._render_current_tree_step()
|
||||
return
|
||||
self.active_hand_idx += 1
|
||||
continue
|
||||
|
||||
# Regulärer Zug im Umlauf:
|
||||
# 1. Falls ein Raise offen ist -> erst Mitgehen? fragen
|
||||
if to_call > 0:
|
||||
self.turn_step = STEP_MITGEHEN
|
||||
self._persist_state()
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
self._render_current_tree_step()
|
||||
return
|
||||
|
||||
# 2. Kein offener Raise -> direkt fragen: Karte ziehen oder Keine neue Karte?
|
||||
h_val, _ = HandEvaluator.evaluate(h.cards)
|
||||
if not h.cards_locked and not h.doubled and h_val < 21:
|
||||
self.turn_step = STEP_ZIEHEN
|
||||
self._persist_state()
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
self._render_current_tree_step()
|
||||
return
|
||||
|
||||
# 3. Hand steht schon bei 21 / Double Down -> darf bei verfügbarem Gold noch erhöhen
|
||||
dyn_chips = self._get_current_level_chips()
|
||||
if wallet >= dyn_chips[0]:
|
||||
self.turn_step = STEP_ERHOEHEN
|
||||
self._persist_state()
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
self._render_current_tree_step()
|
||||
return
|
||||
|
||||
self.active_hand_idx += 1
|
||||
|
||||
# Alle eigenen Hände durch -> sofort der nächste Gegner dran!
|
||||
self._start_bots_cycle()
|
||||
|
||||
def _finish_current_hand_turn(self):
|
||||
self.active_hand_idx += 1
|
||||
self.turn_step = STEP_MITGEHEN
|
||||
self._persist_state()
|
||||
self._step_next_player_hand()
|
||||
|
||||
|
|
@ -494,53 +568,30 @@ class BlackjackTableView:
|
|||
row.pack()
|
||||
|
||||
# =====================================================
|
||||
# KNOTEN 1: MITGEHEN?
|
||||
# SCHRITT 1: MITGEHEN? (nur wenn ein Gegner erhöht hat!)
|
||||
# =====================================================
|
||||
if self.turn_step == STEP_MITGEHEN:
|
||||
raw_deficit = max(0, self.engine.highest_bet - hand.bet_in_pot)
|
||||
to_call = min(wallet, raw_deficit)
|
||||
|
||||
if to_call > 0:
|
||||
self.status_lbl.configure(text=t("bj_tree_step1_call", hand_tag, to_call))
|
||||
ImageButton(
|
||||
row, t("bj_tree_btn_call_yes", to_call),
|
||||
self.ctx.assets.raw_btn, self.ctx.assets.raw_btn_active,
|
||||
lambda: self._on_step1_yes(to_call),
|
||||
sound_mgr=self.ctx.sounds, width=215, height=38, font=("Helvetica", 10, "bold")
|
||||
lambda: self._on_step1_call_yes(to_call),
|
||||
sound_mgr=self.ctx.sounds, width=220, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=8)
|
||||
|
||||
ImageButton(
|
||||
row, t("bj_tree_btn_call_no_lose"),
|
||||
self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active,
|
||||
self._on_step1_no_when_raised,
|
||||
sound_mgr=self.ctx.sounds, width=225, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=8)
|
||||
else:
|
||||
self.status_lbl.configure(text=t("bj_tree_step1_even", hand_tag))
|
||||
ImageButton(
|
||||
row, t("bj_tree_btn_play_yes"),
|
||||
self.ctx.assets.raw_btn, self.ctx.assets.raw_btn_active,
|
||||
lambda: self._on_step1_yes(0),
|
||||
sound_mgr=self.ctx.sounds, width=235, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=8)
|
||||
|
||||
ImageButton(
|
||||
row, t("bj_tree_btn_even_no_done"),
|
||||
self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active,
|
||||
self._on_step1_no_mark_ready,
|
||||
sound_mgr=None, width=225, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=8)
|
||||
|
||||
ImageButton(
|
||||
row, t("bj_fold_btn"),
|
||||
self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active,
|
||||
self._on_step1_no_when_raised,
|
||||
sound_mgr=self.ctx.sounds, width=130, height=38, font=("Helvetica", 10, "bold")
|
||||
self._on_fold_hand,
|
||||
sound_mgr=self.ctx.sounds, width=230, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=8)
|
||||
return
|
||||
|
||||
# =====================================================
|
||||
# KNOTEN 2: ZIEHEN? (inkl. Split / Double Down bei 2 Karten)
|
||||
# SCHRITT 2: KARTE ZIEHEN ODER KEINE NEUE KARTE?
|
||||
# =====================================================
|
||||
if self.turn_step == STEP_ZIEHEN:
|
||||
self.status_lbl.configure(text=t("bj_tree_step2_draw", hand_tag))
|
||||
|
|
@ -550,16 +601,16 @@ class BlackjackTableView:
|
|||
self.ctx.assets.raw_btn, self.ctx.assets.raw_btn_active,
|
||||
self._on_step2_draw_yes,
|
||||
sound_mgr=self.ctx.sounds, width=185, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=6)
|
||||
).pack(side="left", padx=5)
|
||||
|
||||
if self.engine.can_double_down(self.active_hand_idx, wallet, already_drew_this_turn=False):
|
||||
if self.engine.can_double_down(self.active_hand_idx, wallet):
|
||||
dd_cost = self.engine.get_double_down_cost(self.active_hand_idx)
|
||||
ImageButton(
|
||||
row, t("bj_double_btn", dd_cost),
|
||||
self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active,
|
||||
self._on_step2_double_down,
|
||||
sound_mgr=self.ctx.sounds, width=175, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=6)
|
||||
sound_mgr=self.ctx.sounds, width=170, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=5)
|
||||
|
||||
if self.engine.can_split_hand(self.active_hand_idx, wallet):
|
||||
sp_cost = self.engine.highest_bet
|
||||
|
|
@ -567,19 +618,26 @@ class BlackjackTableView:
|
|||
row, t("bj_split_btn", sp_cost),
|
||||
self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active,
|
||||
self._on_step2_split,
|
||||
sound_mgr=self.ctx.sounds, width=150, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=6)
|
||||
sound_mgr=self.ctx.sounds, width=145, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=5)
|
||||
|
||||
ImageButton(
|
||||
row, t("bj_tree_btn_draw_no"),
|
||||
self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active,
|
||||
self._on_step2_draw_no,
|
||||
sound_mgr=self.ctx.sounds, width=180, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=6)
|
||||
sound_mgr=None, width=180, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=5)
|
||||
|
||||
ImageButton(
|
||||
row, t("bj_fold_btn"),
|
||||
self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active,
|
||||
self._on_fold_hand,
|
||||
sound_mgr=self.ctx.sounds, width=120, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=5)
|
||||
return
|
||||
|
||||
# =====================================================
|
||||
# KNOTEN 3: ERHÖHEN? (erst NACH Weiter/Ziehen sichtbar!)
|
||||
# SCHRITT 3: ERHÖHEN?
|
||||
# =====================================================
|
||||
if self.turn_step == STEP_ERHOEHEN:
|
||||
self.status_lbl.configure(text=t("bj_tree_step3_raise", hand_tag))
|
||||
|
|
@ -600,96 +658,56 @@ class BlackjackTableView:
|
|||
self._on_step3_raise_no,
|
||||
sound_mgr=self.ctx.sounds, width=190, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=8)
|
||||
return
|
||||
|
||||
# =====================================================
|
||||
# KNOTEN 4: FERTIG?
|
||||
# =====================================================
|
||||
if self.turn_step == STEP_FERTIG:
|
||||
self.status_lbl.configure(text=t("bj_tree_step4_done", hand_tag))
|
||||
|
||||
ImageButton(
|
||||
row, t("bj_tree_btn_done_yes"),
|
||||
self.ctx.assets.raw_btn, self.ctx.assets.raw_btn_active,
|
||||
self._on_step4_done_yes,
|
||||
sound_mgr=None, width=225, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=8)
|
||||
|
||||
ImageButton(
|
||||
row, t("bj_tree_btn_done_no"),
|
||||
self.ctx.assets.raw_sel, self.ctx.assets.raw_sel_active,
|
||||
self._on_step4_done_no,
|
||||
sound_mgr=self.ctx.sounds, width=230, height=38, font=("Helvetica", 10, "bold")
|
||||
).pack(side="left", padx=8)
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# ÜBERGÄNGE ZWISCHEN DEN BAUM-KNOTEN
|
||||
# BUTTON-AKTIONEN SPIELER
|
||||
# ---------------------------------------------------------
|
||||
def _advance_to_erhoehen_or_fertig(self):
|
||||
"""Springt zu Knoten 3 (Erhöhen?), oder direkt weiter, falls kein Gold/Raise-Cap mehr frei ist."""
|
||||
def _advance_to_erhoehen_or_next(self):
|
||||
self.bj_account = Database.get_blackjack_account(self.bj_account["id"])
|
||||
wallet = self.bj_account["gold"]
|
||||
dyn_chips = self._get_current_level_chips()
|
||||
can_raise = (self.engine.raises_in_round < BJ_MAX_RAISES_PER_ROUND) and (wallet >= dyn_chips[0])
|
||||
|
||||
if can_raise:
|
||||
# Solo ohne Bots und ohne gezogene Karte im Umlauf -> sofort aufdecken ohne unnötige Erhöhungs-Frage!
|
||||
if not self.bots and not self.engine.cycle_card_drawn:
|
||||
self._finish_current_hand_turn()
|
||||
return
|
||||
|
||||
if wallet >= dyn_chips[0]:
|
||||
self.turn_step = STEP_ERHOEHEN
|
||||
self._persist_state()
|
||||
self._render_current_tree_step()
|
||||
else:
|
||||
self._advance_to_fertig_or_next()
|
||||
|
||||
def _advance_to_fertig_or_next(self):
|
||||
"""Springt zu Knoten 4 (Fertig?), oder gibt direkt an den nächsten Spieler ab, falls Karten schon feststehen."""
|
||||
hand = self.engine.player_hands[self.active_hand_idx]
|
||||
if hand.cards_locked:
|
||||
self._finish_current_hand_turn()
|
||||
else:
|
||||
self.turn_step = STEP_FERTIG
|
||||
self._persist_state()
|
||||
self._render_current_tree_step()
|
||||
|
||||
def _on_step1_yes(self, to_call: int):
|
||||
"""Knoten 1 -> Ja (Mitgehen): Zahlt ggf. Differenz ein und geht zu Knoten 2 (Ziehen?)."""
|
||||
def _on_step1_call_yes(self, to_call: int):
|
||||
if to_call > 0:
|
||||
paid = self.engine.player_add_gold_to_pot(self.active_hand_idx, to_call)
|
||||
if paid > 0:
|
||||
self.bj_account = Database.update_blackjack_gold(self.bj_account["id"], -paid)
|
||||
|
||||
hand = self.engine.player_hands[self.active_hand_idx]
|
||||
hand.acted_once = True
|
||||
h_val, _ = HandEvaluator.evaluate(hand.cards)
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
|
||||
if not hand.cards_locked and h_val < 21:
|
||||
if self.settle_only_mode:
|
||||
self._finish_current_hand_turn()
|
||||
return
|
||||
|
||||
hand = self.engine.player_hands[self.active_hand_idx]
|
||||
h_val, _ = HandEvaluator.evaluate(hand.cards)
|
||||
if not hand.cards_locked and not hand.doubled and h_val < 21:
|
||||
self.turn_step = STEP_ZIEHEN
|
||||
self._persist_state()
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
self._render_current_tree_step()
|
||||
else:
|
||||
# Karten standen bereits fest (z.B. 21 oder vorher Fertig gemeldet) -> weiter zu Erhöhen? / Nächster!
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
self._advance_to_erhoehen_or_fertig()
|
||||
self._advance_to_erhoehen_or_next()
|
||||
|
||||
def _on_step1_no_mark_ready(self):
|
||||
"""Knoten 1 -> Nein (ohne offenen Raise): Spieler wird als Fertig markiert -> direkt Nächster dran!"""
|
||||
self.ctx.sounds.play("stand")
|
||||
hand = self.engine.player_hands[self.active_hand_idx]
|
||||
hand.cards_locked = True
|
||||
hand.acted_once = True
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
self._finish_current_hand_turn()
|
||||
|
||||
def _on_step1_no_when_raised(self):
|
||||
"""Knoten 1 -> Nein gegen Erhöhung / Austreten: Sofort Verloren (Out) -> Nächster dran!"""
|
||||
def _on_fold_hand(self):
|
||||
hand = self.engine.player_hands[self.active_hand_idx]
|
||||
hand.folded = True
|
||||
hand.cards_locked = True
|
||||
hand.acted_once = True
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
self._finish_current_hand_turn()
|
||||
|
||||
def _on_step2_draw_yes(self):
|
||||
"""Knoten 2 -> Ja (Ziehen!): Zieht Karte -> über 21 = Verloren, sonst zu Knoten 3 (Erhöhen?)."""
|
||||
hand = self.engine.player_hands[self.active_hand_idx]
|
||||
self.engine.player_draw_card(self.active_hand_idx)
|
||||
|
||||
|
|
@ -699,15 +717,15 @@ class BlackjackTableView:
|
|||
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
if hand.busted:
|
||||
# Über 21 -> sofort Verloren & nächster Spieler dran!
|
||||
self._finish_current_hand_turn()
|
||||
return
|
||||
|
||||
self._advance_to_erhoehen_or_fertig()
|
||||
self._advance_to_erhoehen_or_next()
|
||||
|
||||
def _on_step2_draw_no(self):
|
||||
"""Knoten 2 -> Nein (Nicht ziehen): Direkt weiter zu Knoten 3 (Erhöhen?)."""
|
||||
self._advance_to_erhoehen_or_fertig()
|
||||
"""Keine neue Karte genommen -> cycle_card_drawn bleibt unverändert!"""
|
||||
self.ctx.sounds.play("stand")
|
||||
self._advance_to_erhoehen_or_next()
|
||||
|
||||
def _on_step2_double_down(self):
|
||||
paid, _card = self.engine.double_down_player_hand(self.active_hand_idx)
|
||||
|
|
@ -733,7 +751,6 @@ class BlackjackTableView:
|
|||
self._render_current_tree_step()
|
||||
|
||||
def _on_step3_raise_yes(self, chip_amount: int):
|
||||
"""Knoten 3 -> Ja (Erhöhen!): Erhöht den Pot und übergibt laut Baum direkt an Next round / nächsten Spieler!"""
|
||||
paid = self.engine.player_add_gold_to_pot(self.active_hand_idx, chip_amount)
|
||||
if paid > 0:
|
||||
self.bj_account = Database.update_blackjack_gold(self.bj_account["id"], -paid)
|
||||
|
|
@ -741,29 +758,16 @@ class BlackjackTableView:
|
|||
self._finish_current_hand_turn()
|
||||
|
||||
def _on_step3_raise_no(self):
|
||||
"""Knoten 3 -> Nein: Weiter zu Knoten 4 (Fertig?)."""
|
||||
self._advance_to_fertig_or_next()
|
||||
|
||||
def _on_step4_done_yes(self):
|
||||
"""Knoten 4 -> Ja (Fertig): Karten stehen endgültig fest -> Nächster dran!"""
|
||||
self.ctx.sounds.play("stand")
|
||||
hand = self.engine.player_hands[self.active_hand_idx]
|
||||
hand.cards_locked = True
|
||||
self._render_table(reveal_opponents=False, reveal_dealer=False)
|
||||
self._finish_current_hand_turn()
|
||||
|
||||
def _on_step4_done_no(self):
|
||||
"""Knoten 4 -> Nein (Offen bleiben): Direkt der Nächste dran!"""
|
||||
self._finish_current_hand_turn()
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# BOT-ZYKLUS (durchläuft denselben 4-Knoten-Baum)
|
||||
# BOT-ZYKLUS IM UMLAUF
|
||||
# ---------------------------------------------------------
|
||||
def _start_bots_cycle(self):
|
||||
for w in self.controls_frame.winfo_children():
|
||||
w.destroy()
|
||||
if not self.bots or not self.engine.any_contender_alive(self.bots):
|
||||
self._begin_next_turn_cycle()
|
||||
self._on_table_pass_completed()
|
||||
return
|
||||
self.active_bot_idx = 0
|
||||
self._persist_state()
|
||||
|
|
@ -775,14 +779,17 @@ class BlackjackTableView:
|
|||
|
||||
while self.active_bot_idx < len(self.bots):
|
||||
bot = self.bots[self.active_bot_idx]
|
||||
if self.engine.bot_needs_turn(bot):
|
||||
if bot.is_active_in_pot:
|
||||
if not self.settle_only_mode:
|
||||
break
|
||||
if bot.gold > 0 and bot.bet_in_pot < self.engine.highest_bet:
|
||||
break
|
||||
self.active_bot_idx += 1
|
||||
|
||||
if self.active_bot_idx >= len(self.bots):
|
||||
self.active_bot_idx = -1
|
||||
self._persist_state()
|
||||
self._begin_next_turn_cycle()
|
||||
self._on_table_pass_completed()
|
||||
return
|
||||
|
||||
bot = self.bots[self.active_bot_idx]
|
||||
|
|
@ -799,29 +806,31 @@ class BlackjackTableView:
|
|||
dyn_chips = self._get_current_level_chips()
|
||||
raw_deficit = max(0, self.engine.highest_bet - bot.bet_in_pot)
|
||||
to_call = min(bot.gold, raw_deficit)
|
||||
bot.acted_once = True
|
||||
|
||||
# --- KNOTEN 1: Mitgehen? ---
|
||||
if not self.bot_ai.decide_step1_mitgehen(bot, self.engine.highest_bet):
|
||||
# 1. Offene Erhöhung mitgehen oder austreten?
|
||||
if to_call > 0:
|
||||
if not self.bot_ai.decide_step1_mitgehen(
|
||||
bot, self.engine.highest_bet, upcard, self.engine.deck.remaining()
|
||||
):
|
||||
bot.folded = True
|
||||
bot.cards_locked = True
|
||||
bot.status_text = t("bj_bot_action_fold")
|
||||
else:
|
||||
bot.cards_locked = True
|
||||
bot.status_text = t("bj_bot_action_ready", len(bot.hand))
|
||||
self._finish_bot_step()
|
||||
return
|
||||
|
||||
# Bot geht mit!
|
||||
if to_call > 0:
|
||||
self.ctx.sounds.play("click")
|
||||
self.engine.bot_add_gold_to_pot(bot, to_call)
|
||||
|
||||
# --- KNOTEN 2: Ziehen? ---
|
||||
# Im Settle-Modus nach kartenlosem Umlauf nur noch begleichen -> fertig!
|
||||
if self.settle_only_mode:
|
||||
bot.status_text = t("bj_bot_action_call", to_call)
|
||||
self._finish_bot_step()
|
||||
return
|
||||
|
||||
# 2. Karte ziehen oder keine neue Karte?
|
||||
drew_card = False
|
||||
if not bot.cards_locked:
|
||||
if self.bot_ai.wants_double_down(bot, upcard, self.engine.highest_bet, self.engine.raises_in_round):
|
||||
if not bot.cards_locked and not bot.doubled:
|
||||
if self.bot_ai.wants_double_down(bot, upcard, self.engine.highest_bet, self.engine.deck.remaining()):
|
||||
dd_cost = max(self.engine.highest_bet, bot.bet_in_pot) * 2 - bot.bet_in_pot
|
||||
paid = self.engine.bot_add_gold_to_pot(bot, dd_cost)
|
||||
self.ctx.sounds.play("click")
|
||||
|
|
@ -850,36 +859,26 @@ class BlackjackTableView:
|
|||
self._trigger_instant_777_win(winner_is_player=False, winning_bot=bot)
|
||||
return
|
||||
|
||||
# Über 21? -> Verloren!
|
||||
if bot.busted:
|
||||
b_val, _ = HandEvaluator.evaluate(bot.hand)
|
||||
bot.status_text = t("bj_bot_action_bust", b_val)
|
||||
self._finish_bot_step()
|
||||
return
|
||||
|
||||
# --- KNOTEN 3: Erhöhen? ---
|
||||
# 3. Optional erhöhen (nur wenn im aktuellen Umlauf schon eine Karte gezogen wurde oder man Druck macht)
|
||||
raise_amt = self.bot_ai.decide_step3_erhoehen(
|
||||
bot, dyn_chips, self.engine.deck.remaining(), self.engine.raises_in_round
|
||||
bot, dyn_chips, self.engine.deck.remaining(), upcard
|
||||
)
|
||||
if raise_amt > 0:
|
||||
self.ctx.sounds.play("click")
|
||||
self.engine.bot_add_gold_to_pot(bot, raise_amt)
|
||||
if self.bot_ai.decide_step4_fertig(bot, upcard, self.engine.deck.remaining()):
|
||||
bot.cards_locked = True
|
||||
bot.status_text = t("bj_bot_action_bet", raise_amt)
|
||||
self._finish_bot_step()
|
||||
return
|
||||
|
||||
# --- KNOTEN 4: Fertig? ---
|
||||
if self.bot_ai.decide_step4_fertig(bot, upcard, self.engine.deck.remaining()):
|
||||
bot.cards_locked = True
|
||||
bot.status_text = (
|
||||
t("bj_bot_action_call", to_call) if to_call > 0 else t("bj_bot_action_ready", len(bot.hand))
|
||||
)
|
||||
elif drew_card:
|
||||
bot.status_text = t("bj_bot_action_hit", len(bot.hand))
|
||||
elif to_call > 0:
|
||||
bot.status_text = t("bj_bot_action_call", to_call)
|
||||
else:
|
||||
bot.status_text = (
|
||||
t("bj_bot_action_hit", len(bot.hand)) if drew_card else t("bj_bot_action_check", len(bot.hand))
|
||||
)
|
||||
bot.status_text = t("bj_bot_action_ready", len(bot.hand))
|
||||
|
||||
self._finish_bot_step()
|
||||
|
||||
|
|
|
|||
BIN
user_data.db
BIN
user_data.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue