package uk.ac.leeds.ccg.andyt.projects.genesis.society.environment; import java.util.Random; import uk.ac.leeds.ccg.andyt.grids.core.AbstractGrid2DSquareCell; import uk.ac.leeds.ccg.andyt.grids.core.Grid2DSquareCellDouble; import uk.ac.leeds.ccg.andyt.grids.core.Grid2DSquareCellDoubleFactory; import uk.ac.leeds.ccg.andyt.projects.genesis.society.environment.Location; public class Environment { //public AbstractGrid2DSquareCellFactory _AbstractGrid2DSquareCellFactory; public Grid2DSquareCellDoubleFactory _Grid2DSquareCellDoubleFactory; //public AbstractGrid2DSquareCell _World_AbstractGrid2DSquareCell; public Grid2DSquareCellDouble _World_Grid2DSquareCellDouble; public AbstractGrid2DSquareCell _Resource_Grid2DSquareCellDouble; public boolean _HandleOutOfMemoryError; public Random _Random; public Time _Time; public Environment ( Random _Random, Time _Time){ this._Random = _Random; this._Time = new Time(_Time); } public Environment ( Random _Random, Time _Time, Grid2DSquareCellDoubleFactory _Grid2DSquareCellDoubleFactory, Grid2DSquareCellDouble _World_Grid2DSquareCellDouble, boolean _HandleOutOfMemoryError){ this._Random = _Random; this._Time = new Time(_Time); this._Grid2DSquareCellDoubleFactory = _Grid2DSquareCellDoubleFactory; this._World_Grid2DSquareCellDouble = _World_Grid2DSquareCellDouble; this._HandleOutOfMemoryError = _HandleOutOfMemoryError; //_Init_Resource_Grid2DSquareCellDouble(); } public void _Init_Resource_Grid2DSquareCellDouble(){ _Resource_Grid2DSquareCellDouble = _Grid2DSquareCellDoubleFactory.create(_World_Grid2DSquareCellDouble); long _NRows = _Resource_Grid2DSquareCellDouble.get_NRows(_HandleOutOfMemoryError); long _NCols = _Resource_Grid2DSquareCellDouble.get_NCols(_HandleOutOfMemoryError); long row; long col; double value; for (row =0; row<_NRows; row++){ for (col =0; col<_NCols; col++){ value = _Random.nextDouble(); _Resource_Grid2DSquareCellDouble.setCell(row,col,value,_HandleOutOfMemoryError); } } } public Location getRandomLocation(){ Location result = new Location(); long _NRows = _World_Grid2DSquareCellDouble.get_NRows(_HandleOutOfMemoryError); long _NCols = _World_Grid2DSquareCellDouble.get_NCols(_HandleOutOfMemoryError); long row = _Random.nextInt((int)_NRows); long col = _Random.nextInt((int)_NCols); if (!_World_Grid2DSquareCellDouble.isInGrid(row,col,_HandleOutOfMemoryError)){ System.out.print(this.getClass().getName()+".getRandomLocation() !_World_Grid2DSquareCellDouble.isInGrid(row("+row+"),col("+col+"),_HandleOutOfMemoryError)"); } result._Row = row; result._Col = col; return result; } }