Exemple #1
0
        score = game.score() * game.player
        if score > 0:
            win_text = "White Won"
        elif score < 0:
            win_text = "Black Won"
        else:
            win_text = "Draw"

        self.draw_board(game, last_move)
        self.root.configure(cursor="X_cursor")
        self.movemesg.set("Game Over " + win_text)

        # wait for the user to quit the game
        while self.alive:
            self.root.update()
            time.sleep(.1)

        return


if __name__ == "__main__":

    print("""othello_gui, Copyright (C) 2006 Nimar S. Arora
othello_gui comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.""")

    game2.play(othello.game(), game2.player(lambda x: greedy.get_move(x)),
               player(), True)
Exemple #2
0
        score = game.score() * game.player
        if score > 0:
            win_text = "White Won"
        elif score < 0:
            win_text = "Black Won"
        else:
            win_text = "Draw"

        self.draw_board(game, last_move)        
        self.root.configure(cursor="X_cursor")
        self.movemesg.set("Game Over "+win_text)

        # wait for the user to quit the game        
        while self.alive:
            self.root.update()
            time.sleep(.1)

        return

    
if __name__ == "__main__":

    print("""othello_gui, Copyright (C) 2006 Nimar S. Arora
othello_gui comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.""")
    
    game2.play(othello.game(),
               game2.player(lambda x: minimax.alphabeta(x, 4, othello.edge_eval)),
               player(), True)
import ntuplesystematic as nts
import time
import random
import numpy
import nn

populationsize=10
goodpopulationsize=5
generations=5
parent = []
child = [0]*populationsize

for i in range(populationsize):
		playermaxx = nn.nn()
		for j in range(200):
			game2.play(othello.game(), game2.player(lambda x: playermaxx.play_move(x,0.3)),game2.player(lambda x: playermaxx.play_move(x,0.3)), False)
			playermaxx.reset()
		parent.append(playermaxx)


for z in range(generations):
	win = []
	for i in range(populationsize):
		winsfori=0
		for j in range(100):
			winner = game2.play(othello.game(), game2.player_epsilon(lambda x: parent[i].play_move(x)),game2.player_epsilon(lambda x: nTuplesSystematicObject.play_next_move(x)), False)
			if winner == 1:
				winsfori += 1
			winner = game2.play(othello.game(),game2.player_epsilon(lambda x: nTuplesSystematicObject.play_next_move(x)), game2.player_epsilon(lambda x: parent[i].play_move(x)), False)
			if winner == 2:
				winsfori += 1
Exemple #4
0
 def simulate(self, start_state):
     result, _ = game2.play(start_state, game2.player(lambda x: self.sim_policy(x)), game2.player(lambda x: self.sim_policy(x)), False)
     return result
            print 'PLAYER 1: algorithm', args.p1

    if args.p2:
        # Si nos dan el nombre del algoritmo del jugador 2,
        # obtener su índice y mostrar información.
        algorithmP2 = ai.ALGORITHM_NAMES.index(args.p2)
        if algorithmP2 >= ai.ALGORITHM_MINIMAX_DEEP:
            print 'PLAYER 2: algorithm', args.p2, 'with deep', args.d2
        else:
            print 'PLAYER 2: algorithm', args.p2

    if args.p1 and args.p2:
        # Si nos dan el nombre del algoritmo de los jugadores 1 y 2,
        # comenzar partida entre ambos algoritmos.
        game2.play(othello.game(),
                   game2.player(lambda x: ai.selector(
                       x, algorithmP1, args.d1)),
                   game2.player(lambda x: ai.selector(
                       x, algorithmP2, args.d2)),
                   args.v)
    elif args.p1:
        # Si solo nos dan el nombre del algoritmo del jugador 1,
        # comenzar partida contra el usuario.
        game2.play(othello.game(),
                   game2.player(lambda x: ai.selector(
                       x, algorithmP1, args.d1)),
                   player(),
                   args.v)
    else:
        # Si no nos dan nada, mostrar la ayuda
        parser.print_help()
	def reset_without_train(self):
		self.moveb = 0
		self.movew = 0
		self.last_vb = 0
		self.last_vw = 0
		self.fin_v = []
		self.fin_val = []

if __name__ == "__main__":
	"""
	Creates a main player
	"""
	playernew = nn()
	nTuplesSystematicObject = nts.nTuplesSystematic()
	game2.play(othello.game(), game2.player(lambda x: playernew.play_move(x)),game2.player(lambda x: nTuplesSystematicObject.play_next_move(x)), True)
	playernew.reset_without_train()
	time.sleep(5)
	k = 100
	for i in range(k):
		print(i)
		game2.play(othello.game(), game2.player(lambda x: playernew.play_move(x,0.3)),game2.player(lambda x: playernew.play_move(x,0.3)), False)
		playernew.reset()

	wins = [0, 0]
	for i in range(100):
		winner = game2.play(othello.game(), game2.player_epsilon(lambda x: playernew.play_move(x)),game2.player_epsilon(lambda x: nTuplesSystematicObject.play_next_move(x)), False)
		if winner == 1:
			wins[0] += 1
		elif winner == 2:
			wins[1] += 1
Exemple #7
0
 def simulate(self, start_state):
     result, _ = game2.play(start_state,
                            game2.player(lambda x: self.sim_policy(x)),
                            game2.player(lambda x: self.sim_policy(x)),
                            False)
     return result
Exemple #8
0
        score = game.score() * game.player
        if score > 0:
            win_text = "White Won"
        elif score < 0:
            win_text = "Black Won"
        else:
            win_text = "Draw"

        self.draw_board(game, last_move)        
        self.root.configure(cursor="X_cursor")
        self.movemesg.set("Game Over "+win_text)

        # wait for the user to quit the game        
        while self.alive:
            self.root.update()
            time.sleep(.1)

        return

    
