![]() Earlier this year, I was sitting in a B&B in Western Cuba with a group of friends.Įdit backups for advanced fixes and tweaks. With it being our first evening in the country, and jetlag really starting to kick in, we decided to play a quick card game then head to bed. After realising that none of us actually knew any card games (aside from Snap), I made one up. If the player gets the suit right at any point, then a new card is added to the table.They win if they guess any of the cards correctly The player tries to guess each card in order (both value and suit).The dealer lays 10 (or indeed a variable number of) cards face down on a table.Take a full deck of 52 cards and two people - a dealer and a player. (optional but interesting rule) The player cannot guess the same suit or card value twice in a row.If the player gets the value of the card right, 2 new cards are added. Simple right? I’ve named this game ‘Yakelin’ after the owner of the B&B we were staying in at the time. Give it a go - it’s surprisingly fun to play.Īs a statistician, a question popped straight into my head: what’s the probability of winning Yakelin? As always, there are two ways of starting with this question: approximate using a Monte Carlo simulation or try and evaluate analytically. In this post, I will talk through some of the details of the simulation solution I built and give a few tips for these kinds of problems*. The code is on GitHub: įor the simulation, I used a standard Monte Carlo approach. I won’t go into too much theory on Monte Carlo here, but this article gives a thorough and entertaining overview. ![]() We first need to decide what this game looks like in code form. It needs to be built in such a way that we can simulate playing it easily. We start with the basics - coding up what a card actually is and how a deck is created: class Card(object): def _init_(self, value, suit): self.value = value self.suit = suit def _str_(self): return str(self.value) + " of " + self.suit def _eq_(self,other): return self.value = other.value and self.suit = other.suit def _ne_(self, other): return self.value != other.value or self.suit != other.suit In addition, there are a lot of parameters we might want to play with (the number of cards on the table the number of cards you get as a reward for guessing the right suit or even the number of cards in the pack). This may sound trivial but, given cards are the essential building block of this game, it is essential that these are constructed with the right properties and functions. The equality function in particular will be important as this will be used throughout this game. We next need to consider the groups of cards which are important during the game.
0 Comments
Leave a Reply. |