2022-10-20 12:08:31 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2022-10-21 09:46:57 +00:00
|
|
|
import agents.HumanAgent;
|
|
|
|
import agents.ReplayAgent;
|
2022-10-20 12:08:31 +00:00
|
|
|
import engine.core.MarioAgentEvent;
|
|
|
|
import engine.core.MarioGame;
|
|
|
|
import engine.core.MarioResult;
|
2022-10-21 09:46:57 +00:00
|
|
|
import engine.helper.Replay;
|
2022-10-20 12:08:31 +00:00
|
|
|
|
|
|
|
public class Play {
|
|
|
|
public static String getLevel(String filepath) {
|
|
|
|
String content = "";
|
|
|
|
try {
|
|
|
|
content = new String(Files.readAllBytes(Paths.get(filepath)));
|
|
|
|
} catch (IOException e) {
|
|
|
|
}
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
String groupID = args[0];
|
|
|
|
String levelName = args[1];
|
2022-10-30 13:56:48 +00:00
|
|
|
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 = String.format("./levels/group%s/%s.txt", groupID, levelName); // For local
|
|
|
|
String repPath = String.format("./reps/%s_sav.rep", levelName); // For local
|
|
|
|
MarioResult r2 = game.playGame(getLevel(levelPath), repPath);
|
2022-10-21 09:46:57 +00:00
|
|
|
// MarioResult tmpResult = game.playGame(Replay.getRepAgentFromFile(repPath),getLevel(levelPath), 200, repPath);
|
2022-10-20 12:08:31 +00:00
|
|
|
|
2022-10-21 09:46:57 +00:00
|
|
|
// MarioGame game2 = new MarioGame();
|
2022-10-20 12:08:31 +00:00
|
|
|
|
|
|
|
}
|
2022-10-21 09:46:57 +00:00
|
|
|
|
2022-10-30 13:56:48 +00:00
|
|
|
public static byte[] playGameMain(String groupID, String levelName, int lives){
|
2022-10-20 12:08:31 +00:00
|
|
|
|
2022-10-24 11:48:43 +00:00
|
|
|
String levelPath = String.format("/app/levels/%s.lvl", levelName); // For web
|
2022-10-21 09:46:57 +00:00
|
|
|
String repPath = String.format("/files/%s_sav.rep", levelName); // For web
|
|
|
|
MarioGame game = new MarioGame();
|
2022-10-30 13:56:48 +00:00
|
|
|
game.setLives(lives);
|
2022-10-21 09:46:57 +00:00
|
|
|
MarioResult tmpResult = game.playGame(new HumanAgent(),getLevel(levelPath), 200, repPath);
|
|
|
|
|
|
|
|
return Replay.serializeAgentEvents(tmpResult.getAgentEvents());
|
|
|
|
}
|
|
|
|
|
2022-10-30 13:56:48 +00:00
|
|
|
public static byte[] playGameMain(String groupID, String levelName){
|
|
|
|
return playGameMain(groupID, levelName, 0);
|
|
|
|
}
|
|
|
|
|
2022-10-21 09:46:57 +00:00
|
|
|
public static void replayGameMain(String groupID, String levelName){
|
2022-10-24 11:48:43 +00:00
|
|
|
String levelPath = String.format("/app/levels/%s.lvl", levelName); // For web
|
2022-10-21 09:46:57 +00:00
|
|
|
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);
|
2022-10-20 12:08:31 +00:00
|
|
|
}
|
|
|
|
}
|