paloma blog

NWエンジニアやってます。主に自宅環境のお遊びを書きます。Pythonもちょっと。タイトルは好きなカクテルから。

スリーカードポーカーで勝つことはできるのか 実践編

GTAオンラインでプレイしてみるまで存在も知らなかったスリーカードポーカーですが
一応自作ゲーム、シミュレータまで作成しました。

存在を知らしめた大元であるGTAオンラインで勝てるのか試したいと思います。

50回の勝負にします。 シミュレータの結果はこんな感じ。

masashi@PC-ubuntu:~/Three-card-poker$ python3 simulater.py 
You are first given $1,000.
Three card poker simulator start.
The simulator trials 50 times.
You'll bet ante $10 and pair plus $10 all the time.

=== Probabliry of winning or losing ===

Player 34 wins. (68.0%)
Dealer 16 wins. (32.0%)
Draw 0 times. (0.0%)

=== Percentage of Players all hands ===

High card!            70.0%
One Pair!             18.0%
Flash!                 8.0%
Straight!              4.0%

=== Percentage of Players win(34 times) hands ===

High card!          61.765%
One Pair!           23.529%
Flash!              11.765%
Straight!            2.941%

You finally got $2,230
masashi@PC-ubuntu:~/Three-card-poker$ for a in {1..10} ; do python3 simulater.py | tail -1 ; done 
You finally got $1,230
You finally got $1,540
You finally got $1,940
You finally got $1,750
You finally got $1,520
You finally got $2,430
You finally got $1,910
You finally got $1,400
You finally got $1,620
You finally got $1,620

本当にこの通り勝てるんならウハウハもんですね。

いざ勝負!

ダイヤモンドカジノにやってきました。

開始前のチップは17495です。
増やして帰ることはできるんでしょうか。

f:id:paloma69:20200712201328j:plain

シミュレータと同様にアンティ、ペアプラスを10ずつ賭けます。

結果

50回分のサマリです。
負けた時は賭けチップ分がそのまま引かれています。

左上から右下への順で張り付けてます。

f:id:paloma69:20200712201557p:plain

勝負後のチップは16995。
チップが500減ってしまいました…。

勝敗のまとめはこんな感じです。

f:id:paloma69:20200712202444p:plain

勝率50%ですが、今回は27回負けでした。
アプラスボーナスは25%で出る計算ですが、今回10回なので20%でした。
まあ今回の試行回数的にブレるのは仕方ないですね。

なぜ負けたのか…コードに大切な処理が抜けていた

ゲームしていてチップの減るときを見ていたのですが、
コードを見返したらチップを賭けた分を引く処理が抜けてました…。

  1. チップを賭ける
  2. カードのシャッフル
  3. 手札を配る
  4. 勝負する
  5. 払い戻し

の処理順なのですが、1の分を引く処理が抜けていました。
負けた時にチップを引く処理はあるのですが、勝った時は引かれずそのまま払い戻しも貰うという処理になっていました。
そりゃ勝てるよ...。

なぜ負けたか、ではなくて負けるべくして負けた感じですね。

修正

部分だけ切り抜いてもわかりづらいですが、賭けた分引く処理を追加。

diff --git a/pokerapp.py b/pokerapp.py
index 72c421b..ddf0e00 100644
--- a/pokerapp.py
+++ b/pokerapp.py
@@ -314,6 +314,9 @@ def main(chip):
        pay_ante = Payoff(bet_ante, p_hand[0]).ante_bonus()
        pay_pairplus = Payoff(bet_pairplus, p_hand[0]).pairplus_bonus()
 
+       # Reduce bet chips
+       chip = chip - (bet_ante + bet_play + bet_pairplus)
+
        # To reuse the chips for main loop
        global total
 
diff --git a/simulater.py b/simulater.py
index 9f13ad3..3888795 100644
--- a/simulater.py
+++ b/simulater.py
@@ -39,6 +39,9 @@ def Trials(chips):
                match_list.append(match_result)
                hand_list.append(hand_result)
 
+               # Reduce bet chips
+               chips = chips - (ante + bet_chip + pp)
+
                # pay off
                pays = pokerapp.Liquidation(match_result, dealer_hand, ante, bet_chip)

改めてシミュレーション

チップが0以下になったらループ抜けるようにして再度シミュレーションしてみます。

masashi@PC-ubuntu:~/Three-card-poker$ python3 simulater.py 
You are first given $1,000.
Three card poker simulator start.
The simulator trials 50 times.
You'll bet ante $10 and pair plus $10 all the time.

=== Probabliry of winning or losing ===

Player 27 wins. (54.0%)
Dealer 23 wins. (46.0%)
Draw 0 times. (0.0%)

=== Percentage of Players all hands ===

High card!            70.0%
One Pair!             24.0%
Straight!              4.0%
Flash!                 2.0%

=== Percentage of Players win(27 times) hands ===

High card!          51.852%
One Pair!           37.037%
Straight!            7.407%
Flash!               3.704%

You finally got $190
masashi@PC-ubuntu:~/Three-card-poker$ for a in {1..10} ; do python3 simulater.py | tail -1 ; done 
You finally got $-40
You finally got $-10
You finally got $-100
You finally got $970
You finally got $220
You finally got $360
You finally got $-10
You finally got $230
You finally got $-230
You finally got $400

普通に負ける時があります。
まあ、ギャンブルってこんなもんですよね。

一旦チップが0以下になったら止める処理を入れたのですが、マイナス表記になってしまってますね。
手持ち以上賭けられないように修正しないと。

検証結果: うまい話は無い

期待をもって挑んだ実践ですが、やはり楽に儲ける方法は無いようです。
地道に稼ぎましょう。

むすび

最初に今回の部分のコードをきっちり書けていれば、今回の検証は発生しなかったと思います。
とんでもないデバッグ方法になってしまいましたが、重大なバグを潰せたので良しとしますw

しかし本当に勝つことは出来ないのでしょうか。
オリるケースも考慮してシミュレータ組み直したいですね。

リポジトリ

github.com