 I'm David Turner, and this is Om Nam Nash. I'm going to be telling you about a board game called Om Nam Nam and how I wrote an AI to solve it. So first, I have to tell you how to play the board game. So you've got a board that looks like this. It's got nine sections, and this tells you that cats eat mice and mice eat cheese, and wolves eat rabbits, and rabbits eat carrots, and hedgehogs eat frogs. I looked this up. This is actually true. Hedgehogs eat frogs, and frogs eat flies. And then you roll some dice, and the dice are only on the bottom two-thirds of the board, and they tell you what resources are going to be available to eat during the game, in addition to your opponent's cards. So here the green player has played a cat card, and the red and blue players unfortunately have played mouse cards. So they're going to get zero points, because mice are going to get eaten before they can do anything. But the cats can get four points, the green player, one for surviving, two for the two player's mice, and one for the mice on the die. So everyone's just going to play their cards simultaneously and then reveal them. That's how Om Nam Nam is played. So now we have to discuss game theory, which is how we're going to solve this. So you've probably all played this game with the rock and the paper and the scissors, and let's just break this down a little so that it's easier to read. So here we see that a column player has played rock, and the row player has played scissors, and the rock player is going to win, and the scissors player is going to lose. But I guess since game theory is a branch of mathematics, we probably have to use numbers instead of win and lose. So we'll call a win two, a lost one, zero, sorry, and a tie one. And then so this is the whole matrix with the numbers in it. And in this sort of game there are two kinds of strategies. There's pure strategies and there's mixed strategies. You're familiar with the pure strategies. Those are the ones where you just choose one thing and you always go with it. And then there's the mixed strategies, which are in this particular case how you actually want to play. You have some percentage of each of the options. And so we all know when we're actually playing rock, paper, scissors that we do not choose the good old rock strategy. And the reason behind this is this thing called the Nash Equilibrium. And a Nash Equilibrium is a situation where no one can do better by unilaterally changing strategies. So if you're playing the always-choose-rock strategy and I'm playing the mixed strategy, we are not in a Nash Equilibrium because I can do better by choosing the always-choose-paper strategy. But if we're both in that even, you know, one-third, one-third, one-third strategy, then there's no need to switch strategies. None of us can do any better. This is it. So let's look at an example from Amna Anam and see how we can have a Nash Equilibrium. So this is a board where there's just a couple of pieces of cheese on the bottom, but actually they're red cheeses, so there's four points worth of cheese. And so I've got a mouse and a cat and you've got a mouse and a cat. And this is what our payoff matrix looks like. If we both play our cats, our cats are going to bounce and we're going to get one point because our cats survive. If we both play mice, we'll get three points because we'll split up this four points worth of cheese between us plus the one for our mice surviving. If you play a cat and I play a mouse, then I'm in trouble and so on vice versa. So we're in here as the equilibrium between these cats and these mice. So one option is we can both play cats and one option is we can both play mice. Maybe there's some middle thing. And it turns out that actually all three are equilibria. So if we're both playing cats, I have no reason to ever splash in a mouse because my mouse is just going to get eaten. And interestingly, if we're both playing mice, I have no reason to put in a cat because I'll get the two points for eating your thing but I could get the three points for having the cheese. But something is not quite right here. And that is that in a two player Amna Anam, any point that you get is a point I didn't get. Me getting a point is, you know, I'd be just as happy if you lost the point. And if we both get a point, I'm indifferent, right? So what? My goal is to beat you. So here's what the actual path matrix looks like with the zero sum game thing. But something is still not quite right because Amna Anam is actually multi-round. After you've played your first card from your hand, you evaluate that, you put it aside, then you play the next card from your hand and so on until you're out of cards in your hand. So your actual score is whatever it is for this round plus the rest of the game. And in this case, if my cat eats your mouse this turn, then all I've got is a mouse left and you only got the cat left so your cats can eat my mouse and so the zero. So it's not always this boring in answer to the question. There actually is some interest to the game, right? So let's consider a slightly different situation here. So here there's just one mouse die that's been rolled and you've got a cat and a wolf and I've got a cat and a mouse. And now I'm in trouble, right? Because your cat can eat my mouse but my mouse can't eat your wolf and so it's sort of a bad scene for me. And so I think on average where I play this perfectly, I can get negative three-quarters of a point. You're going to get positive three-quarters of a point. And this turns out to be the equilibrium. Mostly I want to play the cat first and first because once the mouse gets eaten off the board that's the end of it. So let's just splash in the mouse first occasionally just to keep you honest. And so let's talk about how we can do this sort of search to find out what our good strategy is. And first let's look at sort of the size of the problem, right? So on the first play there are these 36... I'm going to call them game states but possible plays, right? I have six cards in my hand from the top six rows of this board. You have six cards in your hand and we have these combinations between them. And then for the second one we have 25 because we've got five cards left and so on. And so if we add this up, our total state space, right, we've got one, we've got the initial state of the game, right? Plus our 36 possibilities for the second one. But then there's the 36 possibilities times the 25 possibilities for the third one, right? And so it actually gets pretty large here. There's like 600 and something thousand of them. Which... So computing the Nash equilibrium itself is outside the scope of this talk and it's kind of difficult. And so for at least my Python program it takes a couple of minutes to evaluate which is not like great if you're trying to actually play this thing. So we want to figure out how to reduce this state space somewhat. And so one way we can do it is by player symmetry. So if we evaluate the situation where I've played a cat and you've played a mouse, we don't need to evaluate the situation where you've played a cat and I've played a mouse, everything else being held equal, right? Because we already have the results and we can just flip them. And that actually reduces our state space a lot. But we can do better. So just simple memoization. So if we just keep track, say, okay, so in the past after some number of plays the board looked like this and your hand looked like that and my hand looked like that. Then next time we're in that same situation which can happen, then we can just use our result that we computed last time. And you'll notice that we have a little tilde here. It's about 14,000. This depends on the exact layout of the board, right? Because if... how many possible distinct states there are depends on how many dice get rolled. If there's just no flies, right, that reduces the number of possible states and increases the value of our memoization. But we can actually do better than that, right? If we take our memoization with player symmetry. So now we remember the situation when you had the cat and I had the mouse, right? Now if we just swap those two. But the really cool thing is we can actually save a little bit more, right? By using these equivalence classes. So you'll notice that the three columns of the board are more or less the same. And so if we use our keys by canonicalizing cleverly the game state to instead of talking about cats and mice, talking about in general there is some predator, right? And there are three instances of its prey available and six instances of its meta-prey, right? With taking into account everyone's cards in their hands and the state of the board, we can knock another like 1,000-ish states off, which gets us down to like a few seconds. And that's I think fast enough to keep us from ever having to play this game. So unfortunately there are a few problems with this AI. So in game theory in general your goal is to get the highest score. And usually this is a good thing, right? Game theorists are happy if you win so long as I win too. But for a game it's your own sum. Again I want to win. And so sometimes there's a case where like what you can do is you can get a solid four every time, right? But there's another option where you can get seven sometimes but most of the time you're going to get zero. And so this is less good than the four all the time unless you're six points down, in which case you really got to throw that Hail Mary pass. And unfortunately our AI is not going to find the Hail Mary. And so how much time do I have left? Two minutes, great. So since I have an extra two minutes, oh my god, right. I can go into a little digression here. So imagine rock, paper, scissors, right? But rock pays out double when you win so instead of paying out two points I guess it pays out three points, right? So that's the points over the tie, right? So you end up in this sort of funny situation, right? Where you want to play rock most of the time but you don't want to play it all the time because you play it all the time. I'm just going to play paper all the time. And it turns out this is one of the things that I was using to test out my AI. So whenever anyone offers to play this game with you for money now you know what you're supposed to do. And since I do have another couple of minutes so if we look at this situation that we had back in the original slide, right? Where we had this set of dice which turns out to contain no rabbits and no... It does contain... Yeah, sorry, it contains no rabbits and it contains no carrots. So 10% of the time in this situation you want to play a rabbit first you know, well, the opponent's probably not going to play a wolf so it'll probably survive so I'll just get that free one point and have my rabbit safe. You never want to play a wolf first. You could say, well maybe I've got that 10% chance of catching their rabbit. Yeah, you do. But instead you could play like a frog first, eat the flies and have your frog be safe from the hedgehog later. So this computation actually comes out with some really cool results and unfortunately I lost the slide for that but that is the... That is Om Nam Nash. Thank you. And a special thank you from Semaphore. You can follow her on Twitter along with her brother Mutex at Big Fluth.