-
1 Attachment(s)
Plinko Board Program
I am designing a simple plinko game program. Basically I am stuck on exactly how to make this unfold. How to randomize the odds of where it hits(rand() % 2)???? and how to keep it going and the ending where they get cash. Here is a pic of how it works and here is my code below it so far.
Attachment 11986
Code:
#include <iostream>
using namespace std;
int main()
{
int choice;
int selection;
double user_winnings;
bool gameOn = true;
while (gameOn != false){
cout << "***PLINKO MENU***\n";
cout << " 1 - Drop one chip into one slot.\n";
cout << " 2 - Drop multiple chips into one slot.\n";
cout << " 3 - Exit.\n";
cout << " Enter your choice and press enter: ";
cin >> choice;
switch (choice)
{
case 1:
cout << "\n Which Slot would you like to Drop a chip in(Please enter a slot #0-8)?"<<"\n";
cin >> selection;
if((selection < 0) || (selection > 8))
{
break;
}
else ;
//simulation description
cout<<"You've won $" << "money" << "!" << endl;
break;
break;
case 2:
cout << "\n Which Slots would you like to Drop a chip in(Please enter a slot #1-9)?"<<"\n";
// rest of code here
break;
case 3:
cout << "End of Program.\n";
gameOn = false;
break;
default:
cout << "Not a Valid Choice. \n";
cout << "Choose again.\n";
cin >> choice;
break;
}
}
return 0;
}
-
Well first, I would suggest you read up on and start practising code organisation.
SourceForge.net: Indentation - cpwiki
Next, just look at two rows of your peg board. Once you understand how this works, you just repeat it 6 times.
Hint: this might make a good basis for a function within your code, which you call 6 times.
Another function would be one to call the above 6 times, and tell you what slot the coin actually ended up in.
-
but i dont understand how it works :)
-
Well if it starts in say column 3, then after passing two pegs, which columns is it likely to be in.
If each peg is unbiased, so it's 50% either way, then it should be
25% in column 2
50% in column 3
25% in column 4
-
There was a contest with a similar theme here - check out the entries for hints on what to do
-
I built a plinko board simulation for my computer modelling class. You should look for a pattern in the pegs. Notice how the paths a ball can move through alternate b/t 8 and 9 choices to traverse (using the provided pic). I had to test different board widths and height and the point of the Plink board was that the balls will follow a normal distribution so a bell curve where most balls will fall into the middle slots below. So you need some loop to know how tall the board is and when to alternate b/t the total pegs it can land ont during each traversal down the board.
EDIT: Actually, I built the Galton board which follows the bell curve (it uses a triangle of pegs), but Plinko is similar so you can look it up to get an idea. Here's a neat app online using Flash that let's you test around (Galton board also called the Quincunx, i know it sounds funny)
http://www.mathsisfun.com/data/quincunx.html