Example #1
0
def test_charts(basic_player):
    game = Game([basic_player])
    game.simulate(10000)
    # heatmap
    chart = result_heatmap(basic_player.history)
    # outcome bars
    chart = outcome_bars(basic_player.history)
Example #2
0
def test_data():
    """
    A few sanity check on the data we collect
    """
    p = Player(100)
    game = Game([p])
    game.simulate(100)
    data = pd.DataFrame(p.history)
    assert data["num_hard_aces"].min() >= 0
    assert data["num_aces"].max() >= 0
    assert np.all(data["num_hard_aces"] <= data["num_aces"])
    assert np.all(data["num_aces"] <= data["num_cards"])
Example #3
0
def test_simulation():
    game = Game([Player(100)])
    game.simulate(10)
from py21 import Game, Player
from py21.utils import result_heatmap, outcome_bars
from py21.strategies import hit_to_seventeen
from embedplots import add_plots
from pathlib import Path

CUR_PATH = Path(__file__).resolve().parent
random.seed(409)

bankroll = 1000000
# create first player
player = Player(bankroll)
# first game
game = Game([player])
rounds = 1000000
game.simulate(rounds)

# create heatmap
heat = result_heatmap(player.history, result="win", title="Winning Pct")
heat_path = Path(CUR_PATH, "heatmap.html")
heat.save("heatmap.html")
heat.save("../images/heatmap.json")

# second game
player = Player(bankroll)
player2 = Player(bankroll, strategy_func=hit_to_seventeen)

game2 = Game([player, player2])
game2.simulate(rounds)
# create outcome bar graph
outcome = outcome_bars([player.history, player2.history],