This is an object that provides a simple way to do probability simulations and such. It comes with documentation and an example. I've spent all morning working on it, but I can't guarantee that there are no bugs left in it - if you find anything let me know.
http://notthecheatr.phatcode.net/downlo ... _AI_pm.zip
Coin-flipping Example:
Code: Select all
''
''
'' ntc.AI probability machine - coin-flipping example
''
''
#Include "ntc/pm.bas"
Using ntc.AI.pm
Randomize Timer
Dim As pmObject probMachine = pmObject()
'Store how many times heads or tails is chosen
Dim As uInteger ht (1 To 2)
'How many times to flip?
Dim As uInteger numFlips
'Add two choices, each with a 50% chance
probMachine.addChoice(0.5)
probMachine.addChoice(0.5)
'Find out how many times to flip the coin
Print "How many flips do you want?"
Input numFlips
'Flip that many times
For i As uInteger = 1 To numFlips
'We add 1 to the index because choose() returns 0 or 1.
ht(probMachine.choose() + 1) += 1
Next i
'How many times was each chosen?
Print "Heads: " + Str(ht(1))
Print "Tails: " + Str(ht(2))
'Experimental probability
Print Str(ht(1)/numFlips)
Print Str(ht(2)/numFlips)
Sleep