コード例 #1
0
def trainingFactor(initialValue, adjustingSize, trainingTimes, numOfValues):

	RaisedPlayer.raiseThreshold = initialValue	
	maxValue = 0
	for j in range(0, numOfValues):
		totalResult = 0
		print("The factor:", RaisedPlayer.raiseThreshold)

		for k in range(0, trainingTimes):
			config = setup_config(max_round=100, initial_stack=10000, small_blind_amount=10)
			# config.register_player(name="call_player", algorithm=CallPlayer())
			# config.register_player(name="random", algorithm=RandomPlayer())
			config.register_player(name="runable", algorithm=RaisedPlayer())
			config.register_player(name="search", algorithm=SearchPlayer())
			game_result = start_poker(config, verbose=1)
			print game_result
			totalResult += game_result['players'][0]['stack'] 
			
			# To change the variables of the function	
	
		# print("The factor:", AlphaBeta.factors[0])
		aveResult = totalResult/trainingTimes
		print("The aveResult:", aveResult)
		maxValue = max(aveResult, maxValue)
		if (aveResult == maxValue): 
			optimalFactor = RaisedPlayer.raiseThreshold
		print("Current Max", maxValue, "current optimalFactor:", optimalFactor)
		trainingResult = "raiseThreshold value:" + str(RaisedPlayer.raiseThreshold) + "aveResult:" + str(aveResult) 
		import cPickle
		result = open('trainingResult' + ' raiseThreshold' + str(RaisedPlayer.raiseThreshold)+ '.pkl', 'w')
		cPickle.dump(trainingResult, result)
		print game_result
		RaisedPlayer.raiseThreshold += adjustingSize
	return optimalFactor
コード例 #2
0
ファイル: testperf.py プロジェクト: weiqing-nic/poker-ai
def testperf(agent_name1, agent1, agent_name2, agent2):

    # Init to play 500 games of 1000 rounds
    num_game = 500
    max_round = 1000
    initial_stack = 10000
    smallblind_amount = 20

    # Init pot of players
    agent1_pot = 0
    agent2_pot = 0

    # Setting configuration
    config = setup_config(max_round=max_round,
                          initial_stack=initial_stack,
                          small_blind_amount=smallblind_amount)

    # Register players
    config.register_player(name=agent_name1, algorithm=RandomPlayer())
    config.register_player(name=agent_name2, algorithm=RaisedPlayer())
    # config.register_player(name=agent_name1, algorithm=agent1())
    # config.register_player(name=agent_name2, algorithm=agent2())

    # Start playing num_game games
    for game in range(1, num_game + 1):
        print("Game number: ", game)
        game_result = start_poker(config, verbose=0)
        agent1_pot = agent1_pot + game_result['players'][0]['stack']
        agent2_pot = agent2_pot + game_result['players'][1]['stack']

    print("\n After playing {} games of {} rounds, the results are: ".format(
        num_game, max_round))
    # print("\n Agent 1's final pot: ", agent1_pot)
    print("\n " + agent_name1 + "'s final pot: ", agent1_pot)
    print("\n " + agent_name2 + "'s final pot: ", agent2_pot)

    # print("\n ", game_result)
    # print("\n Random player's final stack: ", game_result['players'][0]['stack'])
    # print("\n " + agent_name + "'s final stack: ", game_result['players'][1]['stack'])

    if (agent1_pot < agent2_pot):
        print("\n Congratulations! " + agent_name2 + " has won.")
    elif (agent1_pot > agent2_pot):
        print("\n Congratulations! " + agent_name1 + " has won.")
        # print("\n Random Player has won!")
    else:
        Print("\n It's a draw!")
コード例 #3
0
from pypokerengine.api.game import setup_config, start_poker
from raise_player import RaisedPlayer
from call_player import CallPlayer
from randomplayer import RandomPlayer
from nino_with_c import RTPlayer
import pprint
import matplotlib.pyplot as plt

#TODO:config the config as our wish
rtplayer = RTPlayer()
for i in range(15):
    config = setup_config(max_round=1000,
                          initial_stack=10000,
                          small_blind_amount=10)
    config.register_player(name="f1", algorithm=RaisedPlayer())
    config.register_player(name="FT2", algorithm=rtplayer)

    game_result = start_poker(config, verbose=0)
    pp = pprint.PrettyPrinter(indent=0)

    pp.pprint(game_result)
    pp.pprint(rtplayer.step_theta)

y_val_list = rtplayer.get_result()
print(len(y_val_list))
x_val_list = list(range(1, len(y_val_list) + 1))
print(len(x_val_list))
plt.scatter(x_val_list, y_val_list, s=10)

plt.title("Result ")
plt.xlabel("Number")
コード例 #4
0
from pypokerengine.api.game import setup_config, start_poker
from randomplayer import RandomPlayer
from raise_player import RaisedPlayer
from rate_player import RatePlayer
from all_raise_player import AllRaisePlayer
from search_player import SearchPlayer
from simulation_player import ProbabilityPlayer

# config.register_player(name="call_player", algorithm=CallPlayer())
# config.register_player(name="random", algorithm=RandomPlayer())
RaisedPlayer = RaisedPlayer()

for i in range(20):
	config = setup_config(max_round=10, initial_stack=10000, small_blind_amount=10)
	config.register_player(name="runable", algorithm=RaisedPlayer)
	config.register_player(name="allraise", algorithm=AllRaisePlayer())
	#TODO:config the config as our wish
	game_result = start_poker(config, verbose=1)
	print RaisedPlayer.root
	import cPickle
	# result = open('result' + str(i) + '.pkl', 'w')
	# cPickle.dump(RaisedPlayer.result, result)
	print RaisedPlayer.result
	ouf = open('tree.pkl', 'w')
	cPickle.dump(RaisedPlayer.tree, ouf)
	print game_result
コード例 #5
0
from pypokerengine.api.game import setup_config, start_poker
from randomplayer import RandomPlayer
from raise_player import RaisedPlayer
from CFRAgent import CFRAgent

#TODO:config the config as our wish
config = setup_config(max_round=10, initial_stack=10000, small_blind_amount=10)

config.register_player(name="AlwaysRaisedPlayer", algorithm=RaisedPlayer())
config.register_player(name="CFRAgent", algorithm=CFRAgent())

game_result = start_poker(config, verbose=1)