예제 #1
0
    def onStartButton(self):

        if self.started == True:
            result = tkMessageBox.askquestion("Restart?",
                                              "Are You Sure?",
                                              icon='warning')
            if result == 'no':
                return 0
            else:
                self.count = 0
                self.updateCount()
                self.countData = []
                sq = 10 * 20
                for x in range(0, sq, 20):
                    for y in range(0, sq, 20):
                        if (x % 20 == 0) and (y % 20 == 0):
                            self.canvas1.create_rectangle(x,
                                                          y,
                                                          x + 20,
                                                          y + 20,
                                                          fill="white")

        self.death = self.builder.get_object('deathScale').get()
        self.div = self.builder.get_object('divScale').get()
        self.functions = self.builder.get_object('funcSpin').get()
        self.c = ca.ca(10, int(self.functions), self.death, self.div)
        for i in range(5):
            r = random.randint(0, 9)
            r2 = random.randint(0, 9)
            self.c.set(r, r2, 1)
        self.started = True
예제 #2
0
 def start(self):
     self.brush_start = 33
     self.stdscr = curses.initscr()
     self.stdscr.keypad(1)
     (self.max_y,self.max_x) = self.stdscr.getmaxyx()
     self.cb = cursebuf(self.max_y-1)
     self.ca = ca(self.max_x)
     self.info_win = infobox(30, 4, 0, 0)
     curses.start_color()
     curses.noecho()
     curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
     curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
예제 #3
0
 def start(self):
     self.brush_start = 33
     self.stdscr = curses.initscr()
     self.stdscr.keypad(1)
     (self.max_y, self.max_x) = self.stdscr.getmaxyx()
     self.cb = cursebuf(self.max_y - 1)
     self.ca = ca(self.max_x)
     self.info_win = infobox(30, 4, 0, 0)
     curses.start_color()
     curses.noecho()
     curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
     curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
