samerv.in

Home Blog Resume


Creating an AI for playing Dice Forge solo

Creating an AI for playing Dice Forge solo

I'm a big fan of Dice Forge. It's a board game where you can customize all six faces of your two dice in a quest to buy cards and score points over 9 or 10 rounds. The soul of the game is similar to some other games I like: Dice Forge allows you to develop long-term strategies, but requires you to react tactically to chance. It's pretty easy to teach new players. As a bonus, since everyone rolls their dice on everyone's turn, there isn't a lot of downtime.

I play some other dice games solo in my spare time. Dice City comes to mind as a game with many similarities, but others like Roll Player and VivaJava have seen solo play as well. There's no official solo mode for Dice Forge, though. What am I to do?

Well, the first place I went was the BoardGameGeek forums. There's a section dedicated to variants, which was a great place to gather ideas. I found that there were two general categories of solo rules: Score Attack, where you played alone and tried to maximize your score; and AI, where some set of rules guided an AI to emulate a real player.

Playing without any semblance of interaction didn't feel right, though. I also wasn't satisfied with the existing AI rulesets. They were too complicated or required resources outside the game, like a deck of cards with decisions on them. I wanted the rules to be able to fit on an index card.

So I sat down and made up this ruleset. Read the short version to see what it does, then check out the result of my first game against it. I go into more details and explain my thoughts at the bottom.


Short AI rules

The first written version of these rules was a little on the long side. It also didn't put everything in order of importance. So I wrote this quick version to make it more digestible for someone not in my own head. Enjoy.

Set up

Set up the game using the two-player rules. You take the first turn. Use the following stacks of cards:

Round-by-round rules

On the AI's turn, if it is...

Round 1, 2, or 3:

Prioritize sun > moon > gold > points.

If the AI has 8 or more gold, forge the most expensive die face(s) it can afford. Follow its resource priority.

Otherwise, buy the first card from the following list that it can afford:

Round 4, 5, or 6:

Prioritize sun > moon > points > gold.

Buy the first card from the following list that it can afford:

Otherwise, with 8 or more gold, forge the most expensive die face(s) it can afford. Follow its resource priority.

Otherwise, buy the first card from the following list that it can afford:

Otherwise, fall back to Round 1 rules.

Round 7, 8, or 9:

Prioritize points > sun > moon > gold.

Buy the first card from the following list that it can afford:

Otherwise, with 8 or more gold, forge the most expensive die face(s) it can afford that grants points.

Otherwise, buy the first card from the following list that it can afford:

Otherwise, fall back to Round 1 rules.

Other general rules

When forging a die face, randomly determine which 1-gold face to replace. If there are none left, choose the smallest remaining gold die face.

When rolling a minor blessing, choose a die at random. Optionally, it may choose the "best" die, avoiding Boar or x3 faces.

If the AI has a Hammer or an Elder, always use it if possible.

If the AI has 2 sun left over after choosing an action, it always spends it to take another action if possible.

If the AI needs to make a choice (for example, choosing a resource from a Boar roll), it chooses in resource priority order. Optionally, it may avoid options that are not efficient, e.g. not taking 3 gold if it already has 12.


Result of the first attempt

So how did it go?

Well, pretty well! The AI ended up forging only 5 die faces: two 1-sun faces, a 2-sun face, a x3 face, and the combination gold + point + sun + moon face. It managed to buy two Hydras and two Sphinxes with the help of the x3 face, and even kept an Elder running.

I went for a more esoteric strategy. I forged 6 different die faces with some kind of points on them and generally bought cheaper cards. I ended up with a little too much gold towards the end of the game and only two Cancers, but I still went into the last round with a huge number of points.

I expected to trounce the AI. It wasted several rolls by overstocking itself with sun die faces. It wasn't efficient in moving around the board and didn't care if it ousted me.

I didn't trounce the AI. I lost.

It was close. The AI's 140 to my 136. Still. I lost to a dumb robot.

I guess I know what strategy I'm using the next time I play.


Full AI rules

Here's the full explanation of all the unwritten rules I ignored or didn't fully explain above. They'd be useful if you were programming a Dice Forge AI to play how I wanted it to play, but they're not always ideal for learning. I also go into details on some of the decisions I made.

Cards chosen

In most cases here, I chose the simpler card, or the card that an AI would have a harder time misusing. I also record a short explanation of what each card does for reference.

Here's the moon-cost cards. If I didn't list an alternative, there isn't one in the box, and so every game uses it.

And here's the sun-cost cards.

Oh, and the end-row card.

AI rules that always apply

These are a bit more descriptive than I originally wrote. I codified some of the assumed interactions I encountered when I was playing. The gist of the rules is that the AI doesn't do anything wasteful if it can help it, whether that's buying cards it doesn't need or taking resources it can't hold. If you play using these rules, feel free to shorten or improv the edge cases.

Examples of resource priority or priority order appear below in the Round-by-round rules. It's an ordering of sun, moon, gold, and points that's specific to the round.

Unless otherwise listed, play as a normal 2-player game. The AI should go second, so it can use all the resources it accumulates. You can make all decisions on your turn independently of the AI. For the record, I don't remove die faces or cards from the board during setup, even when playing with 2 people. I think this actually benefits the AI, as it can pursue big cards more easily.

When forging a die face:

The 2-point starting face isn't bad for the AI for slowly accumulating points, so it doesn't replace it.

When rolling a minor blessing:

Essentially, choose the die that's least likely to whiff or help the opponent.

Card-specific rules:

The AI shouldn't waste early turns buying several Chests, nor should it try to split its gold into many cards.

Other rules:

Addendum: Potential changes

I didn't include any of these options in my original draft because I wanted to know how well the AI would do with simple rules. Frankly, I'm not in a hurry to implement any of these until I've got my confidence back. Anyway. Here's some ideas to change up the AI for when I step my game up:

← Adding The Long Night to Dead of Winter Blog home


email