-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeepagent.py
More file actions
75 lines (66 loc) · 2.76 KB
/
deepagent.py
File metadata and controls
75 lines (66 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
from marioagent import MarioAgent
class Agent(MarioAgent):
""" In fact the Python twin of the
corresponding Java ForwardJumpingAgent.
"""
action = None
actionStr = None
KEY_JUMP = 3
KEY_SPEED = 4
# levelScene = None
mayMarioJump = None
isMarioOnGround = None
marioFloats = None
enemiesFloats = None
isEpisodeOver = False
marioState = None
def reset(self):
self.action = [0, 0, 0, 0, 0, 0]
self.action[1] = 1
self.action[self.KEY_SPEED] = 1
self.isEpisodeOver = False
def __init__(self):
"""Constructor"""
self.reset()
self.actionStr = ""
self.agentName = "Python Deep Agent"
def getAction(self):
""" Possible analysis of current observation and sending an action back
"""
#print "M: mayJump: %s, onGround: %s, level[11,12]: %d, level[11,13]: %d, jc: %d" % (self.mayMarioJump, self.isMarioOnGround, self.levelScene[11,12], self.levelScene[11,13], self.trueJumpCounter)
if self.isEpisodeOver:
return 1, 1, 1, 1, 1, 1
self.action[self.KEY_SPEED] = self.action[self.KEY_JUMP] = self.mayMarioJump or not self.isMarioOnGround
t = tuple(self.action)
print('action tuple ', t)
return t
def integrateObservation(self, squashedObservation, squashedEnemies, marioPos, enemiesPos, marioState):
"""This method stores the observation inside the agent"""
# print "Py: got observation::: squashedObservation: \n", squashedObservation
# print "Py: got observation::: squashedEnemies: \n", squashedEnemies
# print "Py: got observation::: marioPos: \n", marioPos
# print "Py: got observation::: enemiesPos: \n", enemiesPos
# print "Py: got observation::: marioState: \n", marioState
# a = numpy.array(squashedObservation)
# row = 19
# col = 19
# a.resize((row,col))
# print "\n a== \n", a
# levelScene = a
# enemiesObservation = numpy.array(squashedEnemies)
# enemiesObservation.resize((row,col))
self.marioFloats = marioPos
self.enemiesFloats = enemiesPos
self.mayMarioJump = marioState[3]
self.isMarioOnGround = marioState[2]
# self.levelScene = levelScene
self.marioState = marioState[1]
# self.printLevelScene()
def setObservationDetails(self, rfwidth, rfheight, egorow, egocol):
print(rfwidth, rfheight, egorow, egocol)
self.receptiveFieldWidth = rfwidth
self.receptiveFieldHeight = rfheight
self.marioEgoRow = egorow
self.marioEgoCol = egocol
print(self.receptiveFieldWidth, self.receptiveFieldHeight, self.marioEgoRow, self.marioEgoCol)