# Phases

AC\_Blackjack is divided in phases. You can see them in the Even Graph

### 1 - init game

The game is initialized for the first time OR reset after a game is over (Y\_Money=0 at the end of a round), so all the widgets it needs are created and displayed on screen (if they don't exist yet). The InputModeGameAndUI can be changed to a better experience (if not, clicking in a non interatible widgets causes the mouse cursor to disappear.&#x20;

Then the You (player) money is updated and the second phase (Init round) in launched.

### 2 - Init round

Is called at the end of a round or with the  1 - Init phase.

The data and UI are reset (popup is cleared, bet and all points are set back to 0, drawnCards are cleared). A deck is created and shuffled. The Widget Switch in W\_main is set to index 0 so W\_selectBet is visible and the Betting phase can start.

### 3 - Betting phase

Can either placeBet or resetBet through the buttons of W\_selectBet. Then, when you hit 'confirm', it runs the 4st phase, initial Deal.&#x20;

### 4 - Initial Deal

Dealer and You draw cards which are then displayed on the UI. Dealer has one card face down (its value is not calculated in its points).&#x20;

The bet is substracted from the Y\_money and the UI switch to index 1 so that the bet pannel is hidden and the draw / stand button are now visible.&#x20;

The You hand is evaluated to check if he has a Blackjack right away. If so, skip the 5 - Action Player Phase (no need to draw cards) and go to the Dealer Phase. Otherwise, You can draw new cards and enter the phase 5.

### 5 - Action player phase

By cliking on "draw" in the UI, the You player draw a card, which is added to Y\_drawnCard, added in the UI, his hand is calculated and evaluated. If points >21,  the round is lost. If points =21, he cannot draw anymore and the AC will go to the next phase (6) to reveal and check Dealer's hand and check the winner.&#x20;

If < 21, the player You can draw another card and repeat all of this, or he can stand, which leads to phase 6.

### 6 - Dealer Phase

The face down card of the Dealer is revealed, and its value is added to his currentPoints.&#x20;

Then the AC checks if the player (You) has 2 cards and 21 points (which means he had a blackjack and came right away from phase 4. If so, check if Dealer has a Blackjack too, which would lead to a push. Otherwise, the player (You) wins and gain 1.5x the bet and a new round can start (call phase 2).

If none of those conditions are fulfilled, while the Dealer points < 17, the Dealer keeps drawing (with hand evaluation, ect..). As soon as he reaches 17 or higher with its last drawn card, the round stops and check if win / lose / push. The gains, if any, are then calculated.

On a player (You) lose, if his money = 0, then he lost the whole game and a new one starts over (go to phase 1).&#x20;

If he still has money, round is over, a new round starts, and go to phase 2.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://easy-blackjack.gitbook.io/easy_blackjack-docs/ac_blackjack-actor-component/phases.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
