Below The Deck

Godot 4.5 | C++ | GDScript

Image description

Overview

As the sole programmer, I worked on all the systems in the game, although most of my time was dedicated to setting up the card system and making the AI for the Dealer

AI

I decided to use a system similar to chess AI, where the dealer would simulate all the possible actions it could take, then evaluate each of them and choose the sequence that resulted in the best outcome.

Optimisation

One of the main issues I faced with this was optimization, as although we were only having the dealer look 1 turn into the future, the dealer has a large number of actions it can choose from and can take several actions per turn, increasing the number of possible turns exponentially. This meant it would often take several seconds to calculate its next move.

To combat this without compromising the dealer's intelligence too much, I split the dealer's turn into 4 phases, 1 for each type of move the dealer could take: Destroying cards, Playing cards, Flipping cards, and Swapping cards. This means the dealer will do all of its destroy actions, then all of its place actions, etc

Ordering the actions this way massively cuts down the number of branches to test, since the AI won’t check sequences that have the same actions in a different order, for example it won’t test [Place Slot 2 -> Destroy Slot 1 -> Flip Slot 3] or [Flip Slot 3 -> Place Slot 2 -> Destroy Slot 1], only [Destroy Slot 1 -> Place Slot 2 -> Flip Slot 3].

To further cut down on the number of sequences I also split each phase (excluding the swap phase) up by slot, so the dealer would do all the actions it could with slot 1, then all the actions it could with slot 2, etc. These changes combined made the dealer fast enough that there was no noticeable delay for it choosing its actions.

Image description