From cbe60166384caff59208a3cfad19550945062329 Mon Sep 17 00:00:00 2001
From: bigJIU <1572204178@qq.com>
Date: Wed, 1 Mar 2023 21:05:56 +0800
Subject: [PATCH] Update ID Based Routing
---
.idea/workspace.xml | 15 ++--
IDManager.py | 17 ++++-
Mario-AI-Interface/reps/f_l_sav.rep | Bin 107 -> 1009 bytes
Mario-AI-Interface/src/Play.java | 26 ++++---
.../src/engine/core/MarioRender.java | 10 +++
.../src/engine/helper/Assets.java | 6 +-
__pycache__/IDManager.cpython-39.pyc | Bin 3655 -> 3990 bytes
__pycache__/main.cpython-39.pyc | Bin 5913 -> 6012 bytes
data/annotation.csv | 68 +++++++++---------
data/questionare.csv | 5 ++
main.py | 31 ++++----
11 files changed, 106 insertions(+), 72 deletions(-)
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 4c6350b..c891061 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,11 +3,14 @@
+
+
+
+
+
-
-
-
+
@@ -212,7 +215,9 @@
-
+
+
+
@@ -234,6 +239,6 @@
-
+
\ No newline at end of file
diff --git a/IDManager.py b/IDManager.py
index fd1fe96..e2ae660 100644
--- a/IDManager.py
+++ b/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
diff --git a/Mario-AI-Interface/reps/f_l_sav.rep b/Mario-AI-Interface/reps/f_l_sav.rep
index f116d72d964196da943aaa6f1232ad49c7508c05..e664b0ceec27f1278b667956370b82afd9d1dda2 100644
GIT binary patch
literal 1009
ScmZQz7zLvtFd70QCIkQj@c;n;
literal 107
WcmZQzpe|ryVv<4tE+_zr$O8Zx!~y&O
diff --git a/Mario-AI-Interface/src/Play.java b/Mario-AI-Interface/src/Play.java
index 58762bc..dc0916d 100644
--- a/Mario-AI-Interface/src/Play.java
+++ b/Mario-AI-Interface/src/Play.java
@@ -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
diff --git a/Mario-AI-Interface/src/engine/core/MarioRender.java b/Mario-AI-Interface/src/engine/core/MarioRender.java
index aa27868..8ca2fb2 100644
--- a/Mario-AI-Interface/src/engine/core/MarioRender.java
+++ b/Mario-AI-Interface/src/engine/core/MarioRender.java
@@ -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);
diff --git a/Mario-AI-Interface/src/engine/helper/Assets.java b/Mario-AI-Interface/src/engine/helper/Assets.java
index 8871912..6c8c967 100644
--- a/Mario-AI-Interface/src/engine/helper/Assets.java
+++ b/Mario-AI-Interface/src/engine/helper/Assets.java
@@ -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();
diff --git a/__pycache__/IDManager.cpython-39.pyc b/__pycache__/IDManager.cpython-39.pyc
index 70b2fb1f30d1f1f591e2732f4283d870d4e331a8..2dffa275c04b9d251c24cc28b85f590aeb41878a 100644
GIT binary patch
delta 1438
zcmZ`(Id2m|6rR~DYp>Tw4kvLO8v+3gIXD9nG(ZDV5+RamDT3vg2E5
zhs=vKl-}dWXC4RUX}~=lG|vFtGr{mIFkd{+uLsO?@s|b*Ivy}D12!a(vycP_IR`0l
zkvky`8RRa=LJqkbI-v`>2fCpLIS+a0Mec<@=tu5@0t_JcLlFj%3s8bG@&N3BoybKP
zf?dd^LD)URD#LLifT`+Yb>0`7Uoh!SKoDH+;d^;ePV@YbvBu_fV7SK7b03jnJ=O*}D|+CDw?IPKqxn$mT7&$+mtUY9uVKTQ$~
z-Rj>%`P2Et9r-a;DzqHm#7z-I{#-4*@koA84fB#LyW{J0lZ0v^rR14dXaMR2Hx9=L
z&8wcNym!$sO+eRK?--T{cN}U}L6@v$_
zM#&gYUOjL#;RhH^j9yGU@6j9o!uQ?MV4BiRpJ#Swp6C6TnU7;XM=Up!Nh==>_bTqM^L1#P98d%#*8rTH!I**<*Hts54AvWTjSKa
zQ1zQmJaP|s3O}?UO;hH&C+*pm6v@*HovM=ELS#{Mzhm9gWfAxNy~pqP9&br9k8;^BAWyC#HLe8SuJ~2uOV*9uZb@U7RAm|>{dms
z*s-XjP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vplUbHc{sA^pNiF~Y
delta 1617
zcmZ`(O>7%Q6y6zo*X#AJvv%U7Zu%2S6TGC@ZAzNvkEXvwB~8)<6)*y6RXeFoaH81>
zf+|tPk1AA&RMk5n4%kAKdg!I9IB-D-i6cTBu~hZIDHqBa0p-2%5|Amj-nVbQH#6_e
zdvE6V{HJ-xcN|N@-_1LJT>jyn(;2@6;?qsBLB9NA=BGjqn?5u#&lKHaOF8y&0~KH<)7Lw3l1L#UC=9V97+u+Fz*z1!%e@kxj~l_N{224vT`q0(hwx-8a*x{D%SM9WpHu(KCsukQ)j
zEAduHUSw9Bh6hf;d6#w$D>)6>U9XZlwudbeu80wEWt5?R)>(bn_v$@v*Vwd&HM7okT^@G
zo$D*k;n0h;QZNRO(s{3eOt24uN@wFuw3*2bb^zZ8{wIGN)x##c2Y_r?MkRe}fWO2pUVWH2!TSM&Lna%y')
@@ -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//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/')
@@ -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/')
@@ -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/')
@@ -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)