Blackjack strategy: Difference between revisions

Content added Content deleted
m (syntax highlighting fixup automation)
m (Automated syntax highlighting fixup (second round - minor fixes))
Line 1: Line 1:
{{draft task}} [[Category:Games]]
[[Category:Games]]
The objective of this task is to recreate and explore the following [https://web.archive.org/web/20130625120019/http://www.blackjacktactics.com/blackjack/strategy/charts/single-deck/ strategy charts] for the game of [[wp:Blackjack|blackjack]] (which is known by many other names as well).
{{draft task}} The objective of this task is to recreate and explore the following [https://web.archive.org/web/20130625120019/http://www.blackjacktactics.com/blackjack/strategy/charts/single-deck/ strategy charts] for the game of [[wp:Blackjack|blackjack]] (which is known by many other names as well).


Assume that my casino:
Assume that my casino:
Line 25: Line 25:
* What can I expect to be my biggest loss?
* What can I expect to be my biggest loss?
* What can I expect to win/lose over the year?
* What can I expect to win/lose over the year?

=={{header|Go}}==
=={{header|Go}}==
As the dealer plays automatically, the first thing I did was to write a function which calculates the probabilities of the dealer ending up with various scores according to the Rules. I then checked the resulting table against a similar one on an 'active' online gambling site (which I'd better not link to here) and the results agreed to 6 decimal places.
As the dealer plays automatically, the first thing I did was to write a function which calculates the probabilities of the dealer ending up with various scores according to the Rules. I then checked the resulting table against a similar one on an 'active' online gambling site (which I'd better not link to here) and the results agreed to 6 decimal places.
Line 42: Line 41:


Finally, I've done 10 years of simulations as the basic statistics can vary quite a bit from year to year. However, it will be seen that % loss varies over a narrower range - between about 0.3 and 1.8% for this particular run - which seems reasonable given the casino's edge even after basic strategy is utilized.
Finally, I've done 10 years of simulations as the basic statistics can vary quite a bit from year to year. However, it will be seen that % loss varies over a narrower range - between about 0.3 and 1.8% for this particular run - which seems reasonable given the casino's edge even after basic strategy is utilized.
<syntaxhighlight lang=go>package main
<syntaxhighlight lang="go">package main


import (
import (
Line 1,318: Line 1,317:
Loss % staked : 1.801
Loss % staked : 1.801
</pre>
</pre>

=={{header|Nim}}==
=={{header|Nim}}==
{{trans|Go}}
{{trans|Go}}
<syntaxhighlight lang=Nim>import random, sequtils, strformat, strutils
<syntaxhighlight lang="nim">import random, sequtils, strformat, strutils


type
type
Line 2,514: Line 2,512:
Total staked: 20516.0
Total staked: 20516.0
Loss % staked: 0.453</pre>
Loss % staked: 0.453</pre>

=={{header|Phix}}==
=={{header|Phix}}==
{{trans|Go}}
{{trans|Go}}
<!--<syntaxhighlight lang=Phix>-->
<!--<syntaxhighlight lang="phix">-->
<span style="color: #000080;font-style:italic;">-- demo/rosetta/blackjack.exw</span>
<span style="color: #000080;font-style:italic;">-- demo/rosetta/blackjack.exw</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 3,816: Line 3,813:
Loss % staked : 0.073
Loss % staked : 0.073
</pre>
</pre>

=={{header|Wren}}==
=={{header|Wren}}==
{{trans|Go}}
{{trans|Go}}
Line 3,829: Line 3,825:


So interpreted languages such as Wren are probably stuck with slow times for this task.
So interpreted languages such as Wren are probably stuck with slow times for this task.
<syntaxhighlight lang=ecmascript>import "random" for Random
<syntaxhighlight lang="ecmascript">import "random" for Random
import "./array" for Array, ArrayType
import "./array" for Array, ArrayType
import "./dynamic" for Struct
import "./dynamic" for Struct