def evaluate():
	wins = [0, 0]
	for i in range(100):
		player1 = randomPlayer()
		player2 = nTuplesSystematic()
		winner = game2.play(othello.game(), game2.player_epsilon(lambda x: player1.play_next_move(x)),game2.player_epsilon(lambda x: player2.play_next_move(x)), False)
		if winner == 1:
			wins[0] += 1
		elif winner == 2:
			wins[1] += 1
		winner = game2.play(othello.game(),game2.player_epsilon(lambda x: player2.play_next_move(x)), game2.player_epsilon(lambda x: player1.play_next_move(x)), False)
		if winner == 2:
			wins[0] += 1
		elif winner == 1:
			wins[1] += 1

	print wins
Example #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: greedy.get_move(x)),
               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
Example #4
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)
    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()
Example #6
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
Example #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
Example #8
0
	def play(self, verbose = True):
		return play(self.game, self.player1, self.player2, verbose)
Example #9
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)

Example #10
0
    # 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)
                    uct_black = []
                    uct_white = []
                    for i in range(n):
                        b_result, b_game = game2.play(othello.game(),
                                                      uct_player,
                                                      opponents[opp_key],
                                                      False)
                        uct_black.append(b_result)
                        #print b_game
                        w_result, w_game = game2.play(othello.game(),
                                                      opponents[opp_key],
                                                      uct_player, False)
                        uct_white.append(w_result)
                        #print w_game
                    print("Average score over " + str(n) +
                          "trials for default policy " + str(pol_key) +
                          ", budget " + str(b) + ", c = " + str(c) +
                          ", opponent " + str(opp_key) + ":")
                    print("Results as black (positive = we win):")
                    print(str(average(uct_black)))
                    print("Results as white (negative = we win):")
	"""
	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)
Example #12
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)
Example #13
0
    # 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)
                    uct_black = []
                    uct_white = []
                    for i in range(n):
                        b_result, b_game = game2.play(othello.game(), uct_player, opponents[opp_key], False)
                        uct_black.append(b_result)
                        #print b_game
                        w_result, w_game = game2.play(othello.game(), opponents[opp_key], uct_player, False)
                        uct_white.append(w_result)
                        #print w_game
                    print("Average score over " + str(n) + "trials for default policy " + str(pol_key) + ", budget " + str(b) + ", c = " + str(c) + ", opponent " + str(opp_key) + ":")
                    print("Results as black (positive = we win):")
                    print(str(average(uct_black)))
                    print("Results as white (negative = we win):")
                    print(str(average(uct_white)))