Thread Rating:

7up
7up
  • Threads: 3
  • Posts: 39
Joined: May 22, 2010
May 22nd, 2010 at 2:59:02 AM permalink
How to do combinational analysis faster
To calculate baccarat combinations, if listing all six cards from 0 to 9, there are 1000000 steps.
Cutting down some repeating first two cards, there are still 302500 steps in my program.
Any way to simplify the process? Any formula?
Thanks in advance.
miplet
miplet
  • Threads: 5
  • Posts: 2146
Joined: Dec 1, 2009
May 22nd, 2010 at 7:55:32 AM permalink
Quote: 7up

How to do combinational analysis faster
To calculate baccarat combinations, if listing all six cards from 0 to 9, there are 1000000 steps.
Cutting down some repeating first two cards, there are still 302500 steps in my program.
Any way to simplify the process? Any formula?
Thanks in advance.


What info do you need in your combo analyzer? Just ways for banker, player and tie to win ? Or more detail, like given the first card is a two, what outcomes are posible? Do you need the exact final score? How many cards are used?
“Man Babes” #AxelFabulous
JB
Administrator
JB
  • Threads: 334
  • Posts: 2089
Joined: Oct 14, 2009
May 22nd, 2010 at 8:30:58 AM permalink
I think the 10^6 = 1,000,000 shortcut (using weight factors) is the fastest method. It takes less than a second to analyze on a typical computer.
7up
7up
  • Threads: 3
  • Posts: 39
Joined: May 22, 2010
May 22nd, 2010 at 10:15:07 AM permalink
Quote: miplet

What info do you need in your combo analyzer? Just ways for banker, player and tie to win ? Or more detail, like given the first card is a two, what outcomes are posible? Do you need the exact final score? How many cards are used?


Quote: JB

I think the 10^6 = 1,000,000 shortcut (using weight factors) is the fastest method. It takes less than a second to analyze on a typical computer.


I'vd got all those results, just wonder if there is any better way to do the cal faster.
It takes me 0.5 seconds to go through the 1 million steps for some simple addings for my computer, but it takes 6.8 seconds to find out banker/player/tie to win for those 1 milion steps. For the 302500 steps method, it still takes 2.3 seconds.
So I think there shoud be some better programming techniques.
JB
Administrator
JB
  • Threads: 334
  • Posts: 2089
Joined: Oct 14, 2009
May 22nd, 2010 at 11:43:45 AM permalink
Quote: 7up

I'vd got all those results, just wonder if there is any better way to do the cal faster.
It takes me 0.5 seconds to go through the 1 million steps for some simple addings for my computer, but it takes 6.8 seconds to find out banker/player/tie to win for those 1 milion steps. For the 302500 steps method, it still takes 2.3 seconds.
So I think there shoud be some better programming techniques.



The bottleneck must be in your code which determines the outcome. If you post your code, I can help you speed it up. What language is it in?
7up
7up
  • Threads: 3
  • Posts: 39
Joined: May 22, 2010
May 22nd, 2010 at 1:16:11 PM permalink
Quote: JB

The bottleneck must be in your code which determines the outcome. If you post your code, I can help you speed it up. What language is it in?


I use the ancient FoxPro 2.6, not too hard to read them.


CLEAR
DIMENSION face(10)
STORE 0 TO bwin,pwin,twin
sec0=SECONDS()
*8 decks each mask 32 cards
FOR i=1 TO 9
face(i)=32
ENDFOR
face(10)=32*4

*all combinations
FOR a=1 TO 10
p1=face(a)
face(a)=face(a)-1
FOR c=1 TO 10
p2=face(c)
face(c)=face(c)-1
FOR b=1 TO 10
b1=face(b)
face(b)=face(b)-1
FOR d=1 TO 10
b2=face(d)
face(d)=face(d)-1
FOR e=1 TO 10
h5=face(e)
face(e)=face(e)-1
FOR f=1 TO 10
h6=face(f)
DO whowin300 &&find out banker/player/tie win
NEXT
face(e)=face(e)+1
NEXT
face(d)=face(d)+1
NEXT
face(b)=face(b)+1
NEXT
face(c)=face(c)+1
NEXT
face(a)=face(a)+1
NEXT

