cell_generator.py 459 B

1234567891011121314151617181920212223
  1. import pygame
  2. from settings import *
  3. def cell_checker(field, x, y):
  4. neighbors = 0
  5. for i in range(y - 1, y + 2):
  6. for i2 in range(x - 1, x + 2):
  7. if field[i][i2]:
  8. neighbors += 1
  9. if field[y][x]:
  10. neighbors -= 1
  11. if neighbors == 2 or neighbors == 3:
  12. return 1
  13. else:
  14. return 0
  15. else:
  16. if neighbors == 3:
  17. return 1
  18. else:
  19. return 0