What is it? It’s a little programme where the computer plays a little dice game called Tenzi. In the game, each player is given 10 dice, and you chose a number between one and six. In each turn, you roll your dice, and if you roll any with your chosen number, you get rid of those dice and use the remaining ones for the next turn. The person who gets rid of all their dice the fastest wins.
Of course here, the computer is playing by itself, but I wanted to see if I could code the computer to understand the game rules to see if my implementation of them worked or not. I’ll add the ability to make the game playable by humans by themselves later, and I’ll try making the game pretty after that.
I’ve included the link here, including the code with annotations. Just press the ‘Start’ button in the Result panel to watch it work. The code is probably very inefficient, and there’s likely a more optimised version of this someone else has made, but I think it’s good for a first shot.
EDIT: Whoops! I just realised that the rules I mentioned aren’t completely Tenzi. In the case of Tenzi, it doesn’t have to be a six, it can be the number of your choice. I’m sure next time round, I’ll code it so you can choose the number. No harm done.