*display results
? STR(bwin/(bwin+pwin+twin),10,7),'Banker win'
? STR(pwin/(bwin+pwin+twin),10,7),'Player win'
? STR(twin/(bwin+pwin+twin),10,7),'Tie win'
?
? bwin,'Banker win'
? pwin,'Player win'
? twin,'Tie win'
? SECONDS()-sec0,'seconds'
RETURN && end of program
******

PROCEDURE whowin300 &&find out banker/player/tie win
phand12=MOD(a+c,10) &&-total of player's first 2 cards
bhand12=MOD(b+d,10) &&-total of banker's first 2 cards

*whether hit the fifth or sixth card
DO CASE
CASE phand12>7 OR bhand12>7
*anyhit='22'
phand123=MOD(a+c,10) &&_two card for player, two card for banker
bhand123=MOD(b+d,10)
CASE BETWEEN(phand12,6,7) AND BETWEEN(bhand12,6,7)
*anyhit='22'
phand123=MOD(a+c,10)
bhand123=MOD(b+d,10)
CASE BETWEEN(phand12,6,7) AND bhand12<6
*anyhit='23'
phand123=MOD(a+c,10)
bhand123=MOD(b+d+f,10)
CASE phand12<6 AND bhand12<3
*anyhit='33'
phand123=MOD(a+c+e,10)
bhand123=MOD(b+d+f,10)
CASE phand12<6 AND bhand12=3 AND e#8
*anyhit='33'
phand123=MOD(a+c+e,10)
bhand123=MOD(b+d+f,10)
CASE phand12<6 AND bhand12=4 AND BETWEEN(e,2,7)
*anyhit='33'
phand123=MOD(a+c+e,10)
bhand123=MOD(b+d+f,10)
CASE phand12<6 AND bhand12=5 AND BETWEEN(e,4,7)
*anyhit='33'
phand123=MOD(a+c+e,10)
bhand123=MOD(b+d+f,10)
CASE phand12<6 AND bhand12=6 AND BETWEEN(e,6,7)
*anyhit='33'
phand123=MOD(a+c+e,10)
bhand123=MOD(b+d+f,10)
OTHERWISE
*anyhit='32'
phand123=MOD(a+c+e,10)
bhand123=MOD(b+d,10)
ENDCASE

*add up to banker/player/tie
DO CASE
CASE bhand123>phand123
bwin=bwin+p1*p2*b1*b2*h5*h6
CASE phand123>bhand123
pwin=pwin+p1*p2*b1*b2*h5*h6
CASE phand123=bhand123
twin=twin+p1*p2*b1*b2*h5*h6
ENDCASE
RETURN
***
7up
7up
  • Threads: 3
  • Posts: 39
Joined: May 22, 2010
May 22nd, 2010 at 1:19:32 PM permalink
Oops! All the tabs gone.
JB
Administrator
JB
  • Threads: 334
  • Posts: 2089
Joined: Oct 14, 2009
May 22nd, 2010 at 1:21:57 PM permalink
Quote: 7up

Oops! All the tabs gone.


You can surround it with [code] and [/code] tags to preserve formatting. I inserted the tags into your post.

Okay, my first suggestion is to use an array for determining whether or not the banker should hit. Make it a 2-dimensional boolean array, where one dimension is the banker's total, and the other is the player's third card. Populate this array before entering any loops. Then, when you are in the loop and need to determine whether the banker should hit, just retrieve the boolean value from the appropriate location in the array.

All of the calls to the function are going to hinder performance too. I don't think you even need a function to determine the outcome. Just total the player's hand as soon as his first 2 cards are known, and do the same with the banker. Then determine whether the player takes an extra card or not. If he does, start the fifth loop and recompute his total; and inside that loop, use the array to determine whether the banker takes a third card too, and if so, deal each possible card to him and recompute his total.

You should be able to avoid running several unnecessary loops by not dealing a third card to the player and/or banker if either or both of them are supposed to stand. When dealing with multiple loops like that, you want try to do whatever you can soon as it is possible to do so. That is, don't deal the third card to each and then later decide whether or not they needed it; decide first and deal the cards only when necessary.
7up
7up
  • Threads: 3
  • Posts: 39
Joined: May 22, 2010
May 22nd, 2010 at 2:08:15 PM permalink
Thank you so much, JB!
Have to take some time to digest it and try on it.
7up
7up
  • Threads: 3
  • Posts: 39
