First, try running the game below. You should be able to see the code in action. Try playing the game, then review the code. Surprise! We actually finished the program for you. Still, make sure you read it closely to understand how it works.

from poker import deal, dealer_plays, score_hand, hand_to_string, sort_hand
from drafter import *
from dataclasses import dataclass

@dataclass
class State:
    hand: list[int]
    dealer_hand: list[int]
    score: int


def decide_game(state: State) -> str:
    if not dealer_plays(state.dealer_hand):
        state.score += 10
        dealer_action = "folded"
    elif score_hand(sort_hand(state.dealer_hand)) < score_hand(sort_hand(state.hand)):
        state.score += 20
        dealer_action = "lost"
    else:
        state.score += -20
        dealer_action = "won"
    return dealer_action


@route
def index(state: State):
    state.hand = deal()
    state.dealer_hand = deal()
    return Page(
        state,
        [
            Header("New round!"),
            "Your score: " + str(state.score),
            "Your hand: " + hand_to_string(state.hand),
            Button("Fold", fold),
            Button("Play", play),
        ],
    )


@route
def fold(state: State):
    state.score -= 10
    return Page(
        state,
        [
            Header("You folded!"),
            "You lost 10 points. Your score is now " + str(state.score),
            Button("Start new game", index),
        ],
    )


@route
def play(state: State):
    dealer_action = decide_game(state)
    return Page(
        state,
        [
            Header("Dealer " + dealer_action + "!"),
            "Your hand: " + hand_to_string(state.hand),
            "The dealer's hand: " + hand_to_string(state.dealer_hand),
            "The dealer " + dealer_action + " and your score is now " + str(state.score) + " points.",
            Button("Start new game", index),
        ],
    )


start_server(State([], [], 0))

This version imports deal, dealer_plays, score_hand, hand_to_string and sort_hand from a poker module, the same functions you wrote in the earlier lessons. The State keeps track of the player’s hand, the dealer’s hand, and the running score. Each round, index deals two fresh hands and shows the player’s hand with a choice to fold or play; folding costs 10 points, and playing calls decide_game, which sorts both hands, scores them, and awards or subtracts points depending on whether the dealer folds, loses to, or beats the player.

Drafter is not installed on Dodona, so there is no exercise to submit here: this page is for reading and studying the code, not for running it.