Package application.model.simulation
Class Simulator
java.lang.Object
application.model.simulation.Grid
application.model.simulation.Simulator
- Direct Known Subclasses:
Pattern
public class Simulator extends Grid
Simulations are run using Simulator.
Example Usage:
Example Usage:
Simulator simulator = new Simulator(new HROT("B3/S23")); simulator.fromRLE("bo$obo$o2bo$bobo$2bo!", new Coordinate(0, 0)); simulator.step(); iterateCells(cell -> { System.out.println(cell); });
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description void
clearCells(Coordinate start, Coordinate end)
Clears all cells between the coordinates specifiedjava.util.Set<Coordinate>
getCellsChanged()
Gets the cells that changed in the previous generationint
getGeneration()
Gets the generation of the simulatorRule
getRule()
Gets the rule of the simulatorPattern
identify()
Identify a pattern (still life / oscillator / spaceship) with a max period of 2000Pattern
identify(int maxPeriod)
Identify a pattern (still life / oscillator / spaceship) with the specified max periodPattern
identify(int maxPeriod, java.util.function.Function<Grid,java.lang.Boolean> continueIdentification)
Identify a pattern (still life / oscillator / spaceship) with the specified max periodvoid
setCell(int x, int y, int state)
Sets the cell at position (x, y) to the specified statevoid
setCell(Coordinate coordinate, int state)
Sets the cell at position coordinate to the specified statevoid
setGeneration(int generation)
Set the generation of the simulatorvoid
setRule(Rule rule)
Sets the rule of the simulator.void
step()
Step the simulation forward 1 generationvoid
step(java.util.function.Function<Coordinate,java.lang.Boolean> step)
Step a portion of the simulation forward 1 generationjava.lang.String
toRLE(Coordinate startCoordinate, Coordinate endCoordinate)
Converts the pattern in the given bounds into an RLEMethods inherited from class application.model.simulation.Grid
addBlock, bfs, clearCells, convertCell, deepCopy, equals, fromApgcode, fromRLE, getBackground, getBlock, getBlockCoordinate, getBlockCoordinates, getBlocks, getBounds, getCell, getCell, getCells, getPopulation, hashCode, hashCode, hashCode, hasNext, insertCells, iterateCells, iterateCellsInBlock, iterator, next, reflectCellsX, reflectCellsY, removeBlock, rotateCCW, rotateCW, setBackground, shallowCopy, size, slowEquals, toArray, toRLE, updateBounds
-
Constructor Details
-
Simulator
Initialises the simulator- Parameters:
rule
- The rule to be loaded
-
-
Method Details
-
getRule
Gets the rule of the simulator- Returns:
- Returns the rule of the simulator
-
getGeneration
public int getGeneration()Gets the generation of the simulator- Returns:
- Returns the generation of the simulator
-
getCellsChanged
Gets the cells that changed in the previous generation- Returns:
- Returns the cells that changed in the previous generation
-
setRule
Sets the rule of the simulator.
IMPORTANT: DO NOT CHANGE THE RULE OF THE SIMULATOR WITH ANY OTHER FUNCTION! (Because bugzzz...)- Parameters:
rule
- Rule to set the simulator to
-
setGeneration
public void setGeneration(int generation)Set the generation of the simulator- Parameters:
generation
- Generation to set the simulator to
-
identify
Identify a pattern (still life / oscillator / spaceship) with a max period of 2000- Returns:
- The identified pattern
-
identify
Identify a pattern (still life / oscillator / spaceship) with the specified max period- Parameters:
maxPeriod
- The max period to check for periodicity- Returns:
- The identified pattern
-
identify
public Pattern identify(int maxPeriod, java.util.function.Function<Grid,java.lang.Boolean> continueIdentification)Identify a pattern (still life / oscillator / spaceship) with the specified max period- Parameters:
maxPeriod
- The max period to check for periodicitycontinueIdentification
- Checks if the identification should continue- Returns:
- The identified pattern
-
step
public void step()Step the simulation forward 1 generation -
step
Step a portion of the simulation forward 1 generation- Parameters:
step
- A function that returns whether the cell at that coordinate should be stepped forward.
-
setCell
Sets the cell at position coordinate to the specified state -
setCell
public void setCell(int x, int y, int state)Sets the cell at position (x, y) to the specified state -
clearCells
Clears all cells between the coordinates specified- Overrides:
clearCells
in classGrid
- Parameters:
start
- The starting coordinateend
- The end coordinate
-
toRLE
Converts the pattern in the given bounds into an RLE
-