示例#1
0
 def test_illegal_M_value(self):
   try:
     gs = GameSimulator("nim", G=1, P=1, M=0, N=10, K=0, verbose=False)
     # Initialization did not throw AssertionError: Test failed
     self.assertTrue(False)
   except AssertionError:
     # Initialization threw AssertionError: Test passed
     self.assertTrue(True)
示例#2
0
 def test_illegal_P_value(self):
   try:
     gs = GameSimulator("ledge", G=-1, B=[2, 2, 0, 1, 0, 2, 0, 0, 1, 0], P=5, M=100, verbose=False)
     # Initialization did not throw AssertionError: Test failed
     self.assertTrue(False)
   except AssertionError:
     # Initialization threw AssertionError: Test passed
     self.assertTrue(True)
示例#3
0
 def test_illegal_game_value(self):
   try:
     gs = GameSimulator("this is an illegal value for game", G=100, B=[0, 0, 0, 1, 0, 2, 0, 0, 1, 0], P=1, M=100, verbose=False)
     # Initialization did not throw AssertionError: Test failed
     self.assertTrue(False)
   except AssertionError:
     # Initialization threw AssertionError: Test passed
     self.assertTrue(True)
示例#4
0
class PlayoffSimulator(object):
    game_simulator = GameSimulator()
    series_simulator = SeriesSimulator(game_simulator)

    # simulate conference
    def sim_conference(self, seed1, seed2, seed3, seed4, seed5, seed6, seed7,
                       seed8):
        # round 1
        r1_w1 = self.series_simulator.simulate_series(seed1, seed8)
        r1_w2 = self.series_simulator.simulate_series(seed2, seed7)
        r1_w3 = self.series_simulator.simulate_series(seed3, seed6)
        r1_w4 = self.series_simulator.simulate_series(seed4, seed5)

        # round 2
        r2_w1 = self.series_simulator.simulate_series(r1_w1, r1_w4)
        r2_w2 = self.series_simulator.simulate_series(r1_w2, r1_w3)

        # round 3 (conference finals)
        conf_champ = self.series_simulator.simulate_series(r2_w1, r2_w2)

        return conf_champ

    def sim_playoffs(self, east_teams, west_teams):
        # simulate conferences
        east_champ = self.sim_conference(east_teams[0], east_teams[1],
                                         east_teams[2], east_teams[3],
                                         east_teams[4], east_teams[5],
                                         east_teams[6], east_teams[7])
        west_champ = self.sim_conference(west_teams[0], west_teams[1],
                                         west_teams[2], west_teams[3],
                                         west_teams[4], west_teams[5],
                                         west_teams[6], west_teams[7])

        # simulate stanley cup final

        # for simulation purposes, determine home ice with a coin flip
        flip = np.random.uniform(0, 1, 1)

        if (flip[0] < 0.5):
            champ = self.series_simulator.simulate_series(
                east_champ, west_champ)
        else:
            champ = self.series_simulator.simulate_series(
                west_champ, east_champ)

        return champ
示例#5
0
def run():
    gs = GameSimulator(game="nim",
                       G=10,
                       P=1,
                       M=500,
                       N=10,
                       K=3,
                       c=1,
                       verbose=True)

    # gs = GameSimulator(
    #   game="ledge",
    #   G=10,
    #   B=[0, 0, 0, 1, 0, 2, 0, 0, 1, 0],
    #   P=1,
    #   M=500,
    #   c=1,
    #   verbose=True
    # )

    gs.run_batch()
示例#6
0
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('ggplot')

from game_simulator import GameSimulator

# instantiate our core game simulator
game_simulator = GameSimulator()

# setup lists used for analysis of results
all_home_goals = []
all_away_goals = []
all_home_wins = []
all_away_wins = []
all_home_OTLs = []
all_away_OTLs = []
all_home_SOLs = []
all_away_SOLs = []

for x in range(0, 10000):
    home_goals, away_goals, home_wins, away_wins, home_OTLs, away_OTLs, home_SOLs, away_SOLs, event_chart = game_simulator.simulate_game_poisson(
        3.6, 3, 3.6, 3, False, False, False)
    all_home_goals.append(home_goals)
    all_away_goals.append(away_goals)
    all_home_wins.append(home_wins)
    all_away_wins.append(away_wins)
    all_home_OTLs.append(home_OTLs)
    all_away_OTLs.append(away_OTLs)
    all_home_SOLs.append(home_SOLs)
    all_away_SOLs.append(away_SOLs)
示例#7
0
from utils import init_logger, load_config
from game_simulator import GameSimulator

if __name__ == '__main__':
    init_logger()
    config = load_config("configs/config.yaml")
    game_simulator = GameSimulator(config["Game Simulator"])
    game_simulator.simulate()