diff --git a/src/main/java/evironment/jumpingDino/DinoStateWithSpeed.java b/src/main/java/evironment/jumpingDino/DinoStateWithSpeed.java index debe679..a110f38 100644 --- a/src/main/java/evironment/jumpingDino/DinoStateWithSpeed.java +++ b/src/main/java/evironment/jumpingDino/DinoStateWithSpeed.java @@ -28,7 +28,7 @@ public class DinoStateWithSpeed extends DinoState{ DinoStateWithSpeed that = (DinoStateWithSpeed) o; return getObstacleSpeed() == that.getObstacleSpeed(); } - + @Override public int hashCode() { return Objects.hash(super.hashCode(), getObstacleSpeed()); diff --git a/src/main/java/evironment/jumpingDino/DinoWorld.java b/src/main/java/evironment/jumpingDino/DinoWorld.java index 9ca4fbf..7792b14 100644 --- a/src/main/java/evironment/jumpingDino/DinoWorld.java +++ b/src/main/java/evironment/jumpingDino/DinoWorld.java @@ -16,12 +16,14 @@ public class DinoWorld implements Environment, Visualizable { private Obstacle currentObstacle; private boolean randomObstacleSpeed; private boolean randomObstacleDistance; + private DinoWorldComponent comp; public DinoWorld(boolean randomObstacleSpeed, boolean randomObstacleDistance){ this.randomObstacleSpeed = randomObstacleSpeed; this.randomObstacleDistance = randomObstacleDistance; dino = new Dino(Config.DINO_SIZE, Config.DINO_STARTING_X, Config.FRAME_HEIGHT - Config.GROUND_Y - Config.DINO_SIZE, 0, 0, Color.GREEN); spawnNewObstacle(); + comp = new DinoWorldComponent(this); } public DinoWorld(){ @@ -54,17 +56,19 @@ public class DinoWorld implements Environment, Visualizable { dino.jump(); } - dino.tick(); - currentObstacle.tick(); - if(currentObstacle.getX() < -Config.OBSTACLE_SIZE){ - spawnNewObstacle(); + for(int i= 0; i < 5; ++i){ + dino.tick(); + currentObstacle.tick(); + if(currentObstacle.getX() < -Config.OBSTACLE_SIZE){ + spawnNewObstacle(); + } + comp.repaint(); + if(ranIntoObstacle()){ + done = true; + break; + } } - - if(ranIntoObstacle()){ - done = true; - } - - return new StepResultEnvironment(new DinoState(getDistanceToObstacle()), reward, done, ""); + return new StepResultEnvironment(new DinoStateWithSpeed(getDistanceToObstacle(), getCurrentObstacle().getDx()), reward, done, ""); } @@ -101,6 +105,6 @@ public class DinoWorld implements Environment, Visualizable { @Override public JComponent visualize() { - return new DinoWorldComponent(this); + return comp; } }