Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated for Python3 and fixed a bug #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,8 @@ Ultimately, the results obtained here demonstrate the usefulness of convolutiona
[3] Gerald Tesauro. Temporal difference learning and td-gammon. Communications of the ACM, 38(3):58–68, 1995.

[4] Martin Riedmiller. Neural fitted q iteration–first experiences with a data efficient neural reinforcement learning method. In Machine Learning: ECML 2005, pages 317–328. Springer, 2005.


## 9. installation

[python2 pygame installer](http://www.pygame.org/ftp/pygame-1.9.2pre-py2.7-macosx10.7.mpkg.zip)
Binary file added Raw Game Code/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions Raw Game Code/Mario_Level_1
Submodule Mario_Level_1 added at 28c0d6
4 changes: 4 additions & 0 deletions Raw Game Code/mario.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from Mario_Level_1 import mario_level_1

if __name__ == '__main__':
mario_level_1.run_game()
4 changes: 4 additions & 0 deletions Raw Game Code/mario.py~
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from Mario-Level-1 import mario_level_1

if __name__ == '__main__':
mario_level_1.run_game()
4 changes: 2 additions & 2 deletions Raw Game Code/pong.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
bar2 = bar.convert()
bar2.fill((255,255,255))
circ_sur = pygame.Surface((15,15))
circ = pygame.draw.circle(circ_sur,(255,255,255),(15/2,15/2),15/2)
circ = pygame.draw.circle(circ_sur,(255,255,255),(15//2,15//2),15//2)
circle = circ_sur.convert()
circle.set_colorkey((0,0,0))

Expand Down Expand Up @@ -73,7 +73,7 @@

# movement of circle
time_passed = clock.tick(30)
time_sec = time_passed / 1000.0
time_sec = time_passed // 1000.0

circle_x += speed_x * time_sec
circle_y += speed_y * time_sec
Expand Down
Empty file.
Binary file added Raw Game Code/testing/__init__.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions Raw Game Code/testing/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

def hi():
print "hello"
Binary file added Raw Game Code/testing/test.pyc
Binary file not shown.
12 changes: 6 additions & 6 deletions Raw Game Code/tetris.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
MOVESIDEWAYSFREQ = 0.15
MOVEDOWNFREQ = 0.1

XMARGIN = int((WINDOWWIDTH - BOARDWIDTH * BOXSIZE) / 2)
XMARGIN = int((WINDOWWIDTH - BOARDWIDTH * BOXSIZE) // 2)
TOPMARGIN = WINDOWHEIGHT - (BOARDHEIGHT * BOXSIZE) - 5

# R G B
Expand Down Expand Up @@ -326,17 +326,17 @@ def showTextScreen(text):
# center of the screen until a key is pressed.
# Draw the text drop shadow
titleSurf, titleRect = makeTextObjs(text, BIGFONT, TEXTSHADOWCOLOR)
titleRect.center = (int(WINDOWWIDTH / 2), int(WINDOWHEIGHT / 2))
titleRect.center = (int(WINDOWWIDTH // 2), int(WINDOWHEIGHT // 2))
DISPLAYSURF.blit(titleSurf, titleRect)

# Draw the text
titleSurf, titleRect = makeTextObjs(text, BIGFONT, TEXTCOLOR)
titleRect.center = (int(WINDOWWIDTH / 2) - 3, int(WINDOWHEIGHT / 2) - 3)
titleRect.center = (int(WINDOWWIDTH // 2) - 3, int(WINDOWHEIGHT // 2) - 3)
DISPLAYSURF.blit(titleSurf, titleRect)

# Draw the additional "Press a key to play." text.
pressKeySurf, pressKeyRect = makeTextObjs('Press a key to play.', BASICFONT, TEXTCOLOR)
pressKeyRect.center = (int(WINDOWWIDTH / 2), int(WINDOWHEIGHT / 2) + 100)
pressKeyRect.center = (int(WINDOWWIDTH // 2), int(WINDOWHEIGHT // 2) + 100)
DISPLAYSURF.blit(pressKeySurf, pressKeyRect)

while checkForKeyPress() == None:
Expand All @@ -356,7 +356,7 @@ def checkForQuit():
def calculateLevelAndFallFreq(score):
# Based on the score, return the level the player is on and
# how many seconds pass until a falling piece falls one space.
level = int(score / 10) + 1
level = int(score // 10) + 1
fallFreq = 0.27 - (level * 0.02)
return level, fallFreq

Expand All @@ -365,7 +365,7 @@ def getNewPiece():
shape = random.choice(list(PIECES.keys()))
newPiece = {'shape': shape,
'rotation': random.randint(0, len(PIECES[shape]) - 1),
'x': int(BOARDWIDTH / 2) - int(TEMPLATEWIDTH / 2),
'x': int(BOARDWIDTH // 2) - int(TEMPLATEWIDTH // 2),
'y': -2, # start it above the board (i.e. less than 0)
'color': random.randint(0, len(COLORS)-1)}
return newPiece
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Wrapped Game Code/dummy_game.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Wrapped Game Code/pong_fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
bar2 = bar.convert()
bar2.fill((255,255,255))
circ_sur = pygame.Surface((15,15))
circ = pygame.draw.circle(circ_sur,(255,255,255),(15/2,15/2),15/2)
circ = pygame.draw.circle(circ_sur,(255,255,255),(15//2,15//2),15//2)
circle = circ_sur.convert()
circle.set_colorkey((0,0,0))
font = pygame.font.SysFont("calibri",40)
Expand Down
Binary file modified Wrapped Game Code/pong_fun.pyc
Binary file not shown.
6 changes: 3 additions & 3 deletions Wrapped Game Code/tetris_fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
MOVESIDEWAYSFREQ = 0.15
MOVEDOWNFREQ = 0.1

XMARGIN = int((WINDOWWIDTH - BOARDWIDTH * BOXSIZE) / 2)
XMARGIN = int((WINDOWWIDTH - BOARDWIDTH * BOXSIZE) // 2)
TOPMARGIN = WINDOWHEIGHT - (BOARDHEIGHT * BOXSIZE) - 5

# R G B
Expand Down Expand Up @@ -396,7 +396,7 @@ def makeTextObjs(self,text, font, color):
def calculateLevelAndFallFreq(self):
# Based on the self.score, return the self.level the player is on and
# how many seconds pass until a falling piece falls one space.
self.level = min(int(self.lines / 10) + 1, 10)
self.level = min(int(self.lines // 10) + 1, 10)
self.fallFreq = 0.27 - (self.level * 0.02)
return self.level, self.fallFreq

Expand All @@ -405,7 +405,7 @@ def getNewPiece(self):
shape = random.choice(list(PIECES.keys()))
newPiece = {'shape': shape,
'rotation': random.randint(0, len(PIECES[shape]) - 1),
'x': int(BOARDWIDTH / 2) - int(TEMPLATEWIDTH / 2),
'x': int(BOARDWIDTH // 2) - int(TEMPLATEWIDTH // 2),
'y': 0, # start it above the self.board (i.e. less than 0)
'color': random.randint(0, len(COLORS)-1)}
return newPiece
Expand Down
Binary file modified Wrapped Game Code/tetris_fun.pyc
Binary file not shown.
7 changes: 4 additions & 3 deletions deep_q_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ def trainNetwork(s, readout, h_fc1, sess):
sess.run(tf.initialize_all_variables())
checkpoint = tf.train.get_checkpoint_state("saved_networks")
if checkpoint and checkpoint.model_checkpoint_path:

saver.restore(sess, checkpoint.model_checkpoint_path)
print "Successfully loaded:", checkpoint.model_checkpoint_path
print("Successfully loaded:", checkpoint.model_checkpoint_path)
else:
print "Could not find old network weights"
print("Could not find old network weights")

epsilon = INITIAL_EPSILON
t = 0
Expand Down Expand Up @@ -185,7 +186,7 @@ def trainNetwork(s, readout, h_fc1, sess):
state = "explore"
else:
state = "train"
print "TIMESTEP", t, "/ STATE", state, "/ LINES", game_state.total_lines, "/ EPSILON", epsilon, "/ ACTION", action_index, "/ REWARD", r_t, "/ Q_MAX %e" % np.max(readout_t)
print("TIMESTEP", t, "/ STATE", state, "/ LINES", game_state.total_lines, "/ EPSILON", epsilon, "/ ACTION", action_index, "/ REWARD", r_t, "/ Q_MAX %e" % np.max(readout_t))

# write info to files
'''
Expand Down
12 changes: 6 additions & 6 deletions saved_networks/checkpoint
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
model_checkpoint_path: "saved_networks/tetris-dqn-31660000"
all_model_checkpoint_paths: "saved_networks/tetris-dqn-31620000"
all_model_checkpoint_paths: "saved_networks/tetris-dqn-31630000"
all_model_checkpoint_paths: "saved_networks/tetris-dqn-31640000"
all_model_checkpoint_paths: "saved_networks/tetris-dqn-31650000"
all_model_checkpoint_paths: "saved_networks/tetris-dqn-31660000"
model_checkpoint_path: "tetris-dqn-31660000"
all_model_checkpoint_paths: "tetris-dqn-31620000"
all_model_checkpoint_paths: "tetris-dqn-31630000"
all_model_checkpoint_paths: "tetris-dqn-31640000"
all_model_checkpoint_paths: "tetris-dqn-31650000"
all_model_checkpoint_paths: "tetris-dqn-31660000"