pharaun / alldice

Restful interface to a dice expression eval and generator.
Apache License 2.0
0 stars 1 forks source link

Convert the dice to stop returning Integer and return a Typeclass/probability instead. #24

Open pharaun opened 10 years ago

pharaun commented 10 years ago

Right now it is returning a Integer in the range of 1 and N as defined by randInt.

Now here's the idea. we want to also be able to compute the probability of a dice roll right. Replace the Integer returned by randInt with a type-class that implements the majority of what a Integer can do.

Then create a "probability" implementation of these typeclasses for probability, so that for ex (randProb 6) would emit a probability of (1/6, 1/6, 1/6 for 1-6) then each time its summed or what so ever, it will compute the new probability.

The main sticky point is how to deal with branching point, such as IF, may just want to make sure the program execute all possible branches upto some reasonable depth limits and terminate.

Also another issue is how to deal with for example raw integer, IE +6. One solution could be to have these shift the probability around from say 1-6 to 7-12 for ex.

I am not sure how scalable this solution is, the main issue would be having to head down each branch and determine their probability.... and the issue of termination. But I suspect we can just have it terminate past a certain number of iteration down a branch or have it be bounded by a timeout.

The other approach would be to do a monte-carlo approach and just repeat it thousands of time to build up the probability of the result.