utils.py 1.0KB

1234567891011121314151617181920212223242526272829
  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. config=simulation.config,
  18. simulation=simulation,
  19. position=position,
  20. ))
  21. if item == '1':
  22. subjects.append(Cell(
  23. config=simulation.config,
  24. simulation=simulation,
  25. position=position,
  26. ))
  27. return subjects