The equality function in particular will be important as this will be used throughout this game. 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. 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). It needs to be built in such a way that we can simulate playing it easily. Card game simulator code#We first need to decide what this game looks like in code form. I won’t go into too much theory on Monte Carlo here, but this article gives a thorough and entertaining overview. The code is on GitHub: įor the simulation, I used a standard Monte Carlo approach. 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*. 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. Simple right? I’ve named this game ‘Yakelin’ after the owner of the B&B we were staying in at the time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |