w0uter Posted May 22, 2005 Share Posted May 22, 2005 (edited) Made a diceroll func in java. Wonderd if it was harder in autoit. and it was SOOO easy. but i still decided to post it Func _DiceRoll($i_Dices = 1, $i_Sides = 6) ;check for valid numbers If Not IsInt($i_Dices) Or Not IsInt($i_Sides) Or Round($i_Dices) <> $i_Dices Or Round($i_Sides) <> $i_Sides Then SetError(1) Return 0 EndIf ;filter out technical impossibilitys If $i_Dices <= 0 Or $i_Sides <= 3 Then SetError(2) Return 0 EndIf ;add the buffer Local $i_rnd = 0 ;roll the dices and add em to the buffer For $i_count = 1 To $i_Dices $i_rnd += Random(1, $i_Sides, 1) Next ;return the buffer Return $i_rnd EndFunc;==>_DiceRoll Edited May 30, 2005 by w0uter My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
MSLx Fanboy Posted May 23, 2005 Share Posted May 23, 2005 Is there a reason why you multiply $i_Dices by 1 in the first argument in the Random() func Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate()) Link to comment Share on other sites More sharing options...
GaryFrost Posted May 23, 2005 Share Posted May 23, 2005 (edited) seemed useless to me $a_dice = _DiceRoll(2) $s_text = "" For $i = 1 To $a_dice[0] $s_text = $s_text & "Die #" & $i & ": " & $a_dice[$i] & @LF Next $s_text = $s_text & "Total: " & $a_dice[UBound($a_dice) - 1] MsgBox(0,"Rolled",$s_text) Func _DiceRoll($i_Dices = 1, $i_Sides = 6) Dim $a_dices[$i_Dices + 2], $i $a_dices[0] = $i_Dices For $i = 1 to $a_dices[0] $a_dices[$i] = Random(1, $i_Sides, 1) $a_dices[$i_Dices + 1] = $a_dices[$i_Dices + 1] + $a_dices[$i] Next Return $a_dices EndFunc Edited May 23, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
w0uter Posted May 23, 2005 Author Share Posted May 23, 2005 (edited) Is there a reason why you multiply $i_Dices by 1 in the first argument in the Random() func<{POST_SNAPBACK}>no not really. first it had 1. but then i added multiple dices. and forgot to remove the 1.ty for pointing that out Edited May 23, 2005 by w0uter My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
Smed Posted May 24, 2005 Share Posted May 24, 2005 gafrost corrected for it, but he didn't point out that yours will return each possible value with a linear probability rather than the nice bell curve you expect from rolling multiple dice. I.e. if you roll 2, 6-sided dice, you are more likely to get a 7 than a 2 or a 12. 601DisengageEnd Program Link to comment Share on other sites More sharing options...
GaryFrost Posted May 24, 2005 Share Posted May 24, 2005 (edited) took about 30 seconds to put the below together, probably need more items on the wheel, lower the chances, but see lots of potential for the function for making games like below, even the old game of yatzee dim $slots[7] $slots[1] = 'cherry' $slots[2] = 'bananna' $slots[3] = 'coin' $slots[4] = 'watermelon' $slots[5] = 'lemon' $slots[6] = 'Lucky 7' $a_dice = _DiceRoll(3) $s_text = "" For $i = 1 To $a_dice[0] $s_text = $s_text & "Slot #" & $i & ": " & $slots[$a_dice[$i]] & @LF Next MsgBox(0,"1 armed bandit",$s_text) Func _DiceRoll($i_Dices = 1, $i_Sides = 6) Dim $a_dices[$i_Dices + 2], $i $a_dices[0] = $i_Dices For $i = 1 to $a_dices[0] $a_dices[$i] = Random(1, $i_Sides, 1) $a_dices[$i_Dices + 1] = $a_dices[$i_Dices + 1] + $a_dices[$i] Next Return $a_dices EndFunc Edited May 24, 2005 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
w0uter Posted May 24, 2005 Author Share Posted May 24, 2005 (edited) gafrost corrected for it, but he didn't point out that yours will return each possible value with a linear probability rather than the nice bell curve you expect from rolling multiple dice. I.e. if you roll 2, 6-sided dice, you are more likely to get a 7 than a 2 or a 12.<{POST_SNAPBACK}>i think this is incorrect. since dices have the same chances for evry side. Edited May 24, 2005 by w0uter My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
/dev/null Posted May 24, 2005 Share Posted May 24, 2005 (edited) i think this is incorrect. since dices have the same chances for evry side.<{POST_SNAPBACK}>Nope, it is correct. Dices have the same chances if you throw them independently but not if you add the values of each dice, because then you have dependent probabilities.See the following numbers for a "visual" proof ;-))1+1 = 21+2 = 31+3 = 41+4 = 51+5 = 61+6 = 72+1 = 32+2 = 42+3 = 52+4 = 62+5 = 72+6 = 83+1 = 43+2 = 53+3 = 63+4 = 73+5 = 83+6 = 94+1 = 54+2 = 64+3 = 74+4 = 84+5 = 94+6 = 105+1 = 65+2 = 75+3 = 85+4 = 95+5 = 105+6 = 116+1 = 76+2 = 86+3 = 96+4 = 106+5 = 116+6 = 12value=2 : count= 1value=3 : count= 2value=4 : count= 3value=5 : count= 4value=6 : count= 5value=7 : count= 6value=8 : count= 5value=9 : count= 4value=10 : count= 3value=11 : count= 2value=12 : count= 1There are simply more combinations to get a 7 (6/36) than a 2 or 12 (1/36), so the chances to throw a seven are much higher.CheersKurt Edited May 24, 2005 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
MSLx Fanboy Posted May 25, 2005 Share Posted May 25, 2005 God bless Mutually-Exclusive probabilities. Hehe, just covered that a few weeks ago in PreCalc, I miss them now that we did limits of functions and such Writing AutoIt scripts since _DateAdd("d", -2, _NowCalcDate()) Link to comment Share on other sites More sharing options...
w0uter Posted May 26, 2005 Author Share Posted May 26, 2005 (edited) ahh i see /dev/null. ty. so this would be better ? (also added some checks) Func _DiceRoll($i_Dices = 1, $i_Sides = 6) ;check for valid numbers If Not IsInt($i_Dices) Or Not IsInt($i_Sides) Or Round($i_Dices) <> $i_Dices Or Round($i_Sides) <> $i_Sides Then SetError(1) Return 0 EndIf ;filter out technical impossibilitys If $i_Dices <= 0 Or $i_Sides <= 3 Then SetError(2) Return 0 EndIf ;add the buffer Local $i_rnd = 0 ;roll the dices and add em to the buffer For $i_count = 1 To $i_Dices $i_rnd += Random(1, $i_Sides, 1) Next ;return the buffer Return $i_rnd EndFunc ;==>_DiceRoll Edited May 26, 2005 by w0uter My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll Link to comment Share on other sites More sharing options...
/dev/null Posted May 26, 2005 Share Posted May 26, 2005 ahh i see /dev/null. ty.so this would be better ?Yes, running your func 10.000 times gives:value=2 count=259value=3 count=525value=4 count=834value=5 count=1138value=6 count=1443value=7 count=1671value=8 count=1323value=9 count=1134value=10 count=819value=11 count=530value=12 count=324See also the post of gafrost in this thread.CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now