Joined: May 22, 2010
May 23rd, 2010 at 5:08:11 AM permalink
Now the time drops to 0.31 seconds.
Thanks again!
maglex96
maglex96
  • Threads: 0
  • Posts: 2
Joined: Apr 26, 2017
April 26th, 2017 at 3:13:26 AM permalink
Dear 7UP

Did you post your revised code that dropped the calculation time down to 0.31. If not could you post it so I could try and use it.

Thanks
gordonm888
Administrator
gordonm888
  • Threads: 61
  • Posts: 5374
Joined: Feb 18, 2015
Thanked by
LuckyPhowMission146
April 26th, 2017 at 9:16:35 AM permalink
Not only is there a lot of specialized expertise among the WOV forum crowd, but I'm beginning to appreciate how knowledgeable the admins are as well (specifically Babs, Mission and JB in addition to Wiz). Its actually damn impressive.
So many better men, a few of them friends, are dead. And a thousand thousand slimy things live on, and so do I.
QFIT
QFIT
  • Threads: 1
  • Posts: 315
Joined: Feb 12, 2010
April 26th, 2017 at 2:26:24 PM permalink
I threw together a variation using as many of your variables as I could in Basic that runs in one-thousandth of a second on my PC. It's in floating point and should be faster in integer.


Dim j, btt, ptt As Double, face(10) As Double, p1 As Double, p2 As Double, b1 As Double, b2 As Double, h5 As Double, h6 As Double, a, b, c, d, e, f, bwin As Double, twin As Double, pwin As Double, sec0 As Single, i, pt, bt, xx

sec0 = Timer
bwin = 0: twin = 0: pwin = 0
For i = 1 To 9
face(i) = 32
Next
face(0) = 32 * 4


For a = 0 To 9
p1 = face(a)
face(a) = face(a) - 1
For c = 0 To 9
p2 = face(c)
face(c) = face(c) - 1
For b = 0 To 9
b1 = face(b)
face(b) = face(b) - 1
For d = 0 To 9
b2 = face(d)
face(d) = face(d) - 1
ptt = p1 * p2 * b1 * b2
pt = a + c
bt = b + d
If pt > 9 Then pt = pt - 10
If bt > 9 Then bt = bt - 10
btt = bt
If pt > 7 Or bt > 7 Then
If bt > pt Then
bwin = bwin + ptt * 169332
ElseIf pt > bt Then
pwin = pwin + ptt * 169332
Else
twin = twin + ptt * 169332
End If
Else
If pt < 6 Then
pt = a + c
If pt > 9 Then pt = pt - 10
For e = 0 To 9
h5 = face(e)
face(e) = face(e) - 1
If pt > 9 Then pt = pt - 10

If e < 2 Then
xx = 4
ElseIf e < 4 Then
xx = 5
ElseIf e < 6 Then
xx = 6
ElseIf e < 8 Then
xx = 7
ElseIf e = 8 Then
xx = 3
Else
xx = 4
End If

If bt >= xx Then
If bt > pt Then
bwin = bwin + ptt * h5 * 411
ElseIf pt > bt Then
pwin = pwin + ptt * h5 * 411
Else
twin = twin + ptt * h5 * 411
End If
Else
For f = 0 To 9
h6 = face(f)
bt = b + d + f
If bt > 9 Then bt = bt - 10
If bt > 9 Then bt = bt - 10
If bt > pt Then
bwin = bwin + ptt * h5 * h6
ElseIf pt > bt Then
pwin = pwin + ptt * h5 * h6
Else
twin = twin + ptt * h5 * h6
End If
Next
bt = btt
End If
face(e) = face(e) + 1
pt = pt + 1
Next
Else
If bt > 5 Then
If bt > pt Then
bwin = bwin + ptt * 169332
ElseIf pt > bt Then
pwin = pwin + ptt * 169332
Else
twin = twin + ptt * 169332
End If
Else
For f = 0 To 9
h6 = face(f)
bt = b + d + f
If bt > 9 Then bt = bt - 10
If bt > 9 Then bt = bt - 10
If bt > pt Then
bwin = bwin + ptt * 411 * h6
ElseIf pt > bt Then
pwin = pwin + ptt * 411 * h6
Else
twin = twin + ptt * 411 * h6
End If
Next
End If
End If
End If
face(d) = face(d) + 1
Next
face(b) = face(b) + 1
Next
face(c) = face(c) + 1
Next
face(a) = face(a) + 1
Next


