Play Done

This commit is contained in:
bigJIU 2022-10-24 19:48:43 +08:00
parent 90519a84f0
commit f5563685b2
8 changed files with 128 additions and 51 deletions

1
.gitignore vendored
View File

@ -23,3 +23,4 @@
hs_err_pid*
replay_pid*
*.xml
.idea/workspace.xml

5
.idea/workspace.xml generated
View File

@ -2,11 +2,10 @@
<project version="4">
<component name="ChangeListManager">
<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$/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>
@ -109,6 +108,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="1666345159743" 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="1666606996030" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
</component>
</project>

View File

@ -200,4 +200,4 @@ function _c4F26engine7sprites5ShellC2E0(r,q,o,n,m,l,p){var c=null;var a=new crea
function N4Play(){N4java4lang6Object.call(this);}
N4Play.cl=cheerpjCL;
function N4PlayX(a){a.f=N4PlayX;if(cheerpjSafeInitGuard('N4Play')) return;var q=a.q=N4Play.prototype=Object.create(N4java4lang6Object.prototype);q.constructor=N4Play;N4PlayG=1;cheerpjSafeInitFinish('N4Play');}
function _d4pYPlayC2E0(d,p){_n4VYObjectC2E0(d,p);}function _d4_ZPlay8getLevelE1(h,p){var e=null,d=null,c=null;var a={p:p,pc:0,f:_d4_ZPlay8getLevelE1,h:h,e:null,d:null,c:null};a.pc=0;;a.e=e=cheerpjInternString("");a.d=d=new N4java4lang6String();a.c=c=["[Ljava/lang/String;"];for(var i=1;i<=0;i=i+1|0)c[i|0]=null;;a.pc=12;;if((N4java3nio4file5PathsG|0)==0){cjG(a);};a.pc=13;a.c=c=_h4VaSkWorJxGSqKNcmDiDBqm5vd(h,c,a);a.pc=1;;a.pc=15;;if((N4java3nio4file5FilesG|0)==0){cjG(a);};a.pc=16;c=_h4VaSkWoCJxGSqK_HSqivBhramOTSSHnri5Pxd(c,a);a.pc=2;;a.pc=18;_t4VacmSx9n(d,c,a);a.pc=3;;return d;}function ed4_ZPlay8getLevelE1(a,b){a.f=ed4_ZPlay8getLevelE1;var h=a.h,e=a.e,d=a.d,c=a.c;var pc=a.pc;a.pc=4;;a.d=d=b;if((pc>=3&&pc<22)&&self.hasOwnProperty("N4java2io11IOException")&&(b instanceof N4java2io11IOException)|0){a.pc=5;;return e;}else{a.pc=6;;a.pc=-1;return;}}function _d4_YPlay4mainE2(d,p){d[1];d[2];}function _d4p1Play12playGameMainE3(l,k,p){var e=null,c=null,d=null,g=null;var a={p:p,pc:0,f:_d4p1Play12playGameMainE3,k:k,e:null,c:null,d:null,g:null};e=cheerpjInternString("/app/levels/group%s/%s.txt");c=["[Ljava/lang/Object;"];for(var i=1;i<=2;i=i+1|0)c[i|0]=null;;c[1]=l;c[2]=k;a.pc=-281;a.e=e=_t4VY6formatE78(e,c,a);c=cheerpjInternString("/files/%s_sav.rep");d=["[Ljava/lang/Object;"];for(var i=1;i<=1;i=i+1|0)d[i|0]=null;;d[1]=k;a.pc=-434;a.c=c=_t4VY6formatE78(c,d,a);a.pc=-473;;if((N6engine4core9MarioGameG|0)==0){cjG(a);};a.d=d=new N6engine4core9MarioGame();a.pc=-565;_c4V26engine4core9MarioGameC2E0(d,a);a.pc=-612;;if((N6agents10HumanAgentG|0)==0){cjG(a);};a.g=g=new N6agents10HumanAgent();a.pc=-698;_c4Vaw0SbrZKunDifdqJgrmiGac7rd(g,a);a.pc=-744;e=_d4_ZPlay8getLevelE1(e,a);a.pc=-782;e=d.v11(d,g,e,200,c,a);a.pc=-815;a.e=e=e.v16(e,a);a.pc=-842;;if((N6engine6helper6ReplayG|0)==0){cjG(a);};return _c4F76engine6helper6Replay20serializeAgentEventsE2(e,p);}function _d4V1Play14replayGameMainE4(l,k,p){var e=null,c=null,d=null,g=null;var a={p:p,pc:0,f:_d4V1Play14replayGameMainE4,k:k,e:null,c:null,d:null,g:null};e=cheerpjInternString("/app/levels/group%s/%s.txt");c=["[Ljava/lang/Object;"];for(var i=1;i<=2;i=i+1|0)c[i|0]=null;;c[1]=l;c[2]=k;a.pc=-285;a.e=e=_t4VY6formatE78(e,c,a);c=cheerpjInternString("/files/%s_sav.rep");d=["[Ljava/lang/Object;"];for(var i=1;i<=1;i=i+1|0)d[i|0]=null;;d[1]=k;a.pc=-438;a.c=c=_t4VY6formatE78(c,d,a);a.pc=-477;;if((N6engine4core9MarioGameG|0)==0){cjG(a);};a.d=d=new N6engine4core9MarioGame();a.pc=-569;_c4V26engine4core9MarioGameC2E0(d,a);a.pc=-616;;if((N6engine6helper6ReplayG|0)==0){cjG(a);};a.pc=-671;a.g=g=_c4p76engine6helper6Replay19getRepAgentFromFileE1(c,a);a.pc=-742;e=_d4_ZPlay8getLevelE1(e,a);d.v11(d,g,e,200,c,p);}
function _d4pYPlayC2E0(d,p){_n4VYObjectC2E0(d,p);}function _d4_ZPlay8getLevelE1(h,p){var e=null,d=null,c=null;var a={p:p,pc:0,f:_d4_ZPlay8getLevelE1,h:h,e:null,d:null,c:null};a.pc=0;;a.e=e=cheerpjInternString("");a.d=d=new N4java4lang6String();a.c=c=["[Ljava/lang/String;"];for(var i=1;i<=0;i=i+1|0)c[i|0]=null;;a.pc=12;;if((N4java3nio4file5PathsG|0)==0){cjG(a);};a.pc=13;a.c=c=_h4VaSkWorJxGSqKNcmDiDBqm5vd(h,c,a);a.pc=1;;a.pc=15;;if((N4java3nio4file5FilesG|0)==0){cjG(a);};a.pc=16;c=_h4VaSkWoCJxGSqK_HSqivBhramOTSSHnri5Pxd(c,a);a.pc=2;;a.pc=18;_t4VacmSx9n(d,c,a);a.pc=3;;return d;}function ed4_ZPlay8getLevelE1(a,b){a.f=ed4_ZPlay8getLevelE1;var h=a.h,e=a.e,d=a.d,c=a.c;var pc=a.pc;a.pc=4;;a.d=d=b;if((pc>=3&&pc<22)&&self.hasOwnProperty("N4java2io11IOException")&&(b instanceof N4java2io11IOException)|0){a.pc=5;;return e;}else{a.pc=6;;a.pc=-1;return;}}function _d4_YPlay4mainE2(d,p){d[1];d[2];}function _d4p1Play12playGameMainE3(l,k,p){var e=null,d=null,c=null,g=null;var a={p:p,pc:0,f:_d4p1Play12playGameMainE3,k:k,e:null,d:null,c:null,g:null};e=cheerpjInternString("/app/levels/%s.lvl");d=["[Ljava/lang/Object;"];for(var i=1;i<=1;i=i+1|0)d[i|0]=null;;d[1]=k;a.pc=-266;a.e=e=_t4VY6formatE78(e,d,a);d=cheerpjInternString("/files/%s_sav.rep");c=["[Ljava/lang/Object;"];for(var i=1;i<=1;i=i+1|0)c[i|0]=null;;c[1]=k;a.pc=-419;a.d=d=_t4VY6formatE78(d,c,a);a.pc=-458;;if((N6engine4core9MarioGameG|0)==0){cjG(a);};a.c=c=new N6engine4core9MarioGame();a.pc=-550;_c4V26engine4core9MarioGameC2E0(c,a);a.pc=-597;;if((N6agents10HumanAgentG|0)==0){cjG(a);};a.g=g=new N6agents10HumanAgent();a.pc=-683;_c4Vaw0SbrZKunDifdqJgrmiGac7rd(g,a);a.pc=-729;e=_d4_ZPlay8getLevelE1(e,a);a.pc=-767;e=c.v11(c,g,e,200,d,a);a.pc=-800;a.e=e=e.v16(e,a);a.pc=-827;;if((N6engine6helper6ReplayG|0)==0){cjG(a);};return _c4F76engine6helper6Replay20serializeAgentEventsE2(e,p);}function _d4V1Play14replayGameMainE4(l,k,p){var e=null,c=null,d=null,g=null;var a={p:p,pc:0,f:_d4V1Play14replayGameMainE4,k:k,e:null,c:null,d:null,g:null};e=cheerpjInternString("/app/levels/%s.lvl");c=["[Ljava/lang/Object;"];for(var i=1;i<=1;i=i+1|0)c[i|0]=null;;c[1]=k;a.pc=-270;a.e=e=_t4VY6formatE78(e,c,a);c=cheerpjInternString("/files/%s_sav.rep");d=["[Ljava/lang/Object;"];for(var i=1;i<=1;i=i+1|0)d[i|0]=null;;d[1]=k;a.pc=-423;a.c=c=_t4VY6formatE78(c,d,a);a.pc=-462;;if((N6engine4core9MarioGameG|0)==0){cjG(a);};a.d=d=new N6engine4core9MarioGame();a.pc=-554;_c4V26engine4core9MarioGameC2E0(d,a);a.pc=-601;;if((N6engine6helper6ReplayG|0)==0){cjG(a);};a.pc=-656;a.g=g=_c4p76engine6helper6Replay19getRepAgentFromFileE1(c,a);a.pc=-727;e=_d4_ZPlay8getLevelE1(e,a);d.v11(d,g,e,200,c,p);}

View File

@ -39,7 +39,7 @@ public class Play {
public static byte[] playGameMain(String groupID, String levelName){
String levelPath = String.format("/app/levels/group%s/%s.txt", groupID, levelName); // For web
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();
@ -49,7 +49,7 @@ public class Play {
}
public static void replayGameMain(String groupID, String levelName){
String levelPath = String.format("/app/levels/group%s/%s.txt", groupID, levelName); // For web
String levelPath = String.format("/app/levels/%s.lvl", levelName); // For web
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

Binary file not shown.

View File

@ -15,6 +15,11 @@ def datapage():
return bufferJson
@app.route('/eval')
def eval():
return render_template('eval.html')
@app.route('/', methods=['POST'])
def getData():
if request.method == 'POST':

44
templates/eval.html Normal file
View File

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
</head>
<div id="replayWindow">
<div id="replayWindowGame">
</div>
<div align="center"><button onClick="closeReplayWindow()">Close Window</button></div>
</div>
<body>
<div align="center"><button onClick="Replay('test1')">Replay Game1</button></div>
<div align="center"><button onClick="Replay('test2')">Replay Game2</button></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);
}
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>
</body>
</html>

View File

@ -5,71 +5,99 @@
<title>CheerpJ test</title>
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
<script>
window.onload = function () {
//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(returnVal.value);
});
}
function Replay(){
cjCall("Play", "replayGameMain", "test2", "test2");
};
function GameOver(){
if(alert("Game Over!")){
}
}
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('添加成功');
//alert('添加成功');
}
}
console.log(typeof Array.from(data));
console.log(Array.from(data));
// console.log(typeof Array.from(data));
// console.log(Array.from(data));
httpRequest.send(JSON.stringify(Array.from(data))); //设置为发送给服务器数据
//httpRequest.send((""+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>
<br />{{ py2htmlstr }}
<script>
//Init Cheerpj Framework
cheerpjInit();
cheerpjCreateDisplay(800,600);
/*
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("done");
console.log("Cheerpj Initialize Succeed!");
//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) => {});
//console.log(returnVal);
// cheerpjRunJar("/app/Mario-AI-Interface.jar");
// var actionSequenceInBytes = cjCall("MarioProxy", "play", "0", "f_l", "0");
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>
<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>