# a magic 8 ball algorithm or doing cartomancy in small basic with a 90% edge pls correction • ### Question

• Here the monty hall explained:

So I was thinking if you could do that with cards so I tried.

Soon I realized playing with just 3 cards meant that most probably you would eleimnate your pick or the price so this is what I did:

I extended the option to 52 poker cards and the prizes to both red aces.

I pick after shufle the first 13 cards and start elminating cards till I get a red ace.

Now theres just one red ace left, thats the prize but there has been a change of variable so its in my interest to switch pick.

I did a program that studies this startegy and it gives you an edge as it should matematically.

http://smallbasic.com/program/?PZF902

so what error could it be here really i dont think that can be right

Thursday, February 2, 2017 9:37 PM

• Antonio glez,

Here's your program changed to what I think is right. In the subroutine "TestOnRandomness" it counts the wins. Also, I put a count to count the number of games played. Then print out the number of games, the number of wins and the percentage which should be 50%. Also,I commented out the else and -win in that routine.

JR

re:
shufle()
testonrandomness()
TextWindow.WriteLine("wins "+win+" Games "+Count+" Percentage "+Math.Round(win/Count*100))
Goto re

'this is to shufle 52 cards
sub shufle
i=1
deck=""
While i<53
reshufle:
card= Math.GetRandomNumber(52)
If Array.ContainsValue(deck,card) Then
Goto reshufle
EndIf
deck[i]=card
i=i+1
EndWhile
EndSub
' i test if theres a 1 among the first 26 cards that should be a 50% chance
Sub testonrandomness
count=count+1
For i=1 To 26
If deck[i]=1  Then
win=win+1
'Else
'win=win-1
EndIf
EndFor
EndSub

Saturday, February 4, 2017 10:49 PM
• with replacing goto statement with while-endwhile loop it look like this:

________________________________________________________________________________

' test for 2000 games stats, it gives 50% after 2000 ' scale of probalilty
' program CDC842

While games <> 2000
shufle()
testonrandomness()
TextWindow.WriteLine("wins "+win+" Games "+Count+" Percentage "+Math.Round(win/Count*100))
games=games+1
endwhile

'this is to shufle 52 cards
sub shufle
i=1
deck=""

While i<53
card= Math.GetRandomNumber(52)
double= Array.ContainsValue(deck,card)
While double = "false"
endwhile
deck[i]=card
i=i+1
EndWhile

EndSub
' i test if theres a 1 among the first 26 cards that should be a 50% chance
Sub testonrandomness
count=count+1
For i=1 To 26
If deck[i]=1  Then
win=win+1
'Else
'win=win-1
EndIf
EndFor
EndSub

Monday, February 6, 2017 1:40 PM

### All replies

• Hi !
Here is the output to the text.window screen,

it seems that the BOB figure always go +13

and edge start to 100 and steady decrease... a hint:

round the bob/x*100 value to 2 decimal like this:

___________________________________________________________________________

break2:

edge=math.Round((bob/x)*10000)/100
TextWindow.WriteLine("wins "+bob+" edge "+edge)

Goto rey

______________________________________________________________________

results: Thursday, February 2, 2017 10:09 PM
• thanks for the heads up, i corrected the rounding the edge part

also i realized that sometimes the dealers turns face up cards of the 13 picked and that shouldnt be like that, in that case that should be a null game

i corrected the code and now theres a 60 % edge but that can not be posible there has to be something wrong with the code, here it is:

code

edit:

i think the reason winning grow steady and suddenly drop in the beginning is because the writeline command only happens in the wiinnings so loses dont show up till theres a next win

Friday, February 3, 2017 6:11 PM
• Hi Antonio !

My suggestion:

Seems to me that it would be easier to understand this program by replacing a few goto by subroutines SUB connections.?

Friday, February 3, 2017 11:53 PM
• thanks that was a good idea, i narrowed the problem of my program to this:

i shufle 52 cards and check if the 1 is among the first 26 but seems theres something i did wrong, here the program :

program

Saturday, February 4, 2017 7:13 PM
• Antonio glez,

Here's your program changed to what I think is right. In the subroutine "TestOnRandomness" it counts the wins. Also, I put a count to count the number of games played. Then print out the number of games, the number of wins and the percentage which should be 50%. Also,I commented out the else and -win in that routine.

JR

re:
shufle()
testonrandomness()
TextWindow.WriteLine("wins "+win+" Games "+Count+" Percentage "+Math.Round(win/Count*100))
Goto re

'this is to shufle 52 cards
sub shufle
i=1
deck=""
While i<53
reshufle:
card= Math.GetRandomNumber(52)
If Array.ContainsValue(deck,card) Then
Goto reshufle
EndIf
deck[i]=card
i=i+1
EndWhile
EndSub
' i test if theres a 1 among the first 26 cards that should be a 50% chance
Sub testonrandomness
count=count+1
For i=1 To 26
If deck[i]=1  Then
win=win+1
'Else
'win=win-1
EndIf
EndFor
EndSub

Saturday, February 4, 2017 10:49 PM
• with replacing goto statement with while-endwhile loop it look like this:

________________________________________________________________________________

' test for 2000 games stats, it gives 50% after 2000 ' scale of probalilty
' program CDC842

While games <> 2000
shufle()
testonrandomness()
TextWindow.WriteLine("wins "+win+" Games "+Count+" Percentage "+Math.Round(win/Count*100))
games=games+1
endwhile

'this is to shufle 52 cards
sub shufle
i=1
deck=""

While i<53
card= Math.GetRandomNumber(52)
double= Array.ContainsValue(deck,card)
While double = "false"
endwhile
deck[i]=card
i=i+1
EndWhile

EndSub
' i test if theres a 1 among the first 26 cards that should be a 50% chance
Sub testonrandomness
count=count+1
For i=1 To 26
If deck[i]=1  Then
win=win+1
'Else
'win=win-1
EndIf
EndFor
EndSub

Monday, February 6, 2017 1:40 PM