Remove unused variable dispersal

This commit is contained in:
Unknown 2018-10-23 14:47:23 +02:00
parent 474adb740c
commit e840a3e580
2 changed files with 4 additions and 10 deletions

View file

@ -14,7 +14,7 @@ class SimulationService {
SimulationService(this._engine, [Simulation sim]) SimulationService(this._engine, [Simulation sim])
: this._sim = sim ?? Simulation(DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE) { : this._sim = sim ?? Simulation(DEFAULT_GRID_SIZE, DEFAULT_GRID_SIZE) {
_engine.simulation = _sim; _engine.simulation = _sim;
_sim.addRandomPattern(amount: 15, dispersal: 5); _sim.addRandomPattern(amount: 15);
} }
void reset() { void reset() {

View file

@ -10,7 +10,6 @@ class Simulation {
Grid<bool> _snapshot; Grid<bool> _snapshot;
final int _RANDOM_PATTERN_AMOUNT = 20; final int _RANDOM_PATTERN_AMOUNT = 20;
final int _RANDOM_PATTERN_DISPERSAL = 10;
final double _RANDOM_PATTERN_SPREAD_FROM_CENTER = 1 / 3; final double _RANDOM_PATTERN_SPREAD_FROM_CENTER = 1 / 3;
RuleSet rules = GameOfLife(); RuleSet rules = GameOfLife();
@ -20,8 +19,6 @@ class Simulation {
bool _renderEdges = true; bool _renderEdges = true;
bool get renderEdges => _renderEdges; bool get renderEdges => _renderEdges;
int _dispersal;
math.Point get gridSize => math.Point<int>(map.width, map.height); math.Point get gridSize => math.Point<int>(map.width, map.height);
void set gridSize(math.Point<int> value) { void set gridSize(math.Point<int> value) {
if (value.x <= 0 || value.y <= 0) if (value.x <= 0 || value.y <= 0)
@ -41,18 +38,16 @@ class Simulation {
return map; return map;
} }
void addRandomPattern( void addRandomPattern({int seed, int amount, num spreadFromCenter}) {
{int seed, int amount, int dispersal, num spreadFromCenter}) {
math.Random rng = _getRNG(seed ?? DateTime.now().millisecondsSinceEpoch); math.Random rng = _getRNG(seed ?? DateTime.now().millisecondsSinceEpoch);
amount ??= rng.nextInt(_RANDOM_PATTERN_AMOUNT); amount ??= rng.nextInt(_RANDOM_PATTERN_AMOUNT);
dispersal ??= _RANDOM_PATTERN_DISPERSAL;
spreadFromCenter ??= _RANDOM_PATTERN_SPREAD_FROM_CENTER; spreadFromCenter ??= _RANDOM_PATTERN_SPREAD_FROM_CENTER;
int sanityCheck = 0; int sanityCheck = 0;
Map<int, bool> changeSet = {}; Map<int, bool> changeSet = {};
for (var i = 0; i < (amount); i++) { for (var i = 0; i < (amount); i++) {
sanityCheck++; sanityCheck++;
math.Point cell = _getRandomPoint(rng, gridSize, spreadFromCenter); math.Point cell = _getRandomPoint(rng, spreadFromCenter);
getCellState(cell.x, cell.y) getCellState(cell.x, cell.y)
? i-- ? i--
: changeSet[map.toIndex(cell.x, cell.y)] = true; : changeSet[map.toIndex(cell.x, cell.y)] = true;
@ -66,8 +61,7 @@ class Simulation {
return rng; return rng;
} }
math.Point<int> _getRandomPoint( math.Point<int> _getRandomPoint(math.Random rng, num spreadFromCenter) {
math.Random rng, math.Point size, num spreadFromCenter) {
math.Point absoluteSpread = math.Point absoluteSpread =
math.Point(map.width * spreadFromCenter, map.height * spreadFromCenter); math.Point(map.width * spreadFromCenter, map.height * spreadFromCenter);
math.Point center = math.Point(map.width / 2, map.height / 2); math.Point center = math.Point(map.width / 2, map.height / 2);