def compare_vanilla_genetic_search_with_GMAB2(): print("session length:", PLAY_SESSION_LENGTH) print("sessions to play for each combine_formula:", SESSIONS_TO_PLAY) print() # Simulates PLAY_SESSION_LENGTH*SESSIONS_TO_PLAY rounds of Shape Poker and takes data on how much money player `pevolve` earned over time. for seed in seeds: print("\n\nseed", seed, "\n") random.seed(seed) gamelin = ShapePoker(strategy.StaticStrategy(4,5), strategy.GeneticSearch(4,5, combine_formula=strategy.linear_combine)) gameari = ShapePoker(strategy.StaticStrategy(4,5), strategy.GeneticSearch(4,5, combine_formula=strategy.arithmetic_combine)) gamepyth = ShapePoker(strategy.StaticStrategy(4,5), strategy.GeneticSearch(4,5, combine_formula=strategy.pythagorean_combine)) # GMAB shines in situations where our computational resources are constrained such that we are afforded only a # a certain number of evolution cycles. gameGMAB = ShapePoker(strategy.StaticStrategy(4,5), strategy.GMAB(4,5)) print("linear") money_v_t(gamelin, sessions=SESSIONS_TO_PLAY) print("\narithmetic") money_v_t(gameari, sessions=SESSIONS_TO_PLAY) print("\npythagorean") money_v_t(gamepyth, sessions=SESSIONS_TO_PLAY) print("\nGMAB") money_v_t(gameGMAB, sessions=SESSIONS_TO_PLAY) rounds_by_population(gameGMAB)
def example_rounds(seeds=SEEDS): # play five rounds of two strategies playing against one another. print("seed", seeds[0]) random.seed(seeds[0]) alfred.DEBUG = True ShapePoker(strategy.StaticStrategy(4,5), strategy.StaticStrategy(4,5)).play(5) alfred.DEBUG = False
def river_score_vs_average_holding_score(seeds=SEEDS, n=1000): for s in seeds: print("\nseed\n", s) print("playing", n, "rounds") random.seed(s) game = ShapePoker(strategy.StaticStrategy(4,5), strategy.StaticStrategy(4,5)) vic, fre, res, rf, nt = count_stats(game, n) d = sorted(res.items(), key=lambda s: s[1]) print(d)
def frequency_of_hand_score(seeds=SEEDS, n=1000): for s in seeds: print("\nseed\n", s) print("playing", n, "rounds") random.seed(s) game = ShapePoker(strategy.StaticStrategy(4,5), strategy.StaticStrategy(4,5)) vic, fre, res, rf, nt = count_stats(game, n) d = sorted([(k, fre[k]/nt) for k in fre], key=lambda s: s[0]) print(d)
def win_rate(seeds=SEEDS, n=1000, strat=strategy.StaticStrategy): # Make two random, unchanging `Strategy`s and have them battle a session of `n` rounds # What % of the time does the evolving player win? for s in seeds: print("\nseed\n", s) print("win rate after", n, "rounds") random.seed(s) game = ShapePoker(strategy.StaticStrategy(4,5), strat(4,5)) vic, fre, res, rf, nt = count_stats(game, n) d = sum(vic.values()) / sum(fre.values()) print(d) return d
def benchmark_static_search_strategy(seeds=SEEDS): # For each seed, # Pits an evolving player against a non-evolving player. # Outputs score and gives the evolving player feedback after each session # See example_rounds() to see a sample of what a 'session' of ShapePoker looks like print("session length:", PLAY_SESSION_LENGTH) print("sessions to play:", SESSIONS_TO_PLAY) print() # Simulates PLAY_SESSION_LENGTH*SESSIONS_TO_PLAY rounds of Shape Poker and takes data on how much money player `pevolve` earned over time. for seed in seeds: print("\n\nseed", seed, "\n") random.seed(seed) gamelin = ShapePoker(strategy.StaticStrategy(4,5), strategy.StaticStrategy(4,5)) print("linear") money_v_t(gamelin, sessions=SESSIONS_TO_PLAY)
def compare_combine_formulas(seeds=SEEDS): # tabulates the final scores of the evolving players using each combine formula # plays one session of PlAY_SESSION_LENGTH rounds per seed per formula for s in seeds: print("\n\nseed",s,"\n") random.seed(s) gamelin = ShapePoker(strategy.StaticStrategy(4,5), strategy.GeneticSearch(4,5, combine_formula=strategy.linear_combine)) gameari = ShapePoker(strategy.StaticStrategy(4,5), strategy.GeneticSearch(4,5, combine_formula=strategy.arithmetic_combine)) gamepyth = ShapePoker(strategy.StaticStrategy(4,5), strategy.GeneticSearch(4,5, combine_formula=strategy.pythagorean_combine)) gamelin.play(PLAY_SESSION_LENGTH) gameari.play(PLAY_SESSION_LENGTH) gamepyth.play(PLAY_SESSION_LENGTH) print (repr(("Linear",gamelin.pevolve.money))) print(repr(("Arithmetic",gameari.pevolve.money))) print(repr(("Pythagorean",gamepyth.pevolve.money)))