add basic core structure and first parts of antGame implementation

This commit is contained in:
2019-12-07 22:05:11 +01:00
parent 66ee33b77f
commit 87f435c65a
19 changed files with 347 additions and 0 deletions
@@ -0,0 +1,10 @@
package evironment.antGame;
public enum AntAction {
MOVE_UP,
MOVE_RIGHT,
MOVE_DOWN,
MOVE_LEFT,
PICK_UP,
DROP_DOWN,
}
@@ -0,0 +1,6 @@
package evironment.antGame;
import core.Observation;
public class AntObservation implements Observation {
}
@@ -0,0 +1,7 @@
package evironment.antGame;
import core.State;
// somewhat the "brain" of the agent, current known setting of the environment
public class AntState implements State {
}
@@ -0,0 +1,28 @@
package evironment.antGame;
import core.DiscreteAction;
import core.Observation;
import core.RNG;
import core.StepResult;
public class AntWorld {
private Grid grid;
public AntWorld(int width, int height, double foodDensity){
grid = new Grid(width, height, foodDensity);
}
public AntWorld(){
this(30, 30, 0.1);
}
public StepResult step(DiscreteAction<AntAction> action){
Observation observation = new AntObservation();
return new StepResult(observation, 0.0, false, "");
}
public void reset(){
RNG.reseed();
grid.initCells();
}
}
@@ -0,0 +1,23 @@
package evironment.antGame;
public class Cell {
private CellType type;
private int food;
public Cell(CellType cellType, int foodAmount){
type = cellType;
food = foodAmount;
}
public Cell(CellType cellType){
this(cellType, 0);
}
public void setFoodCount(int amount){
food = amount;
}
public int getFoodCount(){
return food;
}
}
@@ -0,0 +1,8 @@
package evironment.antGame;
public enum CellType {
START,
FREE,
OBSTACLE,
FOOD,
}
@@ -0,0 +1,51 @@
package evironment.antGame;
import core.RNG;
import java.awt.*;
public class Grid {
private int width;
private int height;
private double foodDensity;
private Point start;
private Cell[][] grid;
public Grid(int width, int height, double foodDensity){
this.width = width;
this.height = height;
this.foodDensity = foodDensity;
grid = new Cell[width][height];
}
public void initCells(){
for(int x = 0; x < width; ++x){
for(int y = 0; y < height; ++y){
if( RNG.getRandom().nextDouble() < foodDensity){
grid[x][y] = new Cell(CellType.FOOD, 1);
}else{
grid[x][y] = new Cell(CellType.FREE);
}
}
}
start = new Point(RNG.getRandom().nextInt(width), RNG.getRandom().nextInt(height));
grid[start.x][start.y] = new Cell(CellType.START);
}
public Point getStartPoint(){
return start;
}
public Cell[][] getGrid(){
return grid;
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
}