Blackjack strategy: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (syntax highlighting fixup automation)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(2 intermediate revisions by 2 users not shown)
Line 1:
{{draft task}} [[Category:Games]]
{{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:
Line 25:
* What can I expect to be my biggest loss?
* What can I expect to win/lose over the year?
 
=={{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.
Line 42 ⟶ 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.
<syntaxhighlight lang="go">package main
 
import (
Line 1,318 ⟶ 1,317:
Loss % staked : 1.801
</pre>
 
=={{header|Nim}}==
{{trans|Go}}
<syntaxhighlight lang=Nim"nim">import random, sequtils, strformat, strutils
 
type
Line 2,514 ⟶ 2,512:
Total staked: 20516.0
Loss % staked: 0.453</pre>
 
=={{header|Phix}}==
{{trans|Go}}
<!--<syntaxhighlight lang=Phix"phix">-->
<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>
Line 3,816 ⟶ 3,813:
Loss % staked : 0.073
</pre>
 
=={{header|Wren}}==
{{trans|Go}}
Line 3,822 ⟶ 3,818:
{{libheader|Wren-dynamic}}
{{libheader|Wren-fmt}}
{{libheader|Wren-traititerate}}
<br>
This runs OK but takes a long time to do so - 6 minutes 21 seconds compared to less than 3 seconds for the Go example. As I also wrote the latter I'm confident it's a faithful translation.
Line 3,829 ⟶ 3,825:
 
So interpreted languages such as Wren are probably stuck with slow times for this task.
<syntaxhighlight lang=ecmascript"wren">import "random" for Random
import "./array" for Array, ArrayType
import "./dynamic" for Struct
import "./fmt" for Fmt
import "./traititerate" for Indexed
 
var Rand = Random.new()
9,476

edits