Exemple #1
0
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
Exemple #2
0
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)									
Exemple #3
0
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)
Exemple #4
0
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)
Exemple #5
0
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)))
Exemple #6
0
	def __init__(self, p1strat=strategy.StaticStrategy(4,5), p2strat=strategy.StaticStrategy(4,5)):
		self.p1 = Player("P1", p1strat)
		self.p2 = Player("P2", p2strat)
		self.pstatic = self.p1
		self.pevolve = self.p2
		self.first_player = self.p1
		self.second_player = self.p2
		self.last_winner = self.p1
		self.last_looser = self.p2

		self.river = []
		self.pot = 0
		self.MIN_BET = 1
		self.round_end_flag = False
		self.tie_flag = True
		self.deck = Deck()
		self.consec_ties = 0
Exemple #7
0
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)
Exemple #8
0
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