if evaluation == "win": break elif evaluation == "lose": break else: window.update_view( board.generateState(board.grid) ) window.update_view( board.generateState(board.grid) ) #Feedback about how the game went print "Your best tile is: " + str(int(2 ** board.bestTile)) return int(2 ** board.bestTile) root = Tk() window = GameWindow(root) EPOCHS_PER_GAME = 10 NEURONS_IN_HIDDEN_LAYERS = [17,500,500,4] LIST_OF_FUNCTIONS = ["rectify","rectify","softmax"] LEARNING_RATE = 0.003 MOMENTUM_RATE = 0.9 a = Ann(neuronsInHiddenLayers=NEURONS_IN_HIDDEN_LAYERS, listOfFunctions=LIST_OF_FUNCTIONS, learningRate=LEARNING_RATE, momentumRate=MOMENTUM_RATE, errorFunc=10) for i in range (50): trX, trY = get_data.get_training_data('training/train_data_'+str(i+1)) print "Training on data "+str(i+1) a.training(trX, trY,len(trX)-1,EPOCHS_PER_GAME) random_res = [] #random_res = [128, 128, 256, 64, 256, 128, 64, 64, 32, 64, 128, 128, 128, 128, 128, 128, 64, 128, 64, 128, 128, 64, 64, 64, 64, 128, 128, 128, 64, 128, 128, 128, 128, 128, 128, 128, 32, 128, 256, 64, 64, 128, 64, 64, 64, 128, 128, 64, 128, 64]
from visuals import GameWindow from board import Board from solver import Solver from Tkinter import * import random, sys, copy, time root = Tk() window = GameWindow(root) random_res = [] for i in range(50): board = Board() window.update_view( board.generateState(board.grid) ) solver = Solver(board, window, root) solver.startSolver("random") random_res.append(int(2**board.bestTile)) print random_res '''for i in range(1,50): board = Board() window.update_view( board.generateState(board.grid) ) solver = Solver(board, window, root, train_nr=i) #modes: random, upleftdownright, partialAI, onestepahead solver.startSolver("expectimax")''' # TO PLAY THE GAME, UMCOMMENT THESE LINES ''' while True: window.update_view( board.generateState(board.grid) ) print "POINTS========> > > " + str(board.points) + " < < <========POINTS"
if not alreadyCompleted and gamewon(bestNode.board): gameWonTime = time.time() gametime = gameWonTime - startTime print "######" print "YOU WON! Time elapsed:", gametime / 60.0, " minutes" print "######" print "" alreadyCompleted = True gameBoard.setBoard(bestNode.board) gameBoard.placeRandomTwoOrFour() window.update_view(gameBoard.board) main = Tk() window = GameWindow(main) main.bind('<Left>', leftKey) main.bind('<Right>', rightKey) main.bind('<Up>', upKey) main.bind('<Down>', downKey) main.bind('<KeyRelease>', keyReleased) main.bind('<space>', startAlgorithm) window.pack() gameBoard = initBoard() window.update_view(gameBoard.board) # 1D list representing the board window.mainloop()