Delete MarioForwardModel copy

This commit is contained in:
bigJIU 2023-03-01 21:45:41 +08:00
parent 897cb4a140
commit 58beec7b76
3 changed files with 7 additions and 207 deletions

Binary file not shown.

View File

@ -45,7 +45,7 @@ public class Play {
String repPath = "./reps/f_l_sav.rep"; // For local
//MarioGame.verbose = true;
//Play Game
MarioResult tmpResult = game.playGame(new HumanAgent(false),getLevel(levelPath), 1, repPath,30);
MarioResult tmpResult = game.playGame(new HumanAgent(false),getLevel(levelPath), 100, repPath,30);
//Replay
//MarioResult tmpResult = game.playGame(Replay.getRepAgentFromFile(repPath),getLevel(levelPath), 30, repPath,30);
return Replay.serializeAgentEvents(tmpResult.getAgentEvents());

View File

@ -167,7 +167,9 @@ public class MarioGame extends KeyAdapter{
}
MarioTimer agentTimer = new MarioTimer(MarioGame.maxTime);
this.agent.initialize(new MarioForwardModel(this.world.clone()), agentTimer);
//TODO: MarioForwardModel
//this.agent.initialize(new MarioForwardModel(this.world.clone()), agentTimer);
this.agent.initialize(null,agentTimer);
ArrayList<MarioEvent> gameEvents = new ArrayList<>();
ArrayList<MarioAgentEvent> agentEvents = new ArrayList<>();
@ -185,7 +187,9 @@ public class MarioGame extends KeyAdapter{
agentTimer = new MarioTimer(MarioGame.maxTime);
//get actions
boolean[] actions = this.agent.getActions(new MarioForwardModel(this.world), agentTimer);
//boolean[] actions = this.agent.getActions(new MarioForwardModel(this.world), agentTimer);
//TODO: MarioForwardModel
boolean[] actions = this.agent.getActions(null, agentTimer);
if (MarioGame.verbose) {
if (agentTimer.getRemainingTime() < 0 && Math.abs(agentTimer.getRemainingTime()) > MarioGame.graceTime) {
System.out.println("The Agent is slowing down the game by: "
@ -266,207 +270,3 @@ public class MarioGame extends KeyAdapter{
}
//package engine.core;
//
//import java.util.ArrayList;
//import java.awt.*;
//import java.awt.event.KeyAdapter;
//
//import javax.swing.JFrame;
//
//import agents.HumanAgent;
//import engine.helper.GameStatus;
//import engine.helper.MarioActions;
//import engine.helper.Replay;
//
//public class MarioGame {
// /**
// * the maximum time that agent takes for each step
// */
// public static final long maxTime = 40;
// /**
// * extra time before reporting that the agent is taking more time that it should
// */
// public static final long graceTime = 10;
// /**
// * Screen width
// */
// public static final int width = 256;
// /**
// * Screen height
// */
// public static final int height = 256;
// /**
// * Screen width in tiles
// */
// public static final int tileWidth = width / 16;
// /**
// * Screen height in tiles
// */
// public static final int tileHeight = height / 16;
// /**
// * print debug details
// */
// public static final boolean verbose = false;
//
// /**
// * pauses the whole game at any moment
// */
// public boolean pause = false;
//
// /**
// * events that kills the player when it happens only care about type and param
// */
// private MarioEvent[] killEvents;
//
// //visualization
// private JFrame window = null;
// private MarioRender render = null;
// private MarioAgent agent = null;
// private MarioWorld world = null;
//
// /**
// * Create a mario game to be played
// */
// public MarioGame() {
//
// }
//
// /**
// * Create a mario game with a different forward model where the player on certain event
// *
// * @param killEvents events that will kill the player
// */
// public MarioGame(MarioEvent[] killEvents) {
// this.killEvents = killEvents;
// }
//
// private int getDelay(int fps) {
// if (fps <= 0) {
// return 0;
// }
// return 1000 / fps;
// }
//
// private void setAgent(MarioAgent agent) {
// this.agent = agent;
// if (agent instanceof KeyAdapter) {
// this.render.addKeyListener((KeyAdapter) this.agent);
// }
// }
//
// /**
// * Play a certain mario level
// *
// * @param level a string that constitutes the mario level, it uses the same representation as the VGLC but with more details. for more details about each symbol check the json file in the levels folder.
// * @param timer number of ticks for that level to be played. Setting timer to anything &lt;=0 will make the time infinite
// * @return statistics about the current game
// */
// public byte[] playGame(String level, int timer) {
// return this.runGame(new HumanAgent(), level, timer, 0, true, 30, 2);
// }
//
// /**
// * Run a certain mario level with a certain agent
// *
// * @param agent the current AI agent used to play the game
// * @param level a string that constitutes the mario level, it uses the same representation as the VGLC but with more details. for more details about each symbol check the json file in the levels folder.
// * @param timer number of ticks for that level to be played. Setting timer to anything &lt;=0 will make the time infinite
// * @return statistics about the current game
// */
// public byte[] runGame(MarioAgent agent, String level, int timer) {
// return this.runGame(agent, level, timer, 0, true, 30, 2);
// }
//
// /**
// * Run a certain mario level with a certain agent
// *
// * @param agent the current AI agent used to play the game
// * @param level a string that constitutes the mario level, it uses the same representation as the VGLC but with more details. for more details about each symbol check the json file in the levels folder.
// * @param timer number of ticks for that level to be played. Setting timer to anything &lt;=0 will make the time infinite
// * @param marioState the initial state that mario appears in. 0 small mario, 1 large mario, and 2 fire mario.
// * @param visuals show the game visuals if it is true and false otherwise
// * @param fps the number of frames per second that the update function is following
// * @param scale the screen scale, that scale value is multiplied by the actual width and height
// * @return statistics about the current game
// */
// public byte[] runGame(MarioAgent agent, String level, int timer, int marioState, boolean visuals, int fps, float scale) {
// if (visuals) {
// this.window = new JFrame("Mario AI Framework");
// this.render = new MarioRender(scale);
// this.window.setContentPane(this.render);
// this.window.pack();
// this.window.setResizable(false);
// this.window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// this.render.init();
// this.window.setVisible(true);
// }
// this.setAgent(agent);
// return this.gameLoop(level, timer, marioState, visuals, fps);
// }
//
// private byte[] gameLoop(String level, int timer, int marioState, boolean visual, int fps) {
// this.world = new MarioWorld(this.killEvents);
// this.world.visuals = visual;
// this.world.initializeLevel(level, 1000 * timer);
// if (visual) {
// this.world.initializeVisuals(this.render.getGraphicsConfiguration());
// }
// this.world.mario.isLarge = marioState > 0;
// this.world.mario.isFire = marioState > 1;
// this.world.update(new boolean[MarioActions.numberOfActions()]);
// long currentTime = System.currentTimeMillis();
//
// //initialize graphics
// Image renderTarget = null;
// Graphics backBuffer = null;
// Graphics currentBuffer = null;
// if (visual) {
// renderTarget = this.render.createImage(MarioGame.width, MarioGame.height);
// backBuffer = this.render.getGraphics();
// currentBuffer = renderTarget.getGraphics();
// this.render.addFocusListener(this.render);
// }
//
// MarioTimer agentTimer = new MarioTimer(MarioGame.maxTime);
// this.agent.initialize(new MarioForwardModel(this.world.clone()), agentTimer);
//
// ArrayList<MarioEvent> gameEvents = new ArrayList<>();
// ArrayList<MarioAgentEvent> agentEvents = new ArrayList<>();
// while (this.world.gameStatus == GameStatus.RUNNING) {
// if (!this.pause) {
// //get actions
// agentTimer = new MarioTimer(MarioGame.maxTime);
// boolean[] actions = this.agent.getActions(new MarioForwardModel(this.world.clone()), agentTimer);
// if (MarioGame.verbose) {
// if (agentTimer.getRemainingTime() < 0 && Math.abs(agentTimer.getRemainingTime()) > MarioGame.graceTime) {
// System.out.println("The Agent is slowing down the game by: "
// + Math.abs(agentTimer.getRemainingTime()) + " msec.");
// }
// }
// // update world
// this.world.update(actions);
// gameEvents.addAll(this.world.lastFrameEvents);
// agentEvents.add(new MarioAgentEvent(actions, this.world.mario.x,
// this.world.mario.y, (this.world.mario.isLarge ? 1 : 0) + (this.world.mario.isFire ? 1 : 0),
// this.world.mario.onGround, this.world.currentTick));
// }
//
// //render world
// if (visual) {
// this.render.renderWorld(this.world, renderTarget, backBuffer, currentBuffer);
// }
// //check if delay needed
// if (this.getDelay(fps) > 0) {
// try {
// currentTime += this.getDelay(fps);
// Thread.sleep(Math.max(0, currentTime - System.currentTimeMillis()));
// } catch (InterruptedException e) {
// break;
// }
// }
// }
// return Replay.serializeAgentEvents(agentEvents);
// }
//}