Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. public int singleCellNeighbors(Cell cell) {
  2. int x = cell.getX();
  3. int y = cell.getY();
  4. int neighbors = 0;
  5.  
  6. for (int i = x - 1; i < x + 2; i++) {
  7. if(i < 0 || i >= MAX_SIZE_X) {
  8. continue;
  9. }
  10. for (int j = y - 1; j < y + 2; j++) {
  11. if(j < 0 || j >= MAX_SIZE_Y) {
  12. continue;
  13. }
  14. if (cells[i][j] != null && !cells[i][j].equals(cell)) {
  15. if(cells[i][j].getState() == true) {
  16. neighbors++;
  17. }
  18.  
  19. }
  20. }
  21. }
  22.  
  23. return neighbors;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement