utils.py 910B

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