Saturday, December 1, 2012

Zombie AI

Today my issue of Coder Weekly arrived, and one article got my attention straight away - Programming AI Bots for Zombie Dice. Zombies, dice, AI, and Python, what's not to like?

The article is about a fairly simple dice game, and an AI framework that has been built around it. The challenge is to come up with a bot written in Python that can beat random rolls and some other pre-built bots. I needed a bit of Python practice, so being the person that I am, I thought this would be a great way to spend a Saturday afternoon.

The game involves rolling a collection of 13 dice, of 3 different colours, which have different amounts of 3 different icons on their faces. I hate probabilities, so when I saw these relatively small numbers I immediately started thinking of a brute force way to solve the problem. You could easily calculate the different possible combinations of colours of dice that would come out of a roll, and using those combinations, you could calculate the probability of all permutations of the faces for those colours. Once that was all calculated, you could use those probabilities to work out the chance that the next roll will be a good one or not.

So that's what I did! Unfortunately the results were ... underwhelming, even after trying several different settings for the acceptable amount of risk vs the reward. One improvement I thought of was that if the bot was winning the game then it should play more conservatively, and if it was losing then it might as well play a little riskier. The results were still not spectacular, but after a lot more tweaking of configuration I managed to get results almost as good as the other bots.

I'm sure there is a sweet spot with the configuration that I could find in some scientific way, but that is the boring part of science so I'm happy to call it a day. That is my story for today, and here is the code.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.