Thread Rating:
November 10th, 2014 at 8:11:16 AM
permalink
Guys,
I have written a Baccarat Simulator in python. The problem I am having is the results seem to favor Player just a bit.
My Baccarat Simulator setup.
8 deck shoe
Card is then dealt and the value of that card is the amount of cards burned before first hand.
Once the shoe hits 16 cards no new hands start.
Below are my stats after 100K simulated shoes.
Baccarat Simulator Recap
____________________________________
Total Shoes Played - 100000
Total Hands Played - 8108635
Average Hands Per Shoe - 81
Total Banker Wins - 3568819
Average Banker Wins Per Shoe - 35
Total Player Wins - 3679521
Average Player Wins Per Shoe - 36
Total Ties - 760294
Average Ties Per Shoe - 7
Banker Max Winning Streak - 20
Player Max Winning Streak - 21
Ties Max Winning Streak - 7
Seems like every time I run this sim I get roughly the same thing. Shows more Player wins then Banker?
What do you guys think?
NOTE CODE -----------
Matt
I have written a Baccarat Simulator in python. The problem I am having is the results seem to favor Player just a bit.
My Baccarat Simulator setup.
8 deck shoe
Card is then dealt and the value of that card is the amount of cards burned before first hand.
Once the shoe hits 16 cards no new hands start.
Below are my stats after 100K simulated shoes.
Baccarat Simulator Recap
____________________________________
Total Shoes Played - 100000
Total Hands Played - 8108635
Average Hands Per Shoe - 81
Total Banker Wins - 3568819
Average Banker Wins Per Shoe - 35
Total Player Wins - 3679521
Average Player Wins Per Shoe - 36
Total Ties - 760294
Average Ties Per Shoe - 7
Banker Max Winning Streak - 20
Player Max Winning Streak - 21
Ties Max Winning Streak - 7
Seems like every time I run this sim I get roughly the same thing. Shows more Player wins then Banker?
What do you guys think?
NOTE CODE -----------
Matt
November 10th, 2014 at 8:42:12 AM
permalink
I think that it would help if you posted the code here.
November 10th, 2014 at 9:21:01 AM
permalink
Quote: ThatDonGuyI think that it would help if you posted the code here.
You might not have the banker basic strategy getting implemented correctly. I'd also run my tests for millions of shoes. At that point you should see NO changes when you run it over and over again.
Lastly, I agree I can't really help debug without seeing the code. The best thing you can do is come up with as many different hands as you can to go through all of the logic and test case by case (hard coding the hands) to see it's responding accordingly. This is what I had to do with my Blackjack Simulator when I had a bug in it and didn't know what it was. I'm still banking you have some small mistake like dealer strategy that is getting amplified over 100k shoes, which is why you see a distinct difference in your results.
Playing it correctly means you've already won.
November 10th, 2014 at 10:23:24 AM
permalink
The exact expected player win% is 0.446247 from WOO, and you have 0.453778.
Over 8 million hands, I get a sample standard deviation of 0.000175, which means you are about 43 st dev off. Not random, there's a bug.
Over 8 million hands, I get a sample standard deviation of 0.000175, which means you are about 43 st dev off. Not random, there's a bug.
Wisdom is the quality that keeps you out of situations where you would otherwise need it
November 10th, 2014 at 10:59:50 AM
permalink
I'm not 100% sure, but I think your error is when Player doesn't draw because he has 2-card total of 6 or 7 and the Banker has a 2-card total of 6. I think you have the Banker drawing a third card.
“Man Babes” #AxelFabulous
November 10th, 2014 at 11:49:44 AM
permalink
Miplet,
Yeah that is my issue I just cant figure out how to fix it.
Matt
Yeah that is my issue I just cant figure out how to fix it.
Matt
November 10th, 2014 at 11:57:35 AM
permalink
I think line 110 should be changed
from
elif self.bankerscore == 6 and (self.thirdcard >=6 and self.thirdcard >=7):
to
elif self.bankerscore == 6 and (self.thirdcard >=6 and self.thirdcard <=7):
from
elif self.bankerscore == 6 and (self.thirdcard >=6 and self.thirdcard >=7):
to
elif self.bankerscore == 6 and (self.thirdcard >=6 and self.thirdcard <=7):
November 10th, 2014 at 12:03:07 PM
permalink
Guys below is the piece of code that needs to be changed. I need to fix it in the else statement.
Any python guys here who dont mind helping?
Matt
if playerScore >= 6 or (bankerScore == 8 or bankerScore == 9):
playerThird = None
playerScorefinal = playerScore
print "Player has a score of " + str(playerScore) + ", player stays. "
else:
print "Player has a current score of " + str(playerScore) +", player hits. "
playerThird = self.gameDeck.drawCardfun()
playerScorefinal = self.getActualscore(playerScore+ self.gameDeck.getValue(playerThird))
if bankerScore >= 7 or (playerScore == 8 or playerScore == 9):
bankerThird = None
bankerScorefinal = bankerScore
print "Banker has a score of " + str(bankerScore) + ", banker stays. "
else:
self.hitCharttext(bankerScore)
bankerThird = self.hitChart(bankerScore, self.gameDeck.getValue(playerThird))
#check if playerThird is none
#this prints that banker hits depending on players third card
#this prints the banker's third card
#this returns the actual card of bankers third card
bankerScorefinal = self.getActualscore(bankerScore + self.gameDeck.getValue(bankerThird))
Any python guys here who dont mind helping?
Matt
if playerScore >= 6 or (bankerScore == 8 or bankerScore == 9):
playerThird = None
playerScorefinal = playerScore
print "Player has a score of " + str(playerScore) + ", player stays. "
else:
print "Player has a current score of " + str(playerScore) +", player hits. "
playerThird = self.gameDeck.drawCardfun()
playerScorefinal = self.getActualscore(playerScore+ self.gameDeck.getValue(playerThird))
if bankerScore >= 7 or (playerScore == 8 or playerScore == 9):
bankerThird = None
bankerScorefinal = bankerScore
print "Banker has a score of " + str(bankerScore) + ", banker stays. "
else:
self.hitCharttext(bankerScore)
bankerThird = self.hitChart(bankerScore, self.gameDeck.getValue(playerThird))
#check if playerThird is none
#this prints that banker hits depending on players third card
#this prints the banker's third card
#this returns the actual card of bankers third card
bankerScorefinal = self.getActualscore(bankerScore + self.gameDeck.getValue(bankerThird))
November 10th, 2014 at 12:04:21 PM
permalink
Also the 2 if/else statements on starting lines 175 and 185 should all be one big block. The banker decision is dependent on the player decision so they can't be separated.
if player >= 8 or banker >= 8
game done
else if player <= 5
player draws
banker hitchart
else if banker <= 5
hit
if player >= 8 or banker >= 8
game done
else if player <= 5
player draws
banker hitchart
else if banker <= 5
hit
November 10th, 2014 at 12:10:48 PM
permalink
Quote: wudgedI think line 110 should be changed
from
elif self.bankerscore == 6 and (self.thirdcard >=6 and self.thirdcard >=7):
to
elif self.bankerscore == 6 and (self.thirdcard >=6 and self.thirdcard <=7):
or just
elif self.bankerscore == 6 and (self.thirdcard ==6 or self.thirdcard ==7):
Also:
Line 100 from
if self.thirdcard == None:
to
if self.thirdcard == None and self.bankerscore <6 :
“Man Babes” #AxelFabulous
November 10th, 2014 at 1:37:05 PM
permalink
Ok I implemented MIPLET's changes and this is what I got
Baccarat Simulator Recap
____________________________________
Total Shoes Played - 1000000
Total Hands Played - 81461675
Average Hands Per Shoe - 81.46
Total Banker Wins - 36339857
Average Banker Wins Per Shoe - 36.34
Total Player Wins - 36684996
Average Player Wins Per Shoe - 36.68
Total Ties - 7436821
Average Ties Per Shoe - 7.437
what am I missing now?
someone better at python than me please jump in
Matt
Baccarat Simulator Recap
____________________________________
Total Shoes Played - 1000000
Total Hands Played - 81461675
Average Hands Per Shoe - 81.46
Total Banker Wins - 36339857
Average Banker Wins Per Shoe - 36.34
Total Player Wins - 36684996
Average Player Wins Per Shoe - 36.68
Total Ties - 7436821
Average Ties Per Shoe - 7.437
what am I missing now?
someone better at python than me please jump in
Matt
November 10th, 2014 at 2:32:24 PM
permalink
Lines 80 and 81, in the getValue() definition, are:
Line 193 is:
so if playerThird = none, then the second parameter to hitChart is getValue(playerThird), which is 0.
Lines 102-103, in the hitChart definition, are:
However, thirdcard is never none.
Try changing line 102 to:
No "actual" card should make thirdcard 0; it should only be 0 if it was None.
That code font is a little small; if you can't read it, what it says is, in line 102, change:
if self.thirdcard == None
to
if self.thirdcard == 0
if card == None:
self.value = 0
Line 193 is:
bankerThird = self.hitChart(bankerScore, self.gameDeck.getValue(playerThird))
so if playerThird = none, then the second parameter to hitChart is getValue(playerThird), which is 0.
Lines 102-103, in the hitChart definition, are:
if self.thirdcard == None and self.bankerscore <6:
return self.gameDeck.drawCardfun()
However, thirdcard is never none.
Try changing line 102 to:
if self.thirdcard == 0 and self.bankerscore <6:
No "actual" card should make thirdcard 0; it should only be 0 if it was None.
That code font is a little small; if you can't read it, what it says is, in line 102, change:
if self.thirdcard == None
to
if self.thirdcard == 0
November 10th, 2014 at 2:37:31 PM
permalink
is this easier to read??
Thanks guys for all the help.
Feel free to help innovate on the code and expand it as I just want this to be the best Baccarat simulator you can find.
November 10th, 2014 at 2:44:35 PM
permalink
Quote: rbpd5015https://bpaste.net/show/a95f49884066
is this easier to read??
You misunderstood.
Your code is perfectly readable. I was talking about the code font this board uses for the code I put in my reply.
November 10th, 2014 at 5:50:56 PM
permalink
That Don Guy, I am a bit confused what lines exactly you want me to change?
are you saying only change line 102?
Matt
are you saying only change line 102?
Matt
November 10th, 2014 at 5:55:17 PM
permalink
Quote: rbpd5015That Don Guy, I am a bit confused what lines exactly you want me to change?
are you saying only change line 102?
Yes - change line 102 to:
if self.thirdcard == 0 and self.bankerscore <6:
(in other words, just replace None with 0 in line 102)
November 10th, 2014 at 6:19:41 PM
permalink
That Don Guy,
Looks good so far, I am in the middle of running a 1 million shoe simulation, but will give you an update while its running..
Does this look a bit closer to the correct numbers?
Matt
Baccarat Simulator Recap
____________________________________
Total Shoes Played - 250000
Total Hands Played - 20219261
Average Hands Per Shoe - 80.88
Total Banker Wins - 9156260
Average Banker Wins Per Shoe - 36.63
Banker Win Probability - 0.4528
Total Player Wins - 8912843
Average Player Wins Per Shoe - 35.65
Player Win Probability - 0.4408
Total Ties - 1900157
Average Ties Per Shoe - 7.601
Looks good so far, I am in the middle of running a 1 million shoe simulation, but will give you an update while its running..
Does this look a bit closer to the correct numbers?
Matt
Baccarat Simulator Recap
____________________________________
Total Shoes Played - 250000
Total Hands Played - 20219261
Average Hands Per Shoe - 80.88
Total Banker Wins - 9156260
Average Banker Wins Per Shoe - 36.63
Banker Win Probability - 0.4528
Total Player Wins - 8912843
Average Player Wins Per Shoe - 35.65
Player Win Probability - 0.4408
Total Ties - 1900157
Average Ties Per Shoe - 7.601
November 10th, 2014 at 6:53:49 PM
permalink
ok Guys here are my numbers after my first million simulation...
How do the numbers look?
Baccarat Simulator Recap
____________________________________
Total Shoes Played - 1000000
Total Hands Played - 80876911
Average Hands Per Shoe - 80.88
Total Banker Wins - 36631262
Average Banker Wins Per Shoe - 36.63
Banker Win Probability - 0.4529
Total Player Wins - 35643370
Average Player Wins Per Shoe - 35.64
Player Win Probability - 0.4407
Total Ties - 7602278
Average Ties Per Shoe - 7.602
Tie Win Probability - 0.09400
How do the numbers look?
Baccarat Simulator Recap
____________________________________
Total Shoes Played - 1000000
Total Hands Played - 80876911
Average Hands Per Shoe - 80.88
Total Banker Wins - 36631262
Average Banker Wins Per Shoe - 36.63
Banker Win Probability - 0.4529
Total Player Wins - 35643370
Average Player Wins Per Shoe - 35.64
Player Win Probability - 0.4407
Total Ties - 7602278
Average Ties Per Shoe - 7.602
Tie Win Probability - 0.09400
November 10th, 2014 at 7:39:30 PM
permalink
Not good. You are miscounting hands at the very least.
36631262 + 35643370 + 7602278 = 79876910
and your probabilities don't add up to 1.
36631262 + 35643370 + 7602278 = 79876910
and your probabilities don't add up to 1.
Wisdom is the quality that keeps you out of situations where you would otherwise need it
November 10th, 2014 at 8:13:11 PM
permalink
Good call was counting my hands wrong.
I was count the initial deal as a hand and was counting the final hand which was not dealt
Running another 1 mill sim now.
I was count the initial deal as a hand and was counting the final hand which was not dealt
Running another 1 mill sim now.
November 10th, 2014 at 10:53:59 PM
permalink
I think I got it right now guys what do you think after about 3 million Shoes? Sorry for not being exactly at 3 mill, I was going to 10 mill when my terminal froze, so was able to capture this.
Baccarat Simulator Recap
____________________________________
Total Shoes Played - 2996026
Total Hands Played - 239311936
True Total Hands - 239311936
Average Hands Per Shoe - 79.87646
Total Banker Wins - 109751953
Average Banker Wins Per Shoe - 36.63251
Banker Win Probability - 0.4586146
Total Player Wins - 106792916
Average Player Wins Per Shoe - 35.64486
Player Win Probability - 0.4462499
Total Ties - 22767067
Average Ties Per Shoe - 7.599089
Tie Win Probability - 0.09513553
Below are the Probability according to the Wizard of Odds
EVENT PROBABILITY
Banker wins 0.45859
Player wins 0.446247
Tie 0.095156
Baccarat Simulator Recap
____________________________________
Total Shoes Played - 2996026
Total Hands Played - 239311936
True Total Hands - 239311936
Average Hands Per Shoe - 79.87646
Total Banker Wins - 109751953
Average Banker Wins Per Shoe - 36.63251
Banker Win Probability - 0.4586146
Total Player Wins - 106792916
Average Player Wins Per Shoe - 35.64486
Player Win Probability - 0.4462499
Total Ties - 22767067
Average Ties Per Shoe - 7.599089
Tie Win Probability - 0.09513553
Below are the Probability according to the Wizard of Odds
EVENT PROBABILITY
Banker wins 0.45859
Player wins 0.446247
Tie 0.095156
November 10th, 2014 at 11:08:31 PM
permalink
LOST of effort for a -EV game.
Meanwhile guys are making money on reals advantage plays.
perhaps there's money in selling such a program.
Meanwhile guys are making money on reals advantage plays.
perhaps there's money in selling such a program.
♪♪Now you swear and kick and beg us That you're not a gamblin' man Then you find you're back in Vegas With a handle in your hand♪♪ Your black cards can make you money So you hide them when you're able In the land of casinos and money You must put them on the table♪♪ You go back Jack do it again roulette wheels turinin' 'round and 'round♪♪ You go back Jack do it again♪♪
November 11th, 2014 at 8:01:13 AM
permalink
Thanks for the positivity AcelWolf.
Hey guys I am trying to correctly count my streaks below is the code....
I am trying to count the following
maxbankerstreak
maxplayerstreak
maxtiestreak
1) P/B/T Win Streak, while also tracking a P/B/T hands without a loss.
those are called
maxplayerstreakmeta
maxtiestreakmeta
maxbankerstreakmeta
an example is below
Player Max Winning Streak - 15 (15) true wins started in shoe number 1465 hand number 18 through hand number 33 with 0 ties during streak!
the first 15 is the total number of hands without a loss. and the second 15 is the number of True Wins during that streak
so for example if it was
PPTTPPPTPPPB
the streak would be 11 (8) with 11 hands without a loss and 8 total wins.
Make sense any help would be greatly apprecitated
Matt
Hey guys I am trying to correctly count my streaks below is the code....
I am trying to count the following
maxbankerstreak
maxplayerstreak
maxtiestreak
1) P/B/T Win Streak, while also tracking a P/B/T hands without a loss.
those are called
maxplayerstreakmeta
maxtiestreakmeta
maxbankerstreakmeta
an example is below
Player Max Winning Streak - 15 (15) true wins started in shoe number 1465 hand number 18 through hand number 33 with 0 ties during streak!
the first 15 is the total number of hands without a loss. and the second 15 is the number of True Wins during that streak
so for example if it was
PPTTPPPTPPPB
the streak would be 11 (8) with 11 hands without a loss and 8 total wins.
Make sense any help would be greatly apprecitated
Matt
November 11th, 2014 at 8:53:18 AM
permalink
I notice that if you have a tie, then neither the player streak nor the banker streak is reset.
For example, in your example streak,
PPTTPPPTPPPB
is counted as a player streak of 8.
I am assuming that a "banker metastreak" is a streak of banker wins and ties between two player wins.
I am also ignoring "tie metastreak" as I don't see the difference between that and a "normal" tie streak.
You increment your player metastreak:
(a) when you have a player win, or
(b) when you have a tie and your current player metastreak > 0 (this indicates that you had a player win more recently than a bank win)
Similarly, you increment your banker metastreak:
(a) when you have a banker win, or
(b) when you have a tie and your current banker metastreak > 0
In other words:
On a player win:
On a banker win, replace "player" and "banker" (and vice versa) in the above
On a tie:
Note that playerstreakmeta and bankerstreakmeta are not reset to zero after a tie
For example, in your example streak,
PPTTPPPTPPPB
is counted as a player streak of 8.
I am assuming that a "banker metastreak" is a streak of banker wins and ties between two player wins.
I am also ignoring "tie metastreak" as I don't see the difference between that and a "normal" tie streak.
You increment your player metastreak:
(a) when you have a player win, or
(b) when you have a tie and your current player metastreak > 0 (this indicates that you had a player win more recently than a bank win)
Similarly, you increment your banker metastreak:
(a) when you have a banker win, or
(b) when you have a tie and your current banker metastreak > 0
In other words:
On a player win:
playerstreak++
playerstreakmeta++
if playerstreak > maxplayerstreak:
playerstreak = maxplayerstreak
if playerstreakmeta > maxplayerstreakmeta:
playerstreakmeta = maxplayerstreakmeta
bankerstreak = 0
bankerstreakmeta = 0
tiestreak = 0
On a banker win, replace "player" and "banker" (and vice versa) in the above
On a tie:
playerstreak = 0
bankerstreak = 0
if playerstreakmeta > 0:
playerstreakmeta++
if playerstreakmeta > maxplayerstreakmeta:
playerstreakmeta = maxplayerstreakmeta
if bankerstreakmeta > 0:
bankerstreakmeta++
if bankerstreakmeta > maxbankerstreakmeta:
bankerstreakmeta = maxbankerstreakmeta
tiestreak++
if tiestreak > maxtiestreak:
maxtiestreak = tiestreak
Note that playerstreakmeta and bankerstreakmeta are not reset to zero after a tie
November 11th, 2014 at 11:10:54 AM
permalink
Don,
I really f$#@ed this up....
you mind taking a few and seeing if you can get it to run again? Sorry I am not a python expert and really messed this up LOL.
Matt
I really f$#@ed this up....
you mind taking a few and seeing if you can get it to run again? Sorry I am not a python expert and really messed this up LOL.
Matt
November 11th, 2014 at 11:59:07 AM
permalink
I can see a mistake - and it's one I told you to make.
First, I would move all of the globals in lines 211-224, as well as the "ties" (line 239) and "bankerwins" (line 259), to just before line 208.
Second, here's the mistake I made: wherever you have "if something > maxsomething:" followed by "something = maxsomething", the second line should be "maxsomething = something". Instead of setting the maximum value equal to the current value, you are setting the current value to the maximum value (which is always zero).
This is lines 229, 231, 245, 249, 264, and 266.
Third, right before line 240, you need:
ties += 1
Also, keep in mind that your "longest player streak" shows the number of player wins between two banker wins, while the "longest banker streak" shows the number of consecutive banker wins. Is that what you want?
First, I would move all of the globals in lines 211-224, as well as the "ties" (line 239) and "bankerwins" (line 259), to just before line 208.
Second, here's the mistake I made: wherever you have "if something > maxsomething:" followed by "something = maxsomething", the second line should be "maxsomething = something". Instead of setting the maximum value equal to the current value, you are setting the current value to the maximum value (which is always zero).
This is lines 229, 231, 245, 249, 264, and 266.
Third, right before line 240, you need:
ties += 1
Also, keep in mind that your "longest player streak" shows the number of player wins between two banker wins, while the "longest banker streak" shows the number of consecutive banker wins. Is that what you want?
November 11th, 2014 at 12:38:38 PM
permalink
Me again - the edit didn't bump the post in the Recent Threads list.
There was something else:
Is there a reason line 271 is commented out? It seems to be needed.
Also, if you don't want to have it print out the results after every shoe, which seriously slows it down, you should add a line above the block of print statements in lines 317-334:
if shoes % 1000 == 0:
then indent the print statements below it (but not the line below them that increments the shoes variable).
There was something else:
Is there a reason line 271 is commented out? It seems to be needed.
Also, if you don't want to have it print out the results after every shoe, which seriously slows it down, you should add a line above the block of print statements in lines 317-334:
if shoes % 1000 == 0:
then indent the print statements below it (but not the line below them that increments the shoes variable).