utils.py 942B

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