Each game built using the Sunflower engine exposes an AI interface – basically a text file with all details of the ruleset necessary for a AI designer to design their AI for the game. Let’s see how it works, and reveal the AI interface for Hearts, the first game released for the engine.
An AI interface currerntly consists of three parts:
– Card zones the table is divided to: For each game, the cards are located in specific zones. Movement within a zone is never significant for the game rules (you can reorganize the cards in your hand as much as you want), but movement between zones is usually the main mechanic for playing cards. So you’ll need to know how each zone is called to move cards from your AI code.
– Phases the game is divided to: Almost all games have different things to do at different times – sometimes you need to draw a card and sometimes to play a card; Sometimes it’s your turn and sometimes your opponent’s; And so on. When your AI player is called, it needs to check which phase is currently played, and act accordingly.
– Global variables: General information about the state of the game. Might include things like players’ scores, various things that happened in previous phases and affect the current state, and whatever else.
Hearts AI Interface
In the future, the AI interface will be generated automatically and published in a standard format. We’re not quite there yet, so here’s the Hearts AI interface written manually:
Hand1, Hand2, Hand3, Hand4: Player hands.
Play1, Play2, Play3, Play4: Play zones. Each player, on their turn, plays a card by moving it from their hand to their play zone.
Discard1, Discard2, Discard3, Discard4: That’s where the cards go after you take a trick. You probably won’t need them for your AI.
FirstRoundFirstTurn, FirstRoundTurn, FirstTurn, Turn: The actual turns. It’s split in this way because there are slightly different rules for playing in the first round, and for the first turn per round.
Points1, Points2, Points3, Points4: The scores. Remember, in Hearts the lower score wins.
currentPlayerIndex: Number between 1-4, of the current player who’s supposed to play a card.
HeartsBroken: Not as dramatic as it sounds. It’s a boolean value saying whether or not hearts have already been played.