Update ID Based Routing
This commit is contained in:
parent
896931a046
commit
cbe6016638
15
.idea/workspace.xml
generated
15
.idea/workspace.xml
generated
@ -3,11 +3,14 @@
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="c32bfd4e-6189-47f3-9d6c-c1825d3d7e5f" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/IDManager.py" beforeDir="false" afterPath="$PROJECT_DIR$/IDManager.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Mario-AI-Interface/reps/f_l_sav.rep" beforeDir="false" afterPath="$PROJECT_DIR$/Mario-AI-Interface/reps/f_l_sav.rep" 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/engine/core/MarioRender.java" beforeDir="false" afterPath="$PROJECT_DIR$/Mario-AI-Interface/src/engine/core/MarioRender.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Mario-AI-Interface/src/engine/helper/Assets.java" beforeDir="false" afterPath="$PROJECT_DIR$/Mario-AI-Interface/src/engine/helper/Assets.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/data/annotation.csv" beforeDir="false" afterPath="$PROJECT_DIR$/data/annotation.csv" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/data/questionare.csv" beforeDir="false" afterPath="$PROJECT_DIR$/data/questionare.csv" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/templates/GameAnnotation.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/GameAnnotation.html" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/templates/GameAnnotation2.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/GameAnnotation2.html" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/templates/GamePlay.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/GamePlay.html" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -212,7 +215,9 @@
|
||||
<workItem from="1677221941122" duration="2329000" />
|
||||
<workItem from="1677303698061" duration="6278000" />
|
||||
<workItem from="1677563906178" duration="5318000" />
|
||||
<workItem from="1677572224495" duration="1591000" />
|
||||
<workItem from="1677572224495" duration="2432000" />
|
||||
<workItem from="1677595224096" duration="799000" />
|
||||
<workItem from="1677674512203" duration="1323000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
@ -234,6 +239,6 @@
|
||||
<SUITE FILE_PATH="coverage/MarioWeb$MarioWeb.coverage" NAME="MarioWeb Coverage Results" MODIFIED="1669305478201" 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$test.coverage" NAME="test Coverage Results" MODIFIED="1668079935841" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
<SUITE FILE_PATH="coverage/MarioWeb$Flask__main_py_.coverage" NAME="Flask (main.py) Coverage Results" MODIFIED="1677224605926" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
|
||||
<SUITE FILE_PATH="coverage/MarioWeb$Flask__main_py___1_.coverage" NAME="Flask (main.py) (1) Coverage Results" MODIFIED="1677568713708" 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___1_.coverage" NAME="Flask (main.py) (1) Coverage Results" MODIFIED="1677675778967" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
|
||||
</component>
|
||||
</project>
|
17
IDManager.py
17
IDManager.py
@ -5,9 +5,11 @@ import csv
|
||||
class idManager():
|
||||
levelNum = 200
|
||||
typeNum = 100
|
||||
gid = 0
|
||||
|
||||
timeMin = 1
|
||||
tutorialMax = 3
|
||||
ip_id = {}
|
||||
ip_dic = {}
|
||||
ip_recent = {}
|
||||
ip_control = {}
|
||||
@ -19,6 +21,15 @@ class idManager():
|
||||
self.levelNum = 200
|
||||
self.typeNum = 100
|
||||
self.timeMin = 1
|
||||
self.gid = 0
|
||||
|
||||
def iniId(self, ip):
|
||||
self.gid += 1
|
||||
self.ip_dic[ip] = str(self.gid)
|
||||
return str(self.gid)
|
||||
|
||||
def getId(self, ip):
|
||||
return self.ip_dic[ip]
|
||||
|
||||
def getLevels(self, ip):
|
||||
if ip not in self.ip_dic.keys():
|
||||
@ -45,19 +56,19 @@ class idManager():
|
||||
tmp = random.randint(0, self.typeNum - 1)
|
||||
while "c" + str(tmp) in self.ip_type[ip]:
|
||||
tmp = random.randint(0, self.typeNum - 1)
|
||||
result[0] = "Collector-"+str(tmp)
|
||||
result[0] = "Collector-" + str(tmp)
|
||||
self.ip_type[ip].append("c" + str(tmp))
|
||||
|
||||
tmp = random.randint(0, self.typeNum - 1)
|
||||
while "k" + str(tmp) in self.ip_type[ip]:
|
||||
tmp = random.randint(0, self.typeNum - 1)
|
||||
result[1] = "Killer-"+str(tmp)
|
||||
result[1] = "Killer-" + str(tmp)
|
||||
self.ip_type[ip].append("k" + str(tmp))
|
||||
|
||||
tmp = random.randint(0, self.typeNum - 1)
|
||||
while "r" + str(tmp) in self.ip_type[ip]:
|
||||
tmp = random.randint(0, self.typeNum - 1)
|
||||
result[2] = "Runner-"+str(tmp)
|
||||
result[2] = "Runner-" + str(tmp)
|
||||
self.ip_type[ip].append("r" + str(tmp))
|
||||
|
||||
self.ip_recent[ip] = result
|
||||
|
Binary file not shown.
@ -23,20 +23,10 @@ public class Play {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
//MarioGame game = new MarioGame();
|
||||
|
||||
// String levelPath = String.format("/app/levels/group%s/%s.txt", groupID, levelName); // For web
|
||||
// String repPath = String.format("/files/tmp.rep"); // For web
|
||||
/* game.setLives(10);
|
||||
String levelPath = "./levels/group0/f_l.txt"; // For local
|
||||
String repPath = "./reps/f_l_sav.rep"; */ // For local
|
||||
// MarioResult r2 = game.playGame(getLevel(levelPath), repPath);
|
||||
//game.playGame(Replay.getRepAgentFromFile(repPath),getLevel(levelPath), 30, repPath,20);
|
||||
|
||||
// MarioGame game2 = new MarioGame();
|
||||
//FIXME: Debug Use
|
||||
//playGameMain("lvl1");
|
||||
|
||||
playJavaGame();
|
||||
System.out.println("Java: Play Java Main Function Done");
|
||||
}
|
||||
public static boolean initialGame(){
|
||||
@ -48,6 +38,20 @@ public class Play {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static byte[] playJavaGame(){
|
||||
MarioGame game = new MarioGame();
|
||||
game.setLives(5);
|
||||
String levelPath = "./levels/group0/f_l.txt"; // For local
|
||||
String repPath = "./reps/f_l_sav.rep"; // For local
|
||||
//MarioGame.verbose = true;
|
||||
//Play Game
|
||||
MarioResult tmpResult = game.playGame(new HumanAgent(false),getLevel(levelPath), 30, repPath,30);
|
||||
//Replay
|
||||
//MarioResult tmpResult = game.playGame(Replay.getRepAgentFromFile(repPath),getLevel(levelPath), 30, repPath,30);
|
||||
return Replay.serializeAgentEvents(tmpResult.getAgentEvents());
|
||||
|
||||
}
|
||||
|
||||
public static byte[] playGameMain(String levelName, int lives, boolean control,int time,int col){
|
||||
|
||||
String levelPath = String.format("/app/levels/%s.lvl", levelName); // For web
|
||||
|
@ -55,6 +55,10 @@ public class MarioRender extends JComponent implements FocusListener {
|
||||
}
|
||||
drawStringDropShadow(og, "Buttons: " + pressedButtons, 0, 2, 1);
|
||||
}
|
||||
//Render Status Info
|
||||
drawString(og,"Game Over! ",11,3,1,0.5f);
|
||||
drawString(og,"Game Over! ",11,5,1,0.5f);
|
||||
|
||||
if (scale > 1) {
|
||||
g.drawImage(image, 0, 0, (int) (256 * scale), (int) (240 * scale), null);
|
||||
} else {
|
||||
@ -62,6 +66,12 @@ public class MarioRender extends JComponent implements FocusListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void drawString(Graphics g, String text, int x, int y, int c,float scale){
|
||||
char[] ch = text.toCharArray();
|
||||
for (int i = 0; i < ch.length; i++) {
|
||||
g.drawImage(Assets.font[ch[i] - 32][c], x + i * 8, y,(int) (256 * scale), (int) (240 * scale), null);
|
||||
}
|
||||
}
|
||||
public void drawStringDropShadow(Graphics g, String text, int x, int y, int c) {
|
||||
drawString(g, text, x * 8 + 5, y * 8 + 5, 0);
|
||||
drawString(g, text, x * 8 + 4, y * 8 + 4, c);
|
||||
|
@ -42,9 +42,9 @@ public class Assets {
|
||||
}
|
||||
|
||||
private static Image getImage(GraphicsConfiguration gc, String imageName) throws IOException {
|
||||
//FIXME web/local
|
||||
//File file = new File(System.getProperty("user.dir") + "/img/" + imageName); // Local test
|
||||
File file = new File("/app/img/" + imageName); // For web
|
||||
//FIXME: web/local
|
||||
File file = new File(System.getProperty("user.dir") + "/img/" + imageName); // Local test
|
||||
//File file = new File("/app/img/" + imageName); // For web
|
||||
BufferedImage source = ImageIO.read(file);
|
||||
Image image = gc.createCompatibleImage(source.getWidth(), source.getHeight(), Transparency.BITMASK);
|
||||
Graphics2D g = (Graphics2D) image.getGraphics();
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,33 +1,35 @@
|
||||
IP,A-ID,B-ID,Anno,
|
||||
127.0.0.1,28,96,A,
|
||||
127.0.0.1,19,166,A,
|
||||
127.0.0.1,193,112,E,
|
||||
127.0.0.1,153,200,B,
|
||||
127.0.0.1,187,192,N,
|
||||
10.27.169.251,12,169,N,
|
||||
10.27.169.251,85,63,B,
|
||||
10.27.169.251,131,179,E,
|
||||
10.27.169.251,2,59,E,
|
||||
10.27.169.251,163,78,E,
|
||||
10.27.169.251,77,174,E,
|
||||
10.27.169.251,186,108,A,
|
||||
10.27.169.251,122,155,E,
|
||||
10.27.169.251,32,148,A,
|
||||
127.0.0.1,166,46,N,
|
||||
127.0.0.1,54,167,N,
|
||||
127.0.0.1,26,49,B,
|
||||
127.0.0.1,38,154,N,
|
||||
127.0.0.1,168,74,B,
|
||||
127.0.0.1,82,101,N,
|
||||
127.0.0.1,178,4,A,
|
||||
10.27.169.251,160,121,N,
|
||||
10.27.169.251,69,124,N,
|
||||
10.27.169.251,165,79,A,
|
||||
127.0.0.1,160,84,N,
|
||||
127.0.0.1,75,17,N,
|
||||
127.0.0.1,69,73,N,
|
||||
127.0.0.1,31,125,N,
|
||||
127.0.0.1,56,57,N,
|
||||
127.0.0.1,200,144,N,
|
||||
127.0.0.1,43,129,B,
|
||||
127.0.0.1,71,60,N,
|
||||
IP,A-ID,B-ID,Anno
|
||||
127.0.0.1,28,96,A
|
||||
127.0.0.1,19,166,A
|
||||
127.0.0.1,193,112,E
|
||||
127.0.0.1,153,200,B
|
||||
127.0.0.1,187,192,N
|
||||
10.27.169.251,12,169,N
|
||||
10.27.169.251,85,63,B
|
||||
10.27.169.251,131,179,E
|
||||
10.27.169.251,2,59,E
|
||||
10.27.169.251,163,78,E
|
||||
10.27.169.251,77,174,E
|
||||
10.27.169.251,186,108,A
|
||||
10.27.169.251,122,155,E
|
||||
10.27.169.251,32,148,A
|
||||
127.0.0.1,166,46,N
|
||||
127.0.0.1,54,167,N
|
||||
127.0.0.1,26,49,B
|
||||
127.0.0.1,38,154,N
|
||||
127.0.0.1,168,74,B
|
||||
127.0.0.1,82,101,N
|
||||
127.0.0.1,178,4,A
|
||||
10.27.169.251,160,121,N
|
||||
10.27.169.251,69,124,N
|
||||
10.27.169.251,165,79,A
|
||||
127.0.0.1,160,84,N
|
||||
127.0.0.1,75,17,N
|
||||
127.0.0.1,69,73,N
|
||||
127.0.0.1,31,125,N
|
||||
127.0.0.1,56,57,N
|
||||
127.0.0.1,200,144,N
|
||||
127.0.0.1,43,129,B
|
||||
127.0.0.1,71,60,N
|
||||
1,169,21,B,
|
||||
1,199,148,B,
|
||||
|
Can't render this file because it has a wrong number of fields in line 34.
|
@ -201,3 +201,8 @@ IP,Style,Frequency,Age,Gender
|
||||
127.0.0.1,A,A,A,A,A,A,,
|
||||
127.0.0.1,A,A,A,A,A,A,,
|
||||
127.0.0.1,A,B,D,A,A,C,,
|
||||
127.0.0.1,A,A,B,A,A,A,,
|
||||
,C,A,A,C,A,A,,
|
||||
1,B,A,A,C,A,A,,
|
||||
1,A,A,A,D,A,A,,
|
||||
1,A,A,A,B,A,A,,
|
||||
|
|
31
main.py
31
main.py
@ -33,9 +33,10 @@ def gamepreplay():
|
||||
if request.method == 'POST':
|
||||
result = request.form
|
||||
ip = request.remote_addr
|
||||
cid = idm.iniId(ip)
|
||||
# Save the result to questionare
|
||||
idm.write_csv(questionarePath,
|
||||
[ip,
|
||||
[cid,
|
||||
result.get("playeds"),
|
||||
result.get("playedp"),
|
||||
result.get("gamestyle"),
|
||||
@ -43,11 +44,11 @@ def gamepreplay():
|
||||
result.get("age"),
|
||||
result.get("gender"),
|
||||
""])
|
||||
idm.setControl(ip, result.get("control"))
|
||||
idm.setControl(cid, result.get("control"))
|
||||
print(result.get("gamestyle"))
|
||||
return redirect(url_for('gametutorial', id=ip))
|
||||
return redirect(url_for('gametutorial', id=cid))
|
||||
# debug use:
|
||||
# return redirect(url_for('gameanno2', id=ip))
|
||||
# return redirect(url_for('gameanno2', id=cid))
|
||||
|
||||
|
||||
@app.route('/gametutorial/<id>')
|
||||
@ -58,7 +59,7 @@ def gametutorial(id):
|
||||
|
||||
@app.route('/again')
|
||||
def gamepreplayAgain():
|
||||
return redirect(url_for('gameplay', id=request.remote_addr))
|
||||
return redirect(url_for('gameplay', id=idm.getId(request.remote_addr)))
|
||||
|
||||
|
||||
@app.route('/gametutorial/<id>/data')
|
||||
@ -85,7 +86,7 @@ def getJSONData(id):
|
||||
|
||||
@app.route('/annotation')
|
||||
def gamepreanno():
|
||||
return redirect(url_for('gameanno', id=request.remote_addr))
|
||||
return redirect(url_for('gameanno', id=idm.getId(request.remote_addr)))
|
||||
|
||||
|
||||
@app.route('/annotation/<id>')
|
||||
@ -101,7 +102,7 @@ def gameanno(id):
|
||||
|
||||
@app.route('/annotation/radioresult', methods=['POST'])
|
||||
def getRadioData():
|
||||
ip = request.remote_addr
|
||||
ip = idm.getId(request.remote_addr)
|
||||
|
||||
if request.method == 'POST':
|
||||
print("POST Eval")
|
||||
@ -119,7 +120,7 @@ def getRadioData():
|
||||
|
||||
@app.route('/gameplay2')
|
||||
def gamepreplay2():
|
||||
return redirect(url_for('gameplay2', id=request.remote_addr))
|
||||
return redirect(url_for('gameplay2', id=idm.getId(request.remote_addr)))
|
||||
|
||||
|
||||
@app.route('/gameplay2/<id>')
|
||||
@ -141,7 +142,7 @@ def getJSONData2(id):
|
||||
|
||||
@app.route('/annotation2')
|
||||
def gamepreanno2():
|
||||
return redirect(url_for('gameanno2', id=request.remote_addr))
|
||||
return redirect(url_for('gameanno2', id=idm.getId(request.remote_addr)))
|
||||
|
||||
|
||||
@app.route('/annotation2/<id>')
|
||||
@ -163,11 +164,11 @@ def gameannoresult2(id):
|
||||
if request.method == 'POST':
|
||||
print("result! " + id)
|
||||
resultList = list(request.form)[0].split(",")
|
||||
levelList = idm.getRecent(request.remote_addr)
|
||||
levelList = idm.getRecent(idm.getId(request.remote_addr))
|
||||
print(resultList)
|
||||
|
||||
idm.write_csv(annotationPath2,
|
||||
[request.remote_addr, resultList[0], resultList[1], resultList[2], levelList[0], levelList[1],
|
||||
[idm.getId(request.remote_addr), resultList[0], resultList[1], resultList[2], levelList[0], levelList[1],
|
||||
levelList[2],
|
||||
""])
|
||||
|
||||
@ -180,12 +181,8 @@ def gameannoresult2(id):
|
||||
|
||||
@app.route("/gameover")
|
||||
def over():
|
||||
finish = idm.getTimes(request.remote_addr)
|
||||
# print("finish %d",finish)
|
||||
# if finish:
|
||||
# idm.setTimes(request.remote_addr)
|
||||
# else:
|
||||
# idm.addTimes(request.remote_addr)
|
||||
finish = idm.getTimes(idm.getId(request.remote_addr))
|
||||
|
||||
return render_template("GameOver.html", finish=1, stage=1)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user