Debug.Print bwin / (bwin + pwin + twin)
Debug.Print pwin / (bwin + pwin + twin)
Debug.Print twin / (bwin + pwin + twin)

Debug.Print
Debug.Print bwin, "Banker win"
Debug.Print pwin, "Player win"
Debug.Print twin, "Tie win"
Debug.Print bwin + pwin + twin
"It is impossible to begin to learn that which one thinks one already knows." -Epictetus
QFIT
QFIT
  • Threads: 1
  • Posts: 315
Joined: Feb 12, 2010
April 27th, 2017 at 8:50:23 AM permalink
Cut another 40% off. Now 0.0006 second. I love speed.


Dim ptt2 As Double, j, btt, ptt As Double, face(10) As Double, p1 As Double, p2 As Double, b1 As Double, b2 As Double, h5 As Double, h6 As Double, a, b, c, d, e, f, bwin As Double, twin As Double, pwin As Double, sec0 As Single, i, pt, bt, xx
Dim earray(9), pttmp As Double, TotalPerm As Double, decks, ptth5 As Double, ptt411 As Double, ptt169332 As Double, pc1 As Double, pc2 As Double
sec0 = Timer

bwin = 0: twin = 0: pwin = 0
decks = 8
Select Case decks
Case 6: TotalPerm = 878869206895680# '(decks*52)!/(decks*52-6)!
Case 8: TotalPerm = 4.99839827550336E+15 '(decks*52)!/(decks*52-6)!
End Select
pc1 = decks * 52 - 5
pc2 = (decks * 52 - 4) * (decks * 52 - 5)
earray(0) = 4
earray(1) = 4
earray(2) = 5
earray(3) = 5
earray(4) = 6
earray(5) = 6
earray(6) = 7
earray(7) = 7
earray(8) = 3
earray(9) = 4
For i = 1 To 9
face(i) = decks * 4
Next
face(0) = decks * 4 * 4


For a = 0 To 9
p1 = face(a)
face(a) = face(a) - 1
For c = a To 9
p2 = face(c)
face(c) = face(c) - 1
For b = 0 To 9
b1 = face(b)
face(b) = face(b) - 1
ptt2 = p1 * p2 * b1
If a <> c Then ptt2 = 2 * ptt2
For d = b To 9
b2 = face(d)
ptt = ptt2 * b2
If b <> d Then ptt = 2 * ptt
ptt411 = ptt * pc1
ptt169332 = ptt * pc2
face(d) = face(d) - 1
pt = a + c
bt = b + d
If pt > 9 Then pt = pt - 10
If bt > 9 Then bt = bt - 10
btt = bt
If pt > 7 Or bt > 7 Then
If pt > bt Then
pwin = pwin + ptt169332
ElseIf pt = bt Then
twin = twin + ptt169332
End If
Else
If pt < 6 Then
pt = a + c
If pt > 9 Then pt = pt - 10
For e = 0 To 9
h5 = face(e)
face(e) = face(e) - 1
If pt > 9 Then pt = pt - 10

If bt >= earray(e) Then
If pt > bt Then
pwin = pwin + ptt411 * h5
ElseIf pt = bt Then
twin = twin + ptt411 * h5
End If
Else
ptth5 = ptt * h5
For f = 0 To 9
If bt > 9 Then bt = bt - 10
If pt > bt Then
pwin = pwin + ptth5 * face(f)
ElseIf pt = bt Then
twin = twin + ptth5 * face(f)
End If
bt = bt + 1
Next
bt = btt
End If
face(e) = face(e) + 1
pt = pt + 1
Next
Else
If bt > 5 Then
If pt > bt Then
pwin = pwin + ptt169332
ElseIf pt = bt Then
twin = twin + ptt169332
End If
Else
bt = b + d
For f = 0 To 9
h6 = face(f)
If bt > 9 Then bt = bt - 10
If pt > bt Then
pwin = pwin + ptt411 * h6
Else
If pt = bt Then twin = twin + ptt411 * h6
End If
bt = bt + 1
Next
End If
End If
End If
face(d) = face(d) + 1
Next
face(b) = face(b) + 1
Next
face(c) = face(c) + 1
Next
face(a) = face(a) + 1
Next