if __name__ == "__main__":

    print """othello_gui, Copyright (C) 2006 Nimar S. Arora
othello_gui comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions."""

    game2.play(othello.game(), player(), game2.player(lambda x: minimax.alphabeta(x, 3, othello.positional_eval)), True)

Exemple #9
0
    ## Rich's playing around with functions....
    #game2.play(othello.game(), game2.player(lambda x: minimax.minimax(x, 3)), game2.player(lambda x: random_move_policy(x)), True)

    #t = UCT_tree.Tree(5, random_policy, 1)
    #game2.play(othello.game(), game2.player(lambda x: minimax.minimax(x, 3)), game2.player(t.policy), True)
    #game2.play(othello.game(), game2.player(t.policy), game2.player(lambda x: minimax.minimax(x, 4)), True)

    policies = {"random": random_policy}  #, "greedy": greedy_policy}
    budgets = [1]
    c_vals = [1, 5]  #, 20, 50]
    # opponents = {"random": game2.player(random_policy),
    #              "greedy": game2.player(greedy_policy),
    #              "minimax-2": game2.player(lambda x: minimax.minimax(x, 2)),
    #              "minimax-3": game2.player(lambda x: minimax.minimax(x, 3)),
    #              "minimax-4": game2.player(lambda x: minimax.minimax(x, 4))}
    opponents = {"minimax-4": game2.player(lambda x: minimax.minimax(x, 4))}
    # number of games going first/second with each configuration
    n = 10

    # run this algorithm with different hard-coded sizes
    # for each policy
    # for each budget (i.e. 1,2,5 seconds)
    # for each opponent
    # run n trials with us first, n trials with them first

    for pol_key in policies:
        for b in budgets:
            for c in c_vals:
                for opp_key in opponents:
                    t = UCT_tree.Tree(b, policies[pol_key], c)
                    uct_player = game2.player(t.policy)
	"""
	if game_elem==-1:
		return 2
	elif game_elem==1:
		return 0
	else:
		return 1


if __name__ == "__main__":
	"""
	Creates a main player
	"""
	nTuplesSystematicObject = nTuplesSystematic()

	# nTuplesSystematic - Black
	# Minimax - White
	# game2.play(othello.game(),game2.player(lambda x: nTuplesSystematicObject.play_next_move(x)), game2.player(lambda x: minimax.minimax(x, 0)), False)

	# Minimax - Black
	# nTuplesSystematic - White
	# game2.play(othello.game(), game2.player(lambda x: minimax.minimax(x, 0)),game2.player(lambda x: nTuplesSystematicObject.play_next_move(x)),False)

	# nTuplesSystematic - Black
	# Minimax Edge Eval - White
	# game2.play(othello.game(),game2.player(lambda x: nTuplesSystematicObject.play_next_move(x)), game2.player(lambda x: minimax.minimax(x, 0,othello.edge_eval)), True)
	
	# Minimax Edge Eval - Black
	# nTuplesSystematic - White
	game2.play(othello.game(), game2.player(lambda x: minimax.minimax(x, 0,othello.edge_eval)),game2.player(lambda x: nTuplesSystematicObject.play_next_move(x)), True)
Exemple #11
0
        if score > 0:
            win_text = "White Won"
        elif score < 0:
            win_text = "Black Won"
        else:
            win_text = "Draw"

        self.draw_board(game, last_move)
        self.root.configure(cursor="X_cursor")
        self.movemesg.set("Game Over " + win_text)

        # wait for the user to quit the game
        while self.alive:
            self.root.update()
            time.sleep(.1)

        return


if __name__ == "__main__":

    print("""othello_gui, Copyright (C) 2006 Nimar S. Arora
othello_gui comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.""")

    game2.play(
        othello.game(),
        game2.player(lambda x: minimax.alphabeta(x, 4, othello.edge_eval)),
        player(), True)
Exemple #12
0
    ## Rich's playing around with functions....
    #game2.play(othello.game(), game2.player(lambda x: minimax.minimax(x, 3)), game2.player(lambda x: random_move_policy(x)), True)

    #t = UCT_tree.Tree(5, random_policy, 1)
    #game2.play(othello.game(), game2.player(lambda x: minimax.minimax(x, 3)), game2.player(t.policy), True)
    #game2.play(othello.game(), game2.player(t.policy), game2.player(lambda x: minimax.minimax(x, 4)), True)

    policies = {"random": random_policy}#, "greedy": greedy_policy}
    budgets = [1]
    c_vals = [1, 5]#, 20, 50]
    # opponents = {"random": game2.player(random_policy),
    #              "greedy": game2.player(greedy_policy),
    #              "minimax-2": game2.player(lambda x: minimax.minimax(x, 2)),
    #              "minimax-3": game2.player(lambda x: minimax.minimax(x, 3)),
    #              "minimax-4": game2.player(lambda x: minimax.minimax(x, 4))}
    opponents = {"minimax-4": game2.player(lambda x: minimax.minimax(x, 4))}
    # number of games going first/second with each configuration
    n = 10

    # run this algorithm with different hard-coded sizes
    # for each policy
        # for each budget (i.e. 1,2,5 seconds)
            # for each opponent
                # run n trials with us first, n trials with them first
    
    for pol_key in policies:
        for b in budgets:
            for c in c_vals:
                for opp_key in opponents:
                    t = UCT_tree.Tree(b, policies[pol_key], c)
                    uct_player = game2.player(t.policy)