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 @@ + + + + + - - - + @@ -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 f116d72..e664b0c 100644 Binary files a/Mario-AI-Interface/reps/f_l_sav.rep and b/Mario-AI-Interface/reps/f_l_sav.rep differ 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 70b2fb1..2dffa27 100644 Binary files a/__pycache__/IDManager.cpython-39.pyc and b/__pycache__/IDManager.cpython-39.pyc differ diff --git a/__pycache__/main.cpython-39.pyc b/__pycache__/main.cpython-39.pyc index f2b0ce9..b9a6933 100644 Binary files a/__pycache__/main.cpython-39.pyc and b/__pycache__/main.cpython-39.pyc differ diff --git a/data/annotation.csv b/data/annotation.csv index a982fdc..4aebaf0 100644 --- a/data/annotation.csv +++ b/data/annotation.csv @@ -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, diff --git a/data/questionare.csv b/data/questionare.csv index 80d7c0f..62d2b37 100644 --- a/data/questionare.csv +++ b/data/questionare.csv @@ -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,, diff --git a/main.py b/main.py index 2057b9b..1bb9910 100644 --- a/main.py +++ b/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/') @@ -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)