bwin = TotalPerm - pwin - twin
Debug.Print bwin / (bwin + pwin + twin)
Debug.Print pwin / (bwin + pwin + twin)
Debug.Print twin / (bwin + pwin + twin)

Debug.Print
Debug.Print bwin, "Banker win"
Debug.Print pwin, "Player win"
Debug.Print twin, "Tie win"
Last edited by: QFIT on Apr 27, 2017
"It is impossible to begin to learn that which one thinks one already knows." -Epictetus
QFIT
QFIT
  • Threads: 1
  • Posts: 315
Joined: Feb 12, 2010
April 27th, 2017 at 9:52:01 AM permalink
Cut it another 70% to 0.00017 second. Edited above code.
"It is impossible to begin to learn that which one thinks one already knows." -Epictetus
QFIT
QFIT
  • Threads: 1
  • Posts: 315
Joined: Feb 12, 2010
April 28th, 2017 at 9:44:51 AM permalink
Cut it to under one ten-thousandth of a second (0.000092 second). That fast enough.:) Can't edit my old post, so code added here:


Dim ptt2 As Double, j, btt, ptt As Double, face(10) As Double, p1 As Double, p2 As Double, b1 As Double, b2 As Double, h5 As Double, h6 As Double, a, b, c, d, e, f, bwin As Double, twin As Double, pwin As Double, sec0 As Single, i, pt, bt, xx
Dim earray(9), pttmp As Double, TotalPerm As Double, decks, ptth5 As Double, ptt411 As Double, ptt169332 As Double, pc1 As Double, pc2 As Double
Dim ee, ff, ft As Double
sec0 = Timer

bwin = 0: twin = 0: pwin = 0
decks = 8
Select Case decks
Case 6: TotalPerm = 878869206895680# '(decks*52)!/(decks*52-6)!
Case 8: TotalPerm = 4.99839827550336E+15 '(decks*52)!/(decks*52-6)!
End Select
pc1 = decks * 52 - 5
pc2 = (decks * 52 - 4) * (decks * 52 - 5)
earray(0) = 4
earray(1) = 4
earray(2) = 5
earray(3) = 5
earray(4) = 6
earray(5) = 6
earray(6) = 7
earray(7) = 7
earray(8) = 3
earray(9) = 4
For i = 1 To 9
face(i) = decks * 4
Next
face(0) = decks * 4 * 4



For a = 0 To 9
p1 = face(a)
face(a) = face(a) - 1
For c = a To 9
p2 = face(c)
face(c) = face(c) - 1
For b = 0 To 9
b1 = face(b)
face(b) = face(b) - 1
ptt2 = p1 * p2 * b1
If a <> c Then ptt2 = ptt2 + ptt2
For d = b To 9
b2 = face(d)
ptt = ptt2 * b2
If b <> d Then ptt = ptt + ptt
ptt411 = ptt * pc1
ptt169332 = ptt * pc2
face(d) = face(d) - 1
pt = a + c
bt = b + d
If pt > 9 Then pt = pt - 10
If bt > 9 Then bt = bt - 10
btt = bt
If pt > 7 Or bt > 7 Then
If pt > bt Then
pwin = pwin + ptt169332
ElseIf pt = bt Then
twin = twin + ptt169332
End If
Else
If pt < 6 Then
pt = a + c
If pt > 9 Then pt = pt - 10
For e = 0 To 9
h5 = face(e)
face(e) = face(e) - 1
If pt > 9 Then pt = pt - 10

If bt >= earray(e) Then
If pt > bt Then
pwin = pwin + ptt411 * h5
ElseIf pt = bt Then
twin = twin + ptt411 * h5
End If
Else
ff = 10 - bt
ee = ff + pt - 1
If ee > 9 Then ee = 9
ft = 0
For i = ff To ee
ft = ft + face(i)
Next
For i = 0 To ff + pt - 11
ft = ft + face(i)
Next
pwin = pwin + ptt * h5 * ft
ff = pt - bt
If ff < 0 Then
twin = twin + ptt * h5 * face(ff + 10)
Else
twin = twin + ptt * h5 * face(ff)
End If
End If
face(e) = face(e) + 1
pt = pt + 1
Next
Else
If bt > 5 Then
If pt > bt Then
pwin = pwin + ptt169332
ElseIf pt = bt Then
twin = twin + ptt169332
End If
Else
bt = b + d
For f = 0 To 9
h6 = face(f)
If bt > 9 Then bt = bt - 10
If pt > bt Then
pwin = pwin + ptt411 * h6
Else
If pt = bt Then twin = twin + ptt411 * h6
End If
bt = bt + 1
Next
End If
End If
End If
face(d) = face(d) + 1
Next
face(b) = face(b) + 1
Next
face(c) = face(c) + 1
Next
face(a) = face(a) + 1
Next