예제 #4
0
def runGame():
    global is_running, DIRECTION, ca_over, human_over
    ca_player = ca.ca(CELLWIDTH, CELLHEIGHT)
    ca_over = False
    human_over = False
    dqn_over = False
    cnn = snakedqn.DQN(0.99, 0, 0.001, 0.001, 50000, 32, 4)
    # Set a random start point.
    startx = random.randint(0, CELLWIDTH - 5)
    starty = random.randint(0, CELLHEIGHT - 5)
    ca_snakeCoords = [{
        'x': startx,
        'y': starty
    }, {
        'x': startx - 1,
        'y': starty
    }, {
        'x': startx - 2,
        'y': starty
    }]
    hu_snakeCoords = [{
        'x': startx,
        'y': starty
    }, {
        'x': startx - 1,
        'y': starty
    }, {
        'x': startx - 2,
        'y': starty
    }]
    dqn_snakeCoords = [{
        'x': startx,
        'y': starty
    }, {
        'x': startx - 1,
        'y': starty
    }, {
        'x': startx - 2,
        'y': starty
    }]
    ca_direction = RIGHT
    hu_direction = RIGHT
    is_running = True

    #food = getRandomLocation(ca_snakeCoords)
    food_list = get_food_list()
    hu_food = food_list[0]
    food = food_list[0]
    dqn_food = food_list[0]
    drawSnaky(game_screen, dqn_snakeCoords, player_dqn)
    image_data = pygame.surfarray.array3d(
        pygame.display.get_surface())[WINDOWWIDTH:WINDOWWIDTH * 2]
    op = dqn_operator(dqn_snakeCoords, food, cnn, image_data, food_list)

    while True:
        if human_over == False:
            clock.tick(FPS + len(hu_snakeCoords) - 3)
        else:
            clock.tick(10)
        pressed = checkForKeyPress()
        if ca_over and human_over and dqn_over:
            if pressed != None:
                return
        if full(game_screen, ca_snakeCoords, food) == True:
            ca_over = True
        if full(game_screen, hu_snakeCoords, hu_food) == True:
            human_over = True
        if full(game_screen, dqn_snakeCoords, dqn_food) == True:
            dqn_over = True
        #print("run")
        for event in pygame.event.get():
            if event.type == QUIT:
                terminate()

        if ca_over == False:
            ca_direction = ca_player.ca_operation(ca_snakeCoords, food,
                                                  ca_direction)
            if ca_direction == -1 or ca_direction == None:
                ca_over = True
            #make move
            else:
                coords = player_update(ca_snakeCoords, food, ca_direction,
                                       food_list)
                ca_snakeCoords = coords[0]
                food = coords[1]

        if human_over == False:
            hu_direction = hu.human_operation(hu_direction, hu_snakeCoords,
                                              pressed, CELLWIDTH, CELLHEIGHT)
            if hu_direction == -1:
                human_over = True
            else:
                coords = player_update(hu_snakeCoords, hu_food, hu_direction,
                                       food_list)
                hu_snakeCoords = coords[0]
                hu_food = coords[1]

        if dqn_over == False:
            image_data = pygame.surfarray.array3d(
                pygame.display.get_surface())[WINDOWWIDTH:WINDOWWIDTH * 2]
            res = op.dqn_operate(image_data, food_list)
            if res == -1:
                dqn_over = True
            else:
                dqn_direction = res

        game_screen.fill(BGCOLOR)
        #draw
        if ca_over == False:
            drawSnaky(game_screen, ca_snakeCoords, player_ca)
            drawFood(game_screen, food, player_ca)
            drawScore(game_screen, len(ca_snakeCoords) - 3, player_ca)
        else:
            showOver(game_screen, player_ca)

        if human_over == False:
            drawSnaky(game_screen, hu_snakeCoords, player_human)
            drawFood(game_screen, hu_food, player_human)
            drawScore(game_screen, len(hu_snakeCoords) - 3, player_human)
        else:
            showOver(game_screen, player_human)

        if dqn_over == False:
            drawSnaky(game_screen, dqn_snakeCoords, player_dqn)
            drawFood(game_screen, op.food, player_dqn)
            drawScore(game_screen, len(dqn_snakeCoords) - 3, player_dqn)
        else:
            showOver(game_screen, player_dqn)

        pygame.draw.line(game_screen, (0, 0, 0), (300, 0), (300, 300), 2)
        pygame.draw.line(game_screen, (0, 0, 0), (600, 0), (600, 300), 2)

        pygame.display.update()
예제 #5
0
			st.append((p[0]+1,p[1]-1))
		temp.append(st)
	pos.append(temp)

mainLog=open('avgsLog'+str(time.time()),'w')
mapLog=open('mapLog'+str(time.time()),'w')
for curDeath in deathRange:
	for curSpaw in spawRange:
		for func in functions:
			for p in pos:
				for n in p:
					#n averages

					for r in range(runs):

						c=ca.ca(10,func,curDeath,curSpaw)
						if len(n)==1:
							c.set(n[0][0],n[0][1],1)
							#print 1
						elif len(n)>1:
							count=1
							for i in range(len(n)):
								if count==0: 
									count=count+1
								c.set(n[i][0],n[i][1],count)
								count=count+1
								count=count % func
						#run averages
						avgNet0=0
						avgNet1=0
						
예제 #6
0
import random
import matplotlib.pyplot as plt
import sys
import Tkinter






death=float(sys.argv[1])
div=float(sys.argv[2])
steps=int(sys.argv[3])
functions=int(sys.argv[4])

c=ca.ca(10,functions,death,div)


#for i in range(5):
#	r=random.randint(0,9)
#	r2=random.randint(0,9)
#	c.set(r,r2,1)
c.set(4,4,1)
c.set(4,5,1)
c.set(4,6,1)
#c.set(5,5,2)
#c.set(5,6,3)
#c.set(5,6,3)

countData=[]
netData=[]