private Cell GetNeighborAt(Cell cell, int index) { index = index % 8; int targetx = cell.x; int targety = cell.y; switch (index) { case 0: targetx--; break; case 1: targetx--; targety--; break; case 2: targety--; break; case 3: targety--; targetx++; break; case 4: targetx++; break; case 5: targetx++; targety++; break; case 6: targety++; break; case 7: targety++; targetx--; break; } if ((targetx > (this.width - 1)) || (targety > (this.height - 1)) || (0 > targetx) || (0 > targety)) { return null; } var neighbor = this.cells[targetx, targety]; return neighbor; }
private bool InfectCell(Cell cell) { double random = RandomNumber.GetRandomDouble(); if ((random < this.baseRate) && (0 < cell.state)) { cell.state--; return true; } return false; }