bwin = TotalPerm - pwin - twin
Debug.Print bwin / (bwin + pwin + twin)
Debug.Print pwin / (bwin + pwin + twin)
Debug.Print twin / (bwin + pwin + twin)

Debug.Print
Debug.Print bwin, "Banker win"
Debug.Print pwin, "Player win"
Debug.Print twin, "Tie win"
"It is impossible to begin to learn that which one thinks one already knows." -Epictetus
Mission146
Mission146
  • Threads: 142
  • Posts: 16832
Joined: May 15, 2012
April 29th, 2017 at 9:13:03 AM permalink
Quote: gordonm888

Not only is there a lot of specialized expertise among the WOV forum crowd, but I'm beginning to appreciate how knowledgeable the admins are as well (specifically Babs, Mission and JB in addition to Wiz). Its actually damn impressive.



Thanks for the compliment!
https://wizardofvegas.com/forum/off-topic/gripes/11182-pet-peeves/120/#post815219
maglex96
maglex96
  • Threads: 0
  • Posts: 2
Joined: Apr 26, 2017
October 13th, 2020 at 9:07:13 AM permalink
I am trying to implement your algorithm in pascal /delphi. I am also trying to do it for each draw in the shoe not just the initial start as you have done. Looking at your iterations there are a few variables that you derive that are unknown to me.

In the first iteration you have the constants 169332 and 411. what do these represents and how are they altered as more cards are drawn from the shoe. However in the second and third iterations you define variables ptt411 = ptt * pc1 and ptt169332 = ptt * pc2 in place of the constants introduced in iteration 1 but you also introduce two new variables pc1 and pc2 which are defined as pc1 = decks * 52 - 5
pc2 = (decks * 52 - 4) * (decks * 52 - 5). Again what do these variables represent and how to they change during play. Or is the case that your algorithm is a one time algorithm and only works for a new game before any cards are drawn.

Thanks
USpapergames
USpapergames
  • Threads: 18
  • Posts: 807
Joined: Jun 23, 2020
November 30th, 2020 at 6:31:49 AM permalink
Quote: 7up

How to do combinational analysis faster
To calculate baccarat combinations, if listing all six cards from 0 to 9, there are 1000000 steps.
Cutting down some repeating first two cards, there are still 302500 steps in my program.
Any way to simplify the process? Any formula?
Thanks in advance.



I could help you but I'm choosing not to only because I'm trying to publish my research so it can be nominated for an able prize. I am not joking when I say I have all the knowledge your seeking (and more) but you're going to have to wait till it's published first. I have 3 two hour YouTube videos (currently unlisted) using a theorem that's not currently known to anyone but myself and the very small people that I've shared my research with (like Prof. Hillel Furstenberg). This theorem of mine does exactly what your asking for, an easy way to simplify & subdivide large combinatorial groups so that solving probabilities for these massive amounts of data becomes easy.
Math is the only true form of knowledge
Wizard
Administrator
Wizard
  • Threads: 1520
  • Posts: 27118
Joined: Oct 14, 2009
November 30th, 2020 at 6:44:56 AM permalink
Welcome back USPG! Hope to see you in the easy math puzzle thread.
"For with much wisdom comes much sorrow." -- Ecclesiastes 1:18 (NIV)
USpapergames
USpapergames
  • Threads: 18
  • Posts: 807
Joined: Jun 23, 2020
December 1st, 2020 at 9:55:33 AM permalink
Quote: Wizard

Welcome back USPG! Hope to see you in the easy math puzzle thread.



Thank you, surely you don't want me to post all the answers to easy puzzles. Did you want me to post some easy math puzzles to solve?
Math is the only true form of knowledge
  • Jump to: