Add Control
This commit is contained in:
parent
302d32c9cd
commit
7b9d5567c3
1
.gitignore
vendored
1
.gitignore
vendored
@ -28,3 +28,4 @@ replay_pid*
|
||||
*.xml
|
||||
*.pyc
|
||||
.idea/workspace.xml
|
||||
.idea/workspace.xml
|
||||
|
36
.idea/workspace.xml
generated
36
.idea/workspace.xml
generated
@ -4,9 +4,22 @@
|
||||
<list default="true" id="c32bfd4e-6189-47f3-9d6c-c1825d3d7e5f" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/data/annotation.csv" beforeDir="false" afterPath="$PROJECT_DIR$/data/annotation.csv" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/IDManager.py" beforeDir="false" afterPath="$PROJECT_DIR$/IDManager.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Mario-AI-Interface.jar" beforeDir="false" afterPath="$PROJECT_DIR$/Mario-AI-Interface.jar" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Mario-AI-Interface.jar.js" beforeDir="false" afterPath="$PROJECT_DIR$/Mario-AI-Interface.jar.js" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Mario-AI-Interface/src/Play.java" beforeDir="false" afterPath="$PROJECT_DIR$/Mario-AI-Interface/src/Play.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Mario-AI-Interface/src/agents/HumanAgent.java" beforeDir="false" afterPath="$PROJECT_DIR$/Mario-AI-Interface/src/agents/HumanAgent.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Mario-AI-Interface/src/engine/core/MarioGame.java" beforeDir="false" afterPath="$PROJECT_DIR$/Mario-AI-Interface/src/engine/core/MarioGame.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/data/questionare.csv" beforeDir="false" afterPath="$PROJECT_DIR$/data/questionare.csv" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pyExcel.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/templates/GameAnnotation.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/GameAnnotation.html" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/templates/GamePlay.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/GamePlay.html" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/templates/GameQuestion.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/GameQuestion.html" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/templates/Template.html" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/templates/data.js" beforeDir="false" afterPath="$PROJECT_DIR$/templates/data.js" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/templates/eval.html" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/templates/play.html" beforeDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -117,7 +130,8 @@
|
||||
<workItem from="1667205217155" duration="3357000" />
|
||||
<workItem from="1667357110859" duration="5735000" />
|
||||
<workItem from="1667456828218" duration="24361000" />
|
||||
<workItem from="1667898094682" duration="1203000" />
|
||||
<workItem from="1667898094682" duration="1595000" />
|
||||
<workItem from="1667998268807" duration="2239000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
@ -135,23 +149,7 @@
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="XDebuggerManager">
|
||||
<breakpoint-manager>
|
||||
<breakpoints>
|
||||
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
||||
<url>file://$PROJECT_DIR$/main.py</url>
|
||||
<line>76</line>
|
||||
<option name="timeStamp" value="1" />
|
||||
</line-breakpoint>
|
||||
<line-breakpoint enabled="true" suspend="THREAD" type="python-line">
|
||||
<url>file://$PROJECT_DIR$/main.py</url>
|
||||
<line>81</line>
|
||||
<option name="timeStamp" value="3" />
|
||||
</line-breakpoint>
|
||||
</breakpoints>
|
||||
</breakpoint-manager>
|
||||
</component>
|
||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||
<SUITE FILE_PATH="coverage/MarioWeb$Flask__main_py_.coverage" NAME="Flask (main.py) Coverage Results" MODIFIED="1667898938796" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
|
||||
<SUITE FILE_PATH="coverage/MarioWeb$Flask__main_py_.coverage" NAME="Flask (main.py) Coverage Results" MODIFIED="1667998673231" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
|
||||
</component>
|
||||
</project>
|
10
IDManager.py
10
IDManager.py
@ -4,6 +4,7 @@ class idManager():
|
||||
levelNum = 200
|
||||
ip_dic = {}
|
||||
ip_recent = {}
|
||||
ip_control = {}
|
||||
def __int__(self):
|
||||
self.levelNum = 200
|
||||
|
||||
@ -26,6 +27,15 @@ class idManager():
|
||||
|
||||
def getRecent(self,ip):
|
||||
return self.ip_recent[ip]
|
||||
def setControl(self,ip,content):
|
||||
if content == "A":
|
||||
self.ip_control[ip] = 0
|
||||
else:
|
||||
self.ip_control[ip] = 1
|
||||
|
||||
|
||||
def getControl(self,ip):
|
||||
return self.ip_control[ip]
|
||||
def write_csv(self,path, data):
|
||||
with open(path, 'a+') as f:
|
||||
csv_write = csv.writer(f)
|
||||
|
Binary file not shown.
File diff suppressed because one or more lines are too long
16
Mario-AI-Interface/levels/lvl65.lvl
Normal file
16
Mario-AI-Interface/levels/lvl65.lvl
Normal file
@ -0,0 +1,16 @@
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
---------------------------------------------------------------------------------------------------------------------------2------------------------------------
|
||||
----------------------------------------------------------og------------------------------------SSSSSSSSS-------------------------------------------------------
|
||||
---------------------------------------------------------SSS-------------------------------------SS-------------------------------------------------------------
|
||||
---------------------------------------------------------------U------------------------------------S---------o------------------------o------------------------
|
||||
--------------------------------------------------oRQ---ySQ-------------------------------------------------------SQSS--oooo--@%-------------SSS----------------
|
||||
--SS------------------------------------------------------------------------------------oo--------------------------------r----|--o---------------------oo------
|
||||
--SS--------------%--------------------------------------------------%%%%%%%%%------------------S-----##------------------S--U-|-----------------------%%%%%%%--
|
||||
--SS--------------|---------------------------------------------------|||||||-----------SS------S-----##-------------------K-R-|------------------------|||||---
|
||||
------------------|----%------------------------%%%%--%%%%%%%-----TT--|||||||-------------------------##--------o----SSoo---Q--|---------SSSSSSS--------|||||-%%
|
||||
--------------TT--|----|-------------------------||----|||||------TT--|||||||----------------------#-###-----------------------|------------------------|||||-||
|
||||
--------------TT--|----|---------------TT-------%||----|||||------TT--|||||||--------------tt------#-###-----------------------|------------------------|||||-||
|
||||
------------k-TT--|----|-----------#---TT----k--|||----|||||------TT--|||||||--------------tt----#######--------gg---g-------g-|-----------------gg-----|||||-||
|
||||
XXXXXXXXXXXXXXXXXXXX---|XXXXXXXXXXXXXXXXXXXXXXXX|||----|||||----XXXXXXXXXXX||---XXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX---XXXX----XXXX-XXX-X--|XXX|-||
|
||||
XXXXXXXXXXXXXXXXXXXX---|XXXXXXXXXXXXXXXXXXXXXXXX|||----|||||----XXXXXXXXXXX||---XXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX---XXXXX---XXXX-XXX-X--|XXX|-||
|
BIN
Mario-AI-Interface/reps/127.0.0.1lvl6566.rep
Normal file
BIN
Mario-AI-Interface/reps/127.0.0.1lvl6566.rep
Normal file
Binary file not shown.
@ -37,22 +37,22 @@ public class Play {
|
||||
|
||||
}
|
||||
|
||||
public static byte[] playGameMain(String groupID, String levelName, int lives){
|
||||
public static byte[] playGameMain(String levelName, int lives, boolean control){
|
||||
|
||||
String levelPath = String.format("/app/levels/%s.lvl", levelName); // For web
|
||||
String repPath = String.format("/files/%s_sav.rep", levelName); // For web
|
||||
MarioGame game = new MarioGame();
|
||||
game.setLives(lives);
|
||||
MarioResult tmpResult = game.playGame(new HumanAgent(),getLevel(levelPath), 200, repPath);
|
||||
MarioResult tmpResult = game.playGame(new HumanAgent(control),getLevel(levelPath), 200, repPath);
|
||||
|
||||
return Replay.serializeAgentEvents(tmpResult.getAgentEvents());
|
||||
}
|
||||
|
||||
public static byte[] playGameMain(String groupID, String levelName){
|
||||
return playGameMain(groupID, levelName, 0);
|
||||
public static byte[] playGameMain(String levelName){
|
||||
return playGameMain(levelName, 0, true);
|
||||
}
|
||||
|
||||
public static void replayGameMain(String groupID, String levelName, int lives){
|
||||
public static void replayGameMain(String levelName, int lives){
|
||||
String levelPath = String.format("/app/levels/%s.lvl", levelName); // For web
|
||||
String repPath = String.format("/files/%s_sav.rep", levelName); // For web
|
||||
|
||||
|
@ -10,7 +10,11 @@ import engine.helper.MarioActions;
|
||||
|
||||
public class HumanAgent extends KeyAdapter implements MarioAgent {
|
||||
private boolean[] actions = null;
|
||||
private boolean oldControl = true;
|
||||
|
||||
public HumanAgent(boolean oldControl){
|
||||
this.oldControl = oldControl;
|
||||
}
|
||||
@Override
|
||||
public void initialize(MarioForwardModel model, MarioTimer timer) {
|
||||
actions = new boolean[MarioActions.numberOfActions()];
|
||||
@ -40,6 +44,7 @@ public class HumanAgent extends KeyAdapter implements MarioAgent {
|
||||
if (this.actions == null) {
|
||||
return;
|
||||
}
|
||||
if(oldControl){
|
||||
switch (keyCode) {
|
||||
case KeyEvent.VK_LEFT:
|
||||
this.actions[MarioActions.LEFT.getValue()] = isPressed;
|
||||
@ -58,5 +63,26 @@ public class HumanAgent extends KeyAdapter implements MarioAgent {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else{
|
||||
switch (keyCode) {
|
||||
case KeyEvent.VK_A:
|
||||
this.actions[MarioActions.LEFT.getValue()] = isPressed;
|
||||
break;
|
||||
case KeyEvent.VK_D:
|
||||
this.actions[MarioActions.RIGHT.getValue()] = isPressed;
|
||||
break;
|
||||
case KeyEvent.VK_S:
|
||||
this.actions[MarioActions.DOWN.getValue()] = isPressed;
|
||||
break;
|
||||
case KeyEvent.VK_J:
|
||||
this.actions[MarioActions.JUMP.getValue()] = isPressed;
|
||||
break;
|
||||
case KeyEvent.VK_K:
|
||||
this.actions[MarioActions.SPEED.getValue()] = isPressed;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public class MarioGame {
|
||||
}
|
||||
}
|
||||
public MarioResult playGame(String level, String resultPath) {
|
||||
return this.runGame(new agents.HumanAgent(), level, 200, 0, true, 30, 2, resultPath);
|
||||
return this.runGame(new agents.HumanAgent(true), level, 200, 0, true, 30, 2, resultPath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -32,3 +32,11 @@ IP,Style,Frequency,Age,Gender
|
||||
10.27.169.251,D,E,G,C,
|
||||
127.0.0.1,,A,,,
|
||||
127.0.0.1,A,A,A,B,
|
||||
127.0.0.1,A,E,B,A,
|
||||
127.0.0.1,,,,,
|
||||
127.0.0.1,,,,,
|
||||
127.0.0.1,,,,,
|
||||
127.0.0.1,,,,,
|
||||
127.0.0.1,,,,,
|
||||
127.0.0.1,,,,,
|
||||
127.0.0.1,,,,,
|
||||
|
|
16
levels/Tutorial1.lvl
Normal file
16
levels/Tutorial1.lvl
Normal file
@ -0,0 +1,16 @@
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-----------------------------------------------SSSS-SSS-----------------------SSSSSSSSSSSSSSSSSS----------------SSSSSSSSSSSSSSSS----------------S--SSSSSS-------
|
||||
----------o-----t-------------------------------------------------------------------SSSS--S----------------------SSSSSSSSSSSSSSS--------------------------------
|
||||
%--------S------t--------------------------------------------------------------------SS--SSS--------------------SSSSSSSSSSSSSSS---------------------------------
|
||||
|------------------------------o----------SSSSSS--------------------Q--------------S------SS-------------------o------S----KSSS---------------@%--S-------------
|
||||
|-----------------------------------------SSSSS------oo----------------------------------------------%---------------------SS------------------|----------------
|
||||
|--------------------------------------SSSSSSSS-%----%%%%%-%%--------------------------SS------------|-----------------------------------------|-----#----------
|
||||
|--------o------------------------S--SS--SSSSS--|-----|||--||--------------------------r-------S-----|------------SSo-ooo---oSSS---------------|----##----------
|
||||
|------------------------------S----SSSSSSSSSSS-|-----|||--||-------------------%%%%%%%%%%------QQQ--|-QQ----------SSS%--%%%%%%%---#-----------|---####--##-##-#
|
||||
|------------------------------t--------S-------|-T---|||--||----------------#---||||||||----#-------|----------------|---|||||----#-----------|--#####--##----#
|
||||
|--------------------------tt--t-------SSS%%-SS-|-TT--|||--||----------------#--S|||||||S----#-------tt---------S-----|--S||||S----#-----------|-######--##----#
|
||||
|--------k-------g---------tt-kt----------||----|-TT--|||--||----kkg-------###---|||||||---------g---tt------ggg------|---||||-----#-#---------|#######--##----#
|
||||
XX-------XXXXXXXXXXXXXXXXXXXXXXXS--%------%%----|XXXX-|||--||---XXXXXXXXXXXXXXXX%|%%%%%%%-------XXXXXXXXXXXXXXXX-%%%%%%%%%%%||--XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-X
|
||||
XX-------XXXXXXXXXXXXXXXXXXXXXXX---|------||----|XXXX-|||--||---XXXXXXXXXXXXXXXXg|-|||||--------XXXXXXXXXXXXXXXXg-|||||||||-||--XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-X
|
16
levels/Tutorial2.lvl
Normal file
16
levels/Tutorial2.lvl
Normal file
@ -0,0 +1,16 @@
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-----------------------------------------------SSSS-SSS-----------------------SSSSSSSSSSSSSSSSSS----------------SSSSSSSSSSSSSSSS----------------S--SSSSSS-------
|
||||
----------o-----t-------------------------------------------------------------------SSSS--S----------------------SSSSSSSSSSSSSSS--------------------------------
|
||||
%--------S------t--------------------------------------------------------------------SS--SSS--------------------SSSSSSSSSSSSSSS---------------------------------
|
||||
|------------------------------o----------SSSSSS--------------------Q--------------S------SS-------------------o------S----KSSS---------------@%--S-------------
|
||||
|-----------------------------------------SSSSS------oo----------------------------------------------%---------------------SS------------------|----------------
|
||||
|--------------------------------------SSSSSSSS-%----%%%%%-%%--------------------------SS------------|-----------------------------------------|-----#----------
|
||||
|--------o------------------------S--SS--SSSSS--|-----|||--||--------------------------r-------S-----|------------SSo-ooo---oSSS---------------|----##----------
|
||||
|------------------------------S----SSSSSSSSSSS-|-----|||--||-------------------%%%%%%%%%%------QQQ--|-QQ----------SSS%--%%%%%%%---#-----------|---####--##-##-#
|
||||
|------------------------------t--------S-------|-T---|||--||----------------#---||||||||----#-------|----------------|---|||||----#-----------|--#####--##----#
|
||||
|--------------------------tt--t-------SSS%%-SS-|-TT--|||--||----------------#--S|||||||S----#-------tt---------S-----|--S||||S----#-----------|-######--##----#
|
||||
|--------k-------g---------tt-kt----------||----|-TT--|||--||----kkg-------###---|||||||---------g---tt------ggg------|---||||-----#-#---------|#######--##----#
|
||||
XX-------XXXXXXXXXXXXXXXXXXXXXXXS--%------%%----|XXXX-|||--||---XXXXXXXXXXXXXXXX%|%%%%%%%-------XXXXXXXXXXXXXXXX-%%%%%%%%%%%||--XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-X
|
||||
XX-------XXXXXXXXXXXXXXXXXXXXXXX---|------||----|XXXX-|||--||---XXXXXXXXXXXXXXXXg|-|||||--------XXXXXXXXXXXXXXXXg-|||||||||-||--XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-X
|
16
levels/Tutorial3.lvl
Normal file
16
levels/Tutorial3.lvl
Normal file
@ -0,0 +1,16 @@
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
----------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-----------------------------------------------SSSS-SSS-----------------------SSSSSSSSSSSSSSSSSS----------------SSSSSSSSSSSSSSSS----------------S--SSSSSS-------
|
||||
----------o-----t-------------------------------------------------------------------SSSS--S----------------------SSSSSSSSSSSSSSS--------------------------------
|
||||
%--------S------t--------------------------------------------------------------------SS--SSS--------------------SSSSSSSSSSSSSSS---------------------------------
|
||||
|------------------------------o----------SSSSSS--------------------Q--------------S------SS-------------------o------S----KSSS---------------@%--S-------------
|
||||
|-----------------------------------------SSSSS------oo----------------------------------------------%---------------------SS------------------|----------------
|
||||
|--------------------------------------SSSSSSSS-%----%%%%%-%%--------------------------SS------------|-----------------------------------------|-----#----------
|
||||
|--------o------------------------S--SS--SSSSS--|-----|||--||--------------------------r-------S-----|------------SSo-ooo---oSSS---------------|----##----------
|
||||
|------------------------------S----SSSSSSSSSSS-|-----|||--||-------------------%%%%%%%%%%------QQQ--|-QQ----------SSS%--%%%%%%%---#-----------|---####--##-##-#
|
||||
|------------------------------t--------S-------|-T---|||--||----------------#---||||||||----#-------|----------------|---|||||----#-----------|--#####--##----#
|
||||
|--------------------------tt--t-------SSS%%-SS-|-TT--|||--||----------------#--S|||||||S----#-------tt---------S-----|--S||||S----#-----------|-######--##----#
|
||||
|--------k-------g---------tt-kt----------||----|-TT--|||--||----kkg-------###---|||||||---------g---tt------ggg------|---||||-----#-#---------|#######--##----#
|
||||
XX-------XXXXXXXXXXXXXXXXXXXXXXXS--%------%%----|XXXX-|||--||---XXXXXXXXXXXXXXXX%|%%%%%%%-------XXXXXXXXXXXXXXXX-%%%%%%%%%%%||--XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-X
|
||||
XX-------XXXXXXXXXXXXXXXXXXXXXXX---|------||----|XXXX-|||--||---XXXXXXXXXXXXXXXXg|-|||||--------XXXXXXXXXXXXXXXXg-|||||||||-||--XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-X
|
46
main.py
46
main.py
@ -30,15 +30,7 @@ def gamepreplay():
|
||||
idm.write_csv(questionarePath,
|
||||
[ip, result.get("gamestyle"), result.get("frequency"), result.get("age"), result.get("gender"),
|
||||
""])
|
||||
# excel = ExcelWork(questionarePath)
|
||||
# questionareLine = excel.getMaxRow()+1
|
||||
# print(questionareLine)
|
||||
# excel.setCell(questionareLine,1,ip)
|
||||
# excel.setCell(questionareLine, 2, result.get("gamestyle"))
|
||||
# excel.setCell(questionareLine, 3, result.get("frequency"))
|
||||
# excel.setCell(questionareLine, 4, result.get("age"))
|
||||
# excel.saveFile()
|
||||
# print(questionareLine)
|
||||
idm.setControl(ip, result.get("control"))
|
||||
print(result.get("gamestyle"))
|
||||
return redirect(url_for('gameplay', id=ip))
|
||||
|
||||
@ -52,11 +44,26 @@ def gamepreplayAgain():
|
||||
def gamequestion():
|
||||
return render_template('GameQuestion.html')
|
||||
|
||||
@app.route('/gametutorial/<id>/<level>')
|
||||
def gametutorial(id, level):
|
||||
return render_template('GameTutorial.html', tutorial=level)
|
||||
|
||||
@app.route('/gameplay/<id>')
|
||||
def gameplay(id):
|
||||
gamelevels = idm.getLevels(id)
|
||||
return render_template('GamePlay.html', gamelevels=gamelevels)
|
||||
return render_template('GamePlay.html', gamelevels=gamelevels, control = idm.getControl(id))
|
||||
|
||||
@app.route('/gameplay/<id>/data', methods=['POST'])
|
||||
def getJSONData(id):
|
||||
if request.method == 'POST':
|
||||
print("POST Game")
|
||||
# print(request.form)
|
||||
# print(list(request.form))
|
||||
resultList = list(request.form)[0].split(",")
|
||||
|
||||
saveFile(replayDataPath, id + resultList[0], resultList[1:])
|
||||
return "get!"
|
||||
|
||||
|
||||
|
||||
@app.route('/annotation/<id>')
|
||||
@ -68,21 +75,6 @@ def gameanno(id):
|
||||
level2 = "lvl" + str(gamelevels[1])
|
||||
return render_template('GameAnnotation.html', level1=level1, level2=level2)
|
||||
|
||||
|
||||
#
|
||||
@app.route('/gameplay/<id>/data', methods=['POST'])
|
||||
def getJSONData(id):
|
||||
if request.method == 'POST':
|
||||
print("POST Game")
|
||||
# print(request.form)
|
||||
# print(list(request.form))
|
||||
resultList = list(request.form)[0].split(",")
|
||||
|
||||
# FIXME: SAVING IN TXT
|
||||
saveFile(replayDataPath, id + resultList[0], resultList[1:])
|
||||
return "get!"
|
||||
|
||||
|
||||
@app.route('/annotation/radioresult', methods=['POST'])
|
||||
def getRadioData():
|
||||
if request.method == 'POST':
|
||||
@ -97,6 +89,10 @@ def getRadioData():
|
||||
return render_template("GameOver.html")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def saveFile(path, filename, content):
|
||||
cp = list(map(int, content))
|
||||
file_dir = os.path.join(os.getcwd(), path)
|
||||
|
126
pyExcel.py
126
pyExcel.py
@ -1,126 +0,0 @@
|
||||
"""
|
||||
基于openpyxl的excel读写模块
|
||||
提供更简单的读写方式
|
||||
"""
|
||||
from openpyxl import load_workbook, Workbook
|
||||
|
||||
|
||||
class ExcelWork:
|
||||
|
||||
def __init__(self, filePath):
|
||||
"""
|
||||
初始化, 加载excel,默认选择第一个工作表
|
||||
:param filePath: str: 文件地址
|
||||
"""
|
||||
self.filePath = filePath
|
||||
try:
|
||||
# 加载excel
|
||||
self.excel = load_workbook(self.filePath)
|
||||
except FileNotFoundError:
|
||||
# 创建excel
|
||||
self.excel = Workbook(self.filePath)
|
||||
# 创建sheet
|
||||
self.createSheet('Sheet1')
|
||||
# 保存excel
|
||||
self.close()
|
||||
# 加载excel
|
||||
self.excel = load_workbook(self.filePath)
|
||||
# sheet设置为第一个工作表
|
||||
self.sheet = self.excel.active
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
保存并退出
|
||||
:return:
|
||||
"""
|
||||
self.excel.save(self.filePath)
|
||||
|
||||
def createSheet(self, sheetName):
|
||||
"""
|
||||
创建工作表
|
||||
:param sheetName: str: 工作表名
|
||||
:return:
|
||||
"""
|
||||
self.excel.create_sheet(sheetName)
|
||||
|
||||
def getSheetTitle(self):
|
||||
"""
|
||||
获取当前工作表名称
|
||||
:return: str: 工作表名称
|
||||
"""
|
||||
return self.sheet.title
|
||||
|
||||
def getSheetTitles(self):
|
||||
"""
|
||||
获取excel所有工作表的名称
|
||||
:return: list: [工作表名称,]
|
||||
"""
|
||||
return self.excel.sheetnames
|
||||
|
||||
def delSheet(self):
|
||||
"""
|
||||
删除当前工作表
|
||||
:return:
|
||||
"""
|
||||
self.excel.remove(self.sheet)
|
||||
|
||||
def selectSheet(self, sheetName):
|
||||
"""
|
||||
选择工作表, 如果没有将创建
|
||||
:param sheetName: str: 工作表名
|
||||
:return:
|
||||
"""
|
||||
if sheetName in self.getSheetTitles():
|
||||
# 选择工作表
|
||||
self.sheet = self.excel[sheetName]
|
||||
else:
|
||||
# 创建工作表
|
||||
self.createSheet(sheetName)
|
||||
# 选择工作表
|
||||
self.sheet = self.excel[sheetName]
|
||||
|
||||
def setCell(self, r, c, var):
|
||||
"""
|
||||
修改指定行, 列的单元格内容
|
||||
:param r: int: 行数
|
||||
:param c: int: 列数
|
||||
:param var: str: 修改内容
|
||||
:return:
|
||||
"""
|
||||
self.sheet.cell(row=r, column=c, value=var)
|
||||
|
||||
def getCell(self, r, c):
|
||||
"""
|
||||
获取指定行, 列的单元格内容
|
||||
:param r: int: 行数
|
||||
:param c: int: 列数
|
||||
:return: str: 单元格内容
|
||||
"""
|
||||
return self.sheet.cell(row=r, column=c).value
|
||||
|
||||
def getRow(self, r):
|
||||
"""
|
||||
获取指定行所有数据
|
||||
:param r: int: 行数
|
||||
:return: list: [数据,]
|
||||
"""
|
||||
rowList = []
|
||||
for cell in self.sheet[r]:
|
||||
rowList.append(cell.value)
|
||||
return rowList
|
||||
|
||||
def getColumn(self, c):
|
||||
"""
|
||||
获取指定列所有数据
|
||||
:param c: int: 列数
|
||||
:return: list: [数据,]
|
||||
"""
|
||||
columnList = []
|
||||
for temp in range(1, self.sheet.max_row + 1):
|
||||
columnList.append(self.getCell(temp, c))
|
||||
return columnList
|
||||
def getMaxRow(self):
|
||||
return self.sheet.max_row
|
||||
|
||||
def saveFile(self):
|
||||
self.excel.save(self.filePath)
|
@ -203,12 +203,12 @@ function Replay(id){
|
||||
console.log("{{level1}}")
|
||||
var replayWindow=document.getElementById("replayWindow");
|
||||
replayWindow.style.visibility = 'visible';
|
||||
cjCall("Play", "replayGameMain", "{{level1}}", "{{level1}}",5);
|
||||
cjCall("Play", "replayGameMain", "{{level1}}",5);
|
||||
}else if(id==2){
|
||||
console.log("{{level2}}")
|
||||
var replayWindow=document.getElementById("replayWindow");
|
||||
replayWindow.style.visibility = 'visible';
|
||||
cjCall("Play", "replayGameMain", "{{level2}}", "{{level2}}",5);
|
||||
cjCall("Play", "replayGameMain", "{{level2}}",5);
|
||||
}else{
|
||||
|
||||
}
|
||||
|
@ -2,38 +2,7 @@
|
||||
<!-- saved from url=(0029)http://aingames.cn/index.html -->
|
||||
<html lang="en"><script id="allow-copy_script">(function t(){var t=!1;document.addEventListener("allow_copy",(function(n){t=n.detail.unlock}));var n=["copy","cut","contextmenu","selectstart","mousedown","mouseup","mousemove","keydown","keypress","keyup"],e=function(n){t&&(n.stopPropagation(),n.stopImmediatePropagation&&n.stopImmediatePropagation())};n.forEach((function(t){document.documentElement.addEventListener(t,e,{capture:!0})}))})()</script><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
|
||||
<!-- <script>
|
||||
//The Funtions
|
||||
function PlayLevel(group, level){
|
||||
var returnVal = cjCall("Play", "playGameMain", group, level);
|
||||
return returnVal.then(function(){
|
||||
console.log("the return val is ready");
|
||||
console.log(returnVal.value);
|
||||
PostToServer(level,returnVal.value);
|
||||
});
|
||||
}
|
||||
|
||||
function Replay(){
|
||||
cjCall("Play", "replayGameMain", "test2", "test2");
|
||||
};
|
||||
function GameOver(){
|
||||
if(alert("Game Over!")){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function PostToServer(level, data) {
|
||||
var httpRequest = new XMLHttpRequest();//第一步:建立所需的对象
|
||||
httpRequest.open("POST",""); //调用AddDataToServer
|
||||
httpRequest.setRequestHeader("Content-Type", "application/json"); //设置请求头信息
|
||||
httpRequest.onreadystatechange = function () {
|
||||
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
|
||||
//alert('添加成功');
|
||||
}
|
||||
}
|
||||
httpRequest.send(JSON.stringify(level+","+Array.from(data))); //设置为发送给服务器数据
|
||||
}
|
||||
</script> -->
|
||||
<script src="../templates/data.js"></script>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<meta name="description" content="">
|
||||
@ -145,16 +114,6 @@
|
||||
</nav>
|
||||
|
||||
|
||||
<!-- <div id="headerwrap" name="home">
|
||||
<div script="align:left"></div>
|
||||
|
||||
<header class="bg-primary1 text-white">
|
||||
<img class="img-fluid" src="/static/img/bg.png" width=60%>
|
||||
<h1>Games and Artificial Intelligence</h1>
|
||||
</header>
|
||||
</div> -->
|
||||
|
||||
|
||||
<section id="news">
|
||||
|
||||
<div class="container">
|
||||
@ -175,7 +134,7 @@
|
||||
<div align="center" id = "GameWindow">
|
||||
|
||||
</div>
|
||||
<div align="center"><button onClick="Replay()">Replay Game</button></div>
|
||||
|
||||
<script>
|
||||
//Init Cheerpj Framework
|
||||
cheerpjInit();
|
||||
@ -214,9 +173,11 @@
|
||||
cheerpjRunMain("Play", "/app/Mario-AI-Interface.jar", "0", "f_l");
|
||||
console.log("Cheerpj Initialize Succeed!");
|
||||
|
||||
PlayLevel(level1, level1)
|
||||
console.log("{{control}}")
|
||||
var control = ("{{control}}" == "1");
|
||||
PlayLevel(level1,control)
|
||||
.then(function (){alert("Game Over!")})
|
||||
.then(PlayLevel(level2, level2)
|
||||
.then(PlayLevel(level2,control)
|
||||
.then(function (){
|
||||
alert("Go to Evaluation Window")
|
||||
window.location.href = "/annotation"
|
||||
|
@ -290,6 +290,18 @@
|
||||
</label>
|
||||
</p>
|
||||
|
||||
<p><h4>You would like to play in?</h4>
|
||||
<label>
|
||||
<input type="radio" class="option-input radio" name="control" value="A" >
|
||||
WSD + JK
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" class="option-input radio" name="control" value="B" >
|
||||
←↓→ + AS
|
||||
</label>
|
||||
|
||||
</p>
|
||||
|
||||
|
||||
<br>
|
||||
<p><input type = "submit" value = "submit" /></p>
|
||||
|
File diff suppressed because one or more lines are too long
@ -29,12 +29,12 @@ function PostToServer(url,data) {
|
||||
$.post(url, data);
|
||||
}
|
||||
}
|
||||
function PlayLevel(group, level){
|
||||
var returnVal = cjCall("Play", "playGameMain", group, level,5);
|
||||
function PlayLevel(level,control){
|
||||
var returnVal = cjCall("Play", "playGameMain", level, 5, control);
|
||||
return returnVal.then(function(){
|
||||
console.log("the return val is ready");
|
||||
console.log(returnVal.value);
|
||||
PostToServer(window.location.href+"/data",group+returnVal.value);
|
||||
PostToServer(window.location.href+"/data",level+returnVal.value);
|
||||
//Array.from()
|
||||
});
|
||||
}
|
||||
|
@ -1,186 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
|
||||
<style>
|
||||
*{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
.popwindow {
|
||||
width:500px;
|
||||
height:550px;
|
||||
border:3px solid #ff928e;
|
||||
visibility: hidden;
|
||||
position: absolute;
|
||||
z-index: 999;
|
||||
opacity: 1;
|
||||
overflow: hidden;
|
||||
background-color: white;
|
||||
text-align: center;
|
||||
margin-top: 10%;
|
||||
margin-left: 35%;
|
||||
border-radius: 10px;
|
||||
}
|
||||
.leftInfoBlock{
|
||||
margin-top: 20px;
|
||||
height: 180px;
|
||||
background: #f1a087;
|
||||
}
|
||||
.leftInfo {
|
||||
width: 90%;
|
||||
top: 20px;
|
||||
position:absolute;
|
||||
background: #f7a2a2;
|
||||
}
|
||||
.rightQuery{
|
||||
width: 10%;
|
||||
left: 90%;
|
||||
height: 400px;
|
||||
top: 20px;
|
||||
position:absolute;
|
||||
background: #a19cee;
|
||||
}
|
||||
.circleButton{
|
||||
align-items: center;
|
||||
border-radius:50%;
|
||||
border: none
|
||||
}
|
||||
.pararadio{
|
||||
height: 20%;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
<div id="replayWindow" class="popwindow">
|
||||
<div id="replayWindowGame">
|
||||
</div>
|
||||
<div align="center"><button onClick="closeReplayWindow()">Close Window</button></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<body>
|
||||
<div class = "leftInfo">
|
||||
<div class = "leftInfoBlock">
|
||||
<h3 align = "center"> Game 1</h3>
|
||||
<img src="../levels/test1.png" width="100%" >
|
||||
<div align="center"><button onClick="Replay('test1')">Replay Game1</button></div>
|
||||
</div>
|
||||
|
||||
<div class = "leftInfoBlock">
|
||||
<h3 align = "center"> Game 2</h3>
|
||||
<img src="../levels/test2.png" width="100%" >
|
||||
<div align="center"><button onClick="Replay('test2')">Replay Game2</button></div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
//The Funtions
|
||||
function closeReplayWindow(){
|
||||
var replayWindow=document.getElementById("replayWindow");
|
||||
replayWindow.style.visibility = 'hidden';
|
||||
}
|
||||
function Replay(id){
|
||||
var replayWindow=document.getElementById("replayWindow");
|
||||
replayWindow.style.visibility = 'visible';
|
||||
cjCall("Play", "replayGameMain", id, id);
|
||||
}
|
||||
function getValue(){
|
||||
var radio = document.getElementsByName("gameRadio");
|
||||
for (i=0; i<radio.length; i++) {
|
||||
if (radio[i].checked) {
|
||||
alert(radio[i].value)
|
||||
}
|
||||
}
|
||||
}
|
||||
function PostToServer(data) {
|
||||
var httpRequest = new XMLHttpRequest();//第一步:建立所需的对象
|
||||
httpRequest.open("POST",""); //调用AddDataToServer
|
||||
httpRequest.setRequestHeader("Content-Type", "application/json"); //设置请求头信息
|
||||
httpRequest.onreadystatechange = function () {
|
||||
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
|
||||
//alert('添加成功');
|
||||
}
|
||||
}
|
||||
httpRequest.send(JSON.stringify(data)); //设置为发送给服务器数据
|
||||
}
|
||||
window.onload=function(){
|
||||
closeReplayWindow();
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
cheerpjInit();
|
||||
var divElement = document.getElementById("replayWindowGame");
|
||||
cheerpjCreateDisplay(500,500,divElement);
|
||||
cheerpjRunMain("Play", "/app/Mario-AI-Interface.jar", "0", "f_l");
|
||||
closeReplayWindow();
|
||||
</script>
|
||||
</div>
|
||||
<div class = "rightQuery">
|
||||
<!-- <button class = "circleButton" style = "width: 100px; height: 100px;"></button>
|
||||
<button class = "circleButton" style = "width: 60px; height: 60px;"></button>
|
||||
<button class = "circleButton" style = "width: 40px; height: 40px;"></button>
|
||||
<button class = "circleButton" style = "width: 60px; height: 60px;"></button>
|
||||
<button class = "circleButton" style = "width: 100px; height: 100px;"></button> -->
|
||||
<fieldset style="height: 100%;" >
|
||||
<legend align="center" height = 30px >Fun</legend>
|
||||
|
||||
<div class = "pararadio">
|
||||
<input type="radio" value="1-2" name="fun">
|
||||
<label for="gameRadio">Game1 Better</label>
|
||||
</div>
|
||||
|
||||
<div class = "pararadio">
|
||||
<input type="radio" value="1-1" name="fun">
|
||||
<label for="gameRadio">Game1 Good</label>
|
||||
</div>
|
||||
|
||||
<div class = "pararadio">
|
||||
<input type="radio" value="0-0" name="fun">
|
||||
<label for="gameRadio">Equal</label>
|
||||
</div>
|
||||
|
||||
<div class = "pararadio">
|
||||
<input type="radio" value="2-1" name="fun">
|
||||
<label for="gameRadio">Game2 Good</label>
|
||||
</div>
|
||||
|
||||
<div class = "pararadio">
|
||||
<input type="radio" value="2-2" name="fun">
|
||||
<label for="gameRadio">Game2 Better</label>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<script>
|
||||
function getRadioValue(){
|
||||
var obj = document.getElementsByName("fun");
|
||||
for(var i=0; i<obj.length; i ++){
|
||||
if(obj[i].checked){
|
||||
PostToServer(obj[i].value);
|
||||
alert(obj[i].value);
|
||||
}
|
||||
}
|
||||
// var radio = document.getElementsByName("gameRadio");
|
||||
// var addressID = $("input[name='sex']:checked").val();
|
||||
// alert(addressID)
|
||||
|
||||
}
|
||||
</script>
|
||||
<button onclick="getRadioValue()"> Submit </button>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
|
||||
</html>
|
@ -1,101 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>CheerpJ test</title>
|
||||
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
|
||||
<script>
|
||||
//The Funtions
|
||||
function PlayLevel(group, level){
|
||||
var returnVal = cjCall("Play", "playGameMain", group, level);
|
||||
return returnVal.then(function(){
|
||||
console.log("the return val is ready");
|
||||
console.log(returnVal.value);
|
||||
PostToServer(level,returnVal.value);
|
||||
});
|
||||
}
|
||||
|
||||
function Replay(){
|
||||
cjCall("Play", "replayGameMain", "test2", "test2");
|
||||
};
|
||||
function GameOver(){
|
||||
if(alert("Game Over!")){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function PostToServer(level, data) {
|
||||
var httpRequest = new XMLHttpRequest();//第一步:建立所需的对象
|
||||
httpRequest.open("POST",""); //调用AddDataToServer
|
||||
httpRequest.setRequestHeader("Content-Type", "application/json"); //设置请求头信息
|
||||
httpRequest.onreadystatechange = function () {
|
||||
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
|
||||
//alert('添加成功');
|
||||
}
|
||||
}
|
||||
httpRequest.send(JSON.stringify(level+","+Array.from(data))); //设置为发送给服务器数据
|
||||
}
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div align="center">
|
||||
<h1>Mario Game User Test</h1>
|
||||
</div>
|
||||
<div align="center" id = "GameWindow">
|
||||
|
||||
</div>
|
||||
<div align="center"><button onClick="Replay()">Replay Game</button></div>
|
||||
</body>
|
||||
|
||||
<script>
|
||||
//Init Cheerpj Framework
|
||||
cheerpjInit();
|
||||
/*
|
||||
function cheerpjCreateDisplay(w, h, oldElem)
|
||||
{
|
||||
// Create a div element that will contain all Java Windows
|
||||
var element = document.createElement("div");
|
||||
cjDisplay = element;
|
||||
element.id="cheerpjDisplay";
|
||||
if(oldElem && w<0 && h<0)
|
||||
{
|
||||
// Compute the sizes from the parent
|
||||
element.style.width="100%";
|
||||
element.style.height="100%";
|
||||
}
|
||||
else
|
||||
{
|
||||
element.style.width=w+"px";
|
||||
element.style.height=h+"px";
|
||||
}
|
||||
element.classList.add("cheerpjLoading");
|
||||
element.classList.add("bordered");
|
||||
if(oldElem)
|
||||
oldElem.appendChild(element);
|
||||
else
|
||||
document.body.appendChild(element);
|
||||
cheerpjSetStatus(cjStatus, element);
|
||||
return element;
|
||||
}*/
|
||||
var divElement = document.getElementById("GameWindow");
|
||||
cheerpjCreateDisplay(500,500,divElement);
|
||||
cheerpjRunMain("Play", "/app/Mario-AI-Interface.jar", "0", "f_l");
|
||||
console.log("Cheerpj Initialize Succeed!");
|
||||
|
||||
PlayLevel("test1", "test1")
|
||||
.then(function (){alert("Game Over!")})
|
||||
.then(PlayLevel("test2", "test2")
|
||||
.then(function (){
|
||||
alert("Go to Evaluation Window")
|
||||
window.location.href = window.location.href + "\eval"
|
||||
|
||||
}));
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user