【发布时间】:2021-10-10 12:46:14
【问题描述】:
我尝试在DartPad 中编写一个程序来模拟一系列二十一点游戏,其中玩家遵循与庄家完全相同的策略,即击球直到分数超过16。现在根据文章here 和here房子应该比玩家至少有 5% 的优势。我如何解释这个优势?还有为什么完全像庄家一样玩会使赔率相等,有利于玩家。这是前面提到的程序:-
/*
* PROGRAM SIMULATIING BLACKJACK
*
* PLAYER KEEPS HITTING UNTIL THE SCORE EXEEDS 16
*
* RESULTS:
*
* PLAYER WINS ~ 43.8% OF TIMES
* MATCH IS DRAW ~ 12.4% OF TIMES
* DEALER WINS ~ 43.8% OF TIMES
*
* PROGRAM DOESN'T TAKE INTO ACCOUNT THE CARDS ALREADY DISTRIBUTED
* I.E. DISTRIBUTES CARDS FROM A FULL DECK OF CARDS TO BOTH THE
* PLAYER AND THE DEALER.
*
* */
import 'dart:math';
class Player {
int score;
bool hardHand, busted;
Player() {
this.score = 0;
this.hardHand = false;
this.busted = false;
}
void hit() {
int randomNumber = Random().nextInt(13) + 1;
if (randomNumber > 10) {
this.score += 10;
} else if (randomNumber == 1) {
this.score += 11;
this.hardHand = true;
} else {
this.score += randomNumber;
}
if (this.score > 21) {
if (this.hardHand) {
this.hardHand = false;
this.score -= 10;
}
}
if (this.score > 21) this.busted = true;
}
}
void main() {
int turns = 100000;
int wins = 0, loses = 0, draws = 0;
for (int i = 0; i < turns; i++) {
Player player1 = new Player();
Player dealer = new Player();
while (player1.score < 17) {
player1.hit();
}
while (dealer.score < 17) {
dealer.hit();
}
//print("score: ${player1.score} busted: ${player1.busted}");
if (player1.score > dealer.score) {
wins++;
} else if (player1.score == dealer.score) {
draws++;
} else {
loses++;
}
}
double winPercent = (wins / (wins + loses + draws)) * 100;
double drawPercent = (draws / (wins + loses + draws)) * 100;
double lossPercent = 100 - winPercent - drawPercent;
print("WIN Percentage: $winPercent");
print("DRAW Percentage: $drawPercent");
print("LOSS Percentage: $lossPercent");
}
【问题讨论】:
标签: dart probability blackjack