-
Notifications
You must be signed in to change notification settings - Fork 4
/
betting_strategies.py
52 lines (40 loc) · 1.86 KB
/
betting_strategies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Betting strategies to be used in expected value."""
from utils import get_hilo_running_count
class BaseBetter:
"""Base better. The parent class of all betters."""
@staticmethod
def get_bet(cards_seen: list[int], deck_number: int) -> int:
"""
Raise `NotImplementedError`. To be overridden in the other classes.
:param cards_seen: The cards we have already seen from the shoe. Used when card counting.
:param deck_number: The number of decks in the starting shoe.
:return: How much money to bet.
"""
raise NotImplementedError("The `get_bet` method hasn't been overridden.")
class SimpleBetter(BaseBetter):
"""Simple better. Bets the same amount every time."""
@staticmethod
def get_bet(cards_seen: list[int], deck_number: int) -> int:
"""
Bet 1 every time. The bet doesn't change.
:param cards_seen: The cards we have already seen from the shoe. Used when card counting.
:param deck_number: The number of decks in the starting shoe.
:return: How much money to bet.
"""
return 1
class CardCountBetter(BaseBetter):
"""Change the bet according to the true count."""
@staticmethod
def get_bet(cards_seen: list[int], deck_number: int) -> int:
"""
Bet true_count ^ 2 / 2 if true_count >= +1 else 1. Cap at 15 (using a 1-15 spread).
:param cards_seen: The cards we have already seen from the shoe. Used when card counting.
:param deck_number: The number of decks in the starting shoe.
:return: How much money to bet.
"""
running_count = get_hilo_running_count(cards_seen)
cards_left = deck_number * 52 - len(cards_seen) - 1
true_count = running_count / (cards_left / 52)
if true_count >= 2:
return max(min(int(true_count ** 2 / 2), 15), 1)
return 1