Estimating probability of a score (Pig) C++ -


(i'm using c++, sorry!)

i need simulate single turn of game of pig. user defines "hold" value, , dice rolled until value met/passed, or until 1 rolled, sets score 0 , ends turn.

there value, turnnum, if will, decide how many times turn simulated holdnum.

where i'm running wall needs output score of each attempt, estimated probability, probability adding 1.000000 (100%).

for example: if hold value 21, , number of times ran turn simulation 4, results may like:

score/estimated probability:

0/.500000

21/.250000

22/.250000

23/.000000

24/.000000

25/.000000

26/.000000

which mean our simulation hit 0 twice, 21 once, , 22 once.

i have of code need (the singleturn function, function simulates dice), have no idea how make "remember" every time got specific score can incremented can divide number of turn simulations number probability.

not asking code written me, poke in right direction. can post other functions if necessary.

depending on language answer vary. i'll assume you're using c++ or java or similar language has needed types.

option a

generally in case use dynamic array store of scores, can go through array , tally need @ end.

to make super easy use standard sort routine , sort array according size, can number of each of values.

option b

another solution use map or dictionary type maps particular value value, in case map score count increment each time score.

something (c++)

map<int,int> mymap; //creating std::map mymap[thescore]++; //incrementing score variable 

you have tons of different options!


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -