-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHumanAgent.py
47 lines (40 loc) · 1.19 KB
/
HumanAgent.py
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
from MalmoRun import MalmoRun
import MalmoPython
import os
import random
import sys
import time
import json
import errno
mr = MalmoRun()
def loadXMLFile(mission_file = './Mazes/Maze1.xml'):
with open(mission_file, 'r') as f:
print "Loading mission from %s" % mission_file
xml = f.read()
mr.setXML(xml)
def main():
agentTime = 0.0
reward = 0.0
mr.setAgentFun(agentFun)
for i in range(1,16):
loadXMLFile('./Mazes/EvalMaze'+str(i)+'.xml')
mr.runAgent(True)
currentReward = mr.getReward()
currentTime = mr.agentTime
printString = str(i) + "," + str(currentReward) + "," + str(currentTime) + "\n"
print printString
agentTime = agentTime + currentTime
reward = reward + currentReward
with open("HumanAgentData.txt", 'a') as f:
f.write(printString)
return reward
def agentFun():
world_state = mr.agent_host.getWorldState()
while world_state.is_mission_running:
world_state = mr.agent_host.getWorldState()
def Evaluate():
with open("HumanAgentData.txt", 'w') as f:
f.write("Random Agent Data\n")
f.write("Maze,Reward,Time\n")
main()
Evaluate()