Click here to Skip to main content
15,894,291 members

Card game simulation

woj123 asked:

Open original thread
I wrote a card game simulation for a very simple card game. The simulation runs the game multiple times and doesn't display output except for the number of wins, losses, and win %. I ran multiple simulations of millions, 10s of millions, and even 100 million games, which took several minutes. After more than 1 million games the win % tends to cluster around 1.62%. However, the mathematical win % should be 1.8316% which was confirmed by a professor of mathematics. So I should be winning 1 of every 500 games more than I am. I've checked my code over and over including what I believe to be a good use of the random number generator and the proper way to shuffle a deck of cards.

I'm wondering if someone would be willing to write their own procedure to simulate this game and see what they get for results?

The game goes like this. Shuffle the deck. Then one by one place each card face up and call out, in order, "ace" "two" "three" ... "jack" "queen" "king". Then repeat until the end of the deck. You win only if each card does not match the called out value. For example, if you get to the 5th card and it is a "5" you lose. If you get to the 28th card and it is a 2 you lose. So, obviously, you test using the mod operator % 13. I don't want to bias another solution with a post of code, but thought someone might be interested to try it themselves and, if closer to the mathematical expectation, compare code.
Tags: C# (C# 4.0)

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900