Replay over
This commit is contained in:
parent
8c37071d49
commit
fcfdf8e844
36
.idea/workspace.xml
generated
36
.idea/workspace.xml
generated
@ -2,15 +2,13 @@
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="c32bfd4e-6189-47f3-9d6c-c1825d3d7e5f" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/.idea/MarioWeb.iml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/artifacts/Mario_AI_Interface_jar.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/libraries/Mario_AI_Interface.xml" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Flask/main.py" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/play.html" beforeDir="false" afterPath="$PROJECT_DIR$/play.html" 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/engine/core/MarioGame.java" beforeDir="false" afterPath="$PROJECT_DIR$/Mario-AI-Interface/src/engine/core/MarioGame.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$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/templates/play.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/play.html" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -28,16 +26,16 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"WebServerToolWindowFactoryState": "false",
|
||||
"last_opened_file_path": "C:/Users/duaho/Projects/website materials/MarioWeb",
|
||||
"nodejs_package_manager_path": "npm"
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||
"WebServerToolWindowFactoryState": "false",
|
||||
"last_opened_file_path": "C:/Users/duaho/Projects/website materials/MarioWeb/Mario-AI-Interface",
|
||||
"nodejs_package_manager_path": "npm"
|
||||
}
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="RunManager" selected="Flask server.Flask (main.py)">
|
||||
<configuration name="MarioWeb" type="PythonConfigurationType" factoryName="Python">
|
||||
<module name="MarioWeb" />
|
||||
@ -91,6 +89,8 @@
|
||||
<option name="presentableId" value="Default" />
|
||||
<updated>1666269904844</updated>
|
||||
<workItem from="1666269906002" duration="7106000" />
|
||||
<workItem from="1666331056069" duration="7259000" />
|
||||
<workItem from="1666340478319" duration="84000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
@ -109,6 +109,6 @@
|
||||
</option>
|
||||
</component>
|
||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||
<SUITE FILE_PATH="coverage/MarioWeb$Flask__main_py_.coverage" NAME="Flask (main.py) Coverage Results" MODIFIED="1666277231897" 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="1666345159743" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
|
||||
</component>
|
||||
</project>
|
File diff suppressed because one or more lines are too long
BIN
Mario-AI-Interface/reps/f_l_sav.rep
Normal file
BIN
Mario-AI-Interface/reps/f_l_sav.rep
Normal file
Binary file not shown.
@ -3,9 +3,12 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import agents.HumanAgent;
|
||||
import agents.ReplayAgent;
|
||||
import engine.core.MarioAgentEvent;
|
||||
import engine.core.MarioGame;
|
||||
import engine.core.MarioResult;
|
||||
import engine.helper.Replay;
|
||||
|
||||
public class Play {
|
||||
public static String getLevel(String filepath) {
|
||||
@ -16,46 +19,43 @@ public class Play {
|
||||
}
|
||||
return content;
|
||||
}
|
||||
public static byte[] serializeAgentEvents(ArrayList<MarioAgentEvent> events) {
|
||||
byte[] content = new byte[events.size()];
|
||||
for (int i = 0; i < events.size(); i++) {
|
||||
boolean[] action = events.get(i).getActions();
|
||||
// System.out.println(action);
|
||||
content[i] = serializeAction(action);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
public static byte serializeAction(boolean[] action) {
|
||||
byte res = 0;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (action[i])
|
||||
res += 1 << i;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
String groupID = args[0];
|
||||
String levelName = args[1];
|
||||
String participantID = args[2];
|
||||
// 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
|
||||
//
|
||||
// String levelPath = String.format("./levels/group%s/%s.txt", groupID, levelName); // For local
|
||||
// String repPath = String.format("./reps/%s_sav.rep", levelName); // For local
|
||||
// MarioResult tmpResult = game.playGame(Replay.getRepAgentFromFile(repPath),getLevel(levelPath), 200, repPath);
|
||||
|
||||
String levelPath = String.format("/app/levels/group%s/%s.txt", groupID, levelName); // For web
|
||||
//String repPath = String.format("/files/reps/participant%s/%s.rep", participantID, levelName); // For web
|
||||
String repPath = String.format("/files/1.rep"); // For web
|
||||
//String levelPath = String.format("./levels/group%s/%s.txt", groupID, levelName); // For web
|
||||
//String repPath = String.format("./reps/participant%s/%s.rep", participantID, levelName); // For web
|
||||
//MarioResult tmpResult = game.playGame(getLevel(levelPath), 200, repPath);
|
||||
//return serializeAgentEvents(tmpResult.getAgentEvents());
|
||||
// MarioGame game2 = new MarioGame();
|
||||
// MarioResult r2 = game2.playGame(getLevel(levelPath),200,repPath)
|
||||
|
||||
}
|
||||
public static byte[] otherMain(String groupID, String levelName, String participantID){
|
||||
|
||||
public static byte[] playGameMain(String groupID, String levelName){
|
||||
|
||||
String levelPath = String.format("/app/levels/group%s/%s.txt", groupID, levelName); // For web
|
||||
String repPath = String.format("/files/%s_sav.rep", levelName); // For web
|
||||
|
||||
MarioGame game = new MarioGame();
|
||||
MarioResult tmpResult = game.playGame(new HumanAgent(),getLevel(levelPath), 200, repPath);
|
||||
|
||||
return Replay.serializeAgentEvents(tmpResult.getAgentEvents());
|
||||
}
|
||||
|
||||
public static void replayGameMain(String groupID, String levelName){
|
||||
String levelPath = String.format("/app/levels/group%s/%s.txt", groupID, levelName); // For web
|
||||
//String repPath = String.format("/files/reps/participant%s/%s.rep", participantID, levelName); // For web
|
||||
String repPath = String.format("/files/1.rep"); // For web
|
||||
MarioResult tmpResult = game.playGame(getLevel(levelPath), 200, repPath);
|
||||
return serializeAgentEvents(tmpResult.getAgentEvents());
|
||||
String repPath = String.format("/files/%s_sav.rep", levelName); // For web
|
||||
|
||||
// String levelPath = String.format("/app/levels/group%s/%s.txt", groupID, levelName); // For local
|
||||
// String repPath = String.format("./files/%s_sav.rep", levelName); // For local
|
||||
|
||||
MarioGame game = new MarioGame();
|
||||
game.playGame(Replay.getRepAgentFromFile(repPath),getLevel(levelPath), 200, repPath);
|
||||
}
|
||||
}
|
||||
|
@ -94,8 +94,8 @@ public class MarioGame {
|
||||
* @param timer number of ticks for that level to be played. Setting timer to anything <=0 will make the time infinite
|
||||
* @return statistics about the current game
|
||||
*/
|
||||
public MarioResult playGame(String level, int timer, String resultPath) {
|
||||
return this.runGame(new HumanAgent(), level, timer, 0, true, 30, 2, resultPath);
|
||||
public MarioResult playGame(MarioAgent gameAgent,String level, int timer, String resultPath) {
|
||||
return this.runGame(gameAgent, level, timer, 0, true, 30, 2, resultPath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,6 +42,7 @@ 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
|
||||
BufferedImage source = ImageIO.read(file);
|
||||
|
Binary file not shown.
15
main.py
15
main.py
@ -2,21 +2,28 @@ from flask import Flask, render_template, request, redirect, url_for
|
||||
|
||||
app = Flask(__name__, static_folder='')
|
||||
|
||||
bufferJson = ['']
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
py2htmlstr = 'py2html test str'
|
||||
return render_template('play.html', py2htmlstr=py2htmlstr)
|
||||
|
||||
@app.route('/dataPage')
|
||||
def dataPage(data):
|
||||
return data
|
||||
|
||||
@app.route('/datapage')
|
||||
def datapage():
|
||||
return bufferJson
|
||||
|
||||
|
||||
@app.route('/', methods=['POST'])
|
||||
def getData():
|
||||
if request.method == 'POST':
|
||||
print("POST")
|
||||
print(request.json)
|
||||
return redirect(url_for('dataPage',data = request.json))
|
||||
return redirect(url_for('datapage'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.debug = True
|
||||
app.run()
|
||||
app.run(debug=True)
|
@ -4,17 +4,10 @@
|
||||
<meta charset="utf-8">
|
||||
<title>CheerpJ test</title>
|
||||
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
<br />{{ py2htmlstr }}
|
||||
<script>
|
||||
function showPreloadProgress(loadedFiles, totalFiles)
|
||||
{
|
||||
console.log("Percentage loaded "+(loadedFiles*100/totalFiles));
|
||||
window.onload = function () {
|
||||
|
||||
}
|
||||
//上传测井数据表到服务器数据库
|
||||
function PostToServer(data) {
|
||||
|
||||
var httpRequest = new XMLHttpRequest();//第一步:建立所需的对象
|
||||
@ -31,24 +24,52 @@
|
||||
//httpRequest.send((""+data));
|
||||
}
|
||||
|
||||
var cheerpjListener = {preloadProgress:showPreloadProgress};
|
||||
cheerpjInit({listener:cheerpjListener});
|
||||
//cheerpjInit();
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
<br />{{ py2htmlstr }}
|
||||
<script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cheerpjInit();
|
||||
cheerpjCreateDisplay(800,600);
|
||||
//cheerpjRunMain("Play", "/app/Mario-AI-Interface.jar", "0", "f_l", "0");
|
||||
cheerpjRunMain("Play", "/app/Mario-AI-Interface.jar", "0", "f_l");
|
||||
|
||||
console.log("done");
|
||||
|
||||
cheerpjRunJar("/app/Mario-AI-Interface.jar");
|
||||
var returnVal = cjCall("Play", "otherMain", "0", "f_l", "0");//
|
||||
returnVal.then(function(e) {
|
||||
//cheerpjRunJar("/app/Mario-AI-Interface.jar");
|
||||
var returnVal = cjCall("Play", "playGameMain", "0", "f_l");
|
||||
|
||||
returnVal.then(function(){
|
||||
console.log("the return val is ready");
|
||||
console.log(returnVal.value);
|
||||
PostToServer(returnVal.value);
|
||||
});
|
||||
|
||||
//.then(function(){console.log(" over2 ");});
|
||||
//.catch((e) => {});
|
||||
|
||||
|
||||
}).catch(e => console.log("Critical failure: " + e.message));
|
||||
//console.log(returnVal);
|
||||
// cheerpjRunJar("/app/Mario-AI-Interface.jar");
|
||||
// var actionSequenceInBytes = cjCall("MarioProxy", "play", "0", "f_l", "0");
|
||||
|
||||
</script>
|
||||
<form>
|
||||
<input type="button" id="replayButton" value="Replay">
|
||||
</form>
|
||||
<script>
|
||||
var button = document.getElementById("replayButton");
|
||||
button.onclick = function(){
|
||||
//alert("WTF?")
|
||||
cjCall("Play", "replayGameMain", "0", "f_l");
|
||||
};
|
||||
</script>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user