BlackjackDealer
Server-authoritative game controller that manages the full round lifecycle of a Blackjack game - from betting to dealing, player turns, and payout resolution.
Overview
The BlackjackDealer component defines the server logic for a Blackjack table.
It controls the game flow by sequencing timed phases, updating network-synced states, and communicating all visible game events (such as dealing cards) to connected clients.
It ensures fair gameplay and consistent synchronization between players by enforcing server-side rules and managing all card draws via the shared shoe.
Core Responsibilities
Round Lifecycle Management - Handles the sequence of all game phases (betting, dealing, player turns, dealer turn, resolution).
Card Dealing & Visibility - Deals cards to each seated player and to the dealer, ensuring hidden cards are correctly represented on clients.
Server-Authoritative Control - The dealer runs exclusively on the server; all actions, timers, and transitions are verified and executed there.
Table Integration - Accesses
BaseTableto draw cards from the shoe, read seat data, and updateTableStateandSeatStateobjects.Rule Enforcement - Uses
BlackjackRulesto validate blackjacks, busts, and payouts (including multipliers).Client Synchronization - Sends targeted Mirror RPCs to update each player’s hand, reveal cards, and synchronize visual states.
Phase Lifecycle
The BlackjackDealer progresses through several timed phases during a round.
Each phase is server-controlled, using coroutines to manage durations and automatic transitions.
Idle
BlackjackState.Idle
Table is inactive; no players or game running.
Waiting for Bets
BlackjackState.WaitingForBets
Players can place their bets before the round begins.
Dealing
BlackjackState.Dealing
Dealer distributes two cards to each betting player and to themselves.
Evaluate
BlackjackState.Evaluate
Checks for natural Blackjacks before player turns begin.
Player Turn
BlackjackState.PlayerTurn
Each player makes decisions (hit, stand, double, split).
Dealer Turn
BlackjackState.DealerTurn
Dealer plays automatically according to rules (hit until 17, etc.).
Resolution
BlackjackState.Resolution
Winnings and losses are calculated, balances are updated, and the next round begins.
The phase system uses the StartPhase() method to initialize a new state, paired with a coroutine countdown for its duration. When a timer expires, the dealer transitions automatically using NextPhase().
Example Flow
Init - The dealer shuffles the shoe and waits in idle mode.
Betting Phase - Once at least one player joins, the dealer starts the betting phase.
Dealing Phase - Dealer distributes two cards to each betting player and to themselves (one card hidden).
Evaluation Phase - Natural Blackjacks are detected; immediate payouts or pushes occur.
Player Turns - Each player acts within a fixed time window (hit/stand logic to be implemented).
Dealer Turn - Dealer reveals hidden card and plays according to house rules.
Resolution Phase - All hands are compared, results paid out, and the table resets for the next round.
Server Integration
The dealer depends on the BlackjackTable for data access and state synchronization:
This gives access to:
The
Shoefor card draws.The list of active
Seatobjects (each representing a player).The networked
TableStatefor synchronized updates.BlackjackRulesfor rule logic (viatable.Rules).
Communication with Clients
Mirror’s TargetRPC calls are used to send card information and reset events to players:
TargetAddCardToHand()– Adds a card to a specific player's hand.TargetAddCardToDealer()– Updates the client’s dealer hand view.TargetResetPlayer()– Resets a player’s state for the next round.
Cards are sent as network-safe Card structs; hidden cards are represented with
Suit.Hidden and Rank.None until they are revealed later.
Summary
The BlackjackDealer is the state machine and execution engine of the Blackjack game. By keeping all logic on the server, and using network-synced DTOs for communication, it guarantees fairness and scalability across multiplayer environments.
It is designed to be modular, expandable, and reusable for other dealer-based card games (like Baccarat or Three Card Poker), by following the same BaseTable and IDealer interfaces.
Last updated