Files
refo/src/main/java/evironment/antGame/Grid.java
T
kono 7db5a2af3b add fix RNG, add extended interface EpsilonPolicy and move rewardHistory to model instead of view
- only setting the seed of RNG once at the beginning and not reseeding it afterwards. Deep copying
the initial AntWorld to use as blueprint for resetting the world instead of reseeding and creating pesudo random again. Reseeding the RNG has influence action selecting to always
choose the same trajectory.
- instance of is used to determine if policy has epsilon or not and the view will adopt to this, only showing epsilon slider if policy has epsilon
2019-12-20 16:51:09 +01:00

80 lines
1.9 KiB
Java

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;
private Cell[][] initialGrid;
public Grid(int width, int height, double foodDensity){
this.width = width;
this.height = height;
this.foodDensity = foodDensity;
grid = new Cell[width][height];
initialGrid = new Cell[width][height];
initRandomWorld();
}
public Grid(int width, int height){
this(width, height, 0);
}
public void resetWorld(){
grid = Util.deepCopyCellGrid(initialGrid);
}
public void initRandomWorld(){
for(int x = 0; x < width; ++x){
for(int y = 0; y < height; ++y){
if( RNG.getRandom().nextDouble() < foodDensity){
initialGrid[x][y] = new Cell(new Point(x,y), CellType.FREE, 1);
}else{
initialGrid[x][y] = new Cell(new Point(x,y), CellType.FREE);
}
}
}
start = new Point(RNG.getRandom().nextInt(width), RNG.getRandom().nextInt(height));
initialGrid[start.x][start.y] = new Cell(new Point(start.x, start.y), CellType.START);
}
public Point getStartPoint(){
return start;
}
public boolean isAllFoodCollected(){
for(int x = 0; x < width; ++x){
for(int y = 0; y < height; ++y){
if(grid[x][y].getFood() > 0){
return false;
}
}
}
return true;
}
public Cell[][] getGrid(){
return grid;
}
public Cell getCell(Point pos){
return grid[pos.x][pos.y];
}
public Cell getCell(int x, int y){
return grid[x][y];
}
public int getWidth(){
return width;
}
public int getHeight(){
return height;
}
}