def sim_and_rank_seasons(lineup, num_rotations=2): ordered_seasons = [] # stores seasons in descending order by runs/game counter = 0 lineup_copy = lineup[:] while counter < num_rotations: # generate random rotation shuffle(lineup_copy) # test all 9 possible orders of given rotation for i in range(9): lineup_copy.append(lineup_copy.pop(0)) # place first batter at end s = Season(lineup=deepcopy(list(lineup_copy)), num_games=162) s.play_season() ordered_seasons.append(s) #print to terminal so people don't freak out waiting for simulations to end sys.stdout.write("\rSeasons Simulated: %d/%d" % (i+counter*9+1, num_rotations*9)) sys.stdout.flush() counter += 1 ordered_seasons.sort(key=lambda s: s.get_runs_per_game()) sys.stdout.write("\n") return ordered_seasons
def sim_and_rank_seasons(lineup, num_rotations=2): ordered_seasons = [] # stores seasons in descending order by runs/game counter = 0 lineup_copy = lineup[:] while counter < num_rotations: # generate random rotation shuffle(lineup_copy) # test all 9 possible orders of given rotation for i in range(9): lineup_copy.append(lineup_copy.pop(0)) # place first batter at end s = Season(lineup=deepcopy(list(lineup_copy)), num_games=162) s.play_season() ordered_seasons.append(s) #print to terminal so people don't freak out waiting for simulations to end sys.stdout.write("\rSeasons Simulated: %d/%d" % (i + counter * 9 + 1, num_rotations * 9)) sys.stdout.flush() counter += 1 ordered_seasons.sort(key=lambda s: s.get_runs_per_game()) sys.stdout.write("\n") return ordered_seasons