utils.py 958B

123456789101112131415161718192021222324252627
  1. # coding: utf-8
  2. from sandbox.life_game.simulation import Empty
  3. from sandbox.life_game.simulation import Cell
  4. from synergine2.simulation import Simulation
  5. from synergine2.xyz import XYZSubjects
  6. from synergine2.xyz_utils import get_positions_from_str_representation
  7. def get_subjects_from_str_representation(
  8. str_representations: str,
  9. simulation: Simulation,
  10. ) -> [Cell, Empty]:
  11. subjects = XYZSubjects(simulation=simulation)
  12. items_positions = get_positions_from_str_representation(str_representations)
  13. for item, positions in items_positions.items():
  14. for position in positions:
  15. if item == '0':
  16. subjects.append(Empty(
  17. simulation=simulation,
  18. position=position,
  19. ))
  20. if item == '1':
  21. subjects.append(Cell(
  22. simulation=simulation,
  23. position=position,
  24. ))
  25. return subjects