THKP

View Original

Beat Your Grandma at Cards - Chapter 5 - Euchre Phases

In the last chapter, we implemented the first bidding phase of the game. We got to see how the phases result feeds into changes to the GameState, which in turn leads to subsequent phases. In this chapter, we’ll implement the remaining phases and write the widgetry for displaying them.

Let’s add our remaining phases to the controller’s build method:

See this content in the original post

We also have a new set of widgets for rendering the current state of the game (i.e. how many tricks each team has and the current trump).

Next, we need to implement our callbacks for when the controller receives actions from players. We already implemented _onFirstRoundBidResult in the last chapter, let’s implement the rest now:

See this content in the original post

One unorthodox thing to call out here is the Timer wait. This is just so the UI doesn’t update too quickly, and a human player can get a better idea of what’s happening.

This is basically the entire EuchreGameController class. If you want to see it all in one place, check it out here.

Finally, we need our individual widgets for displaying each phase of the game. The second bidding round is almost as simple as the first, but we need a few extra buttons for each suit:

See this content in the original post

It looks like this:

Discard is dead simple:

See this content in the original post

Playing is the most complicated phase, as you might imagine, but even it’s not too bad. First, we need a widget to show the in-progress trick. I like to just show each card in front of the respective player, and if they haven’t played yet, we can show a blank card like this:

This trick widget will look something like this:

See this content in the original post

And once we have that, the play widget is relatively simple:

See this content in the original post

That’s it! That’s all the necessary widgets for the game flow. Now we can play a full game against the DerpAI:

Aaand, I just barely won. Against a completely randomized AI... No wonder my Grandma schooled me so easily. Anyway, tis no matter, because in our next chapter, we’ll discuss Perfect Information AIs, which will be able to utterly destroy the randomized AI.