visualisation.py 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from xyworld.display.object.pygame.PygameImage import PygameImage
  2. from xyworld.display.object.pygame.DirectionnedImage import DirectionnedImage
  3. from intelligine.synergy.object.Bug import Bug
  4. from intelligine.synergy.object.ant.Ant import Ant
  5. from intelligine.sandbox.redblue.BlueAnt import BlueAnt
  6. from intelligine.sandbox.redblue.RedAnt import RedAnt
  7. from intelligine.synergy.object.Rock import Rock
  8. from os import getcwd
  9. from synergine.metas import metas
  10. from intelligine.cst import PREVIOUS_DIRECTION
  11. ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/ant.png')
  12. red_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/red_ant.png')
  13. blue_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/blue_ant.png')
  14. bug = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/ant.png')
  15. rock = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/rock.png')
  16. directions_ant = DirectionnedImage(ant)
  17. directions_red_ant = DirectionnedImage(red_ant)
  18. directions_blue_ant = DirectionnedImage(blue_ant)
  19. def bug_direction(bug):
  20. try:
  21. previous_direction = metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  22. except KeyError:
  23. previous_direction = 14
  24. return directions_ant.get_for_direction(previous_direction)
  25. def red_ant_direction(bug):
  26. try:
  27. previous_direction = metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  28. except KeyError:
  29. previous_direction = 14
  30. return directions_red_ant.get_for_direction(previous_direction)
  31. def blue_ant_direction(bug):
  32. try:
  33. previous_direction = metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  34. except KeyError:
  35. previous_direction = 14
  36. return directions_blue_ant.get_for_direction(previous_direction)
  37. visualisation = {
  38. 'window': {},
  39. 'objects': {
  40. RedAnt: {
  41. 'default': red_ant,
  42. 'callbacks': [red_ant_direction]
  43. },
  44. BlueAnt: {
  45. 'default': blue_ant,
  46. 'callbacks': [blue_ant_direction]
  47. },
  48. Ant: {
  49. 'default': ant,
  50. 'callbacks': [bug_direction]
  51. },
  52. Bug: {
  53. 'default': bug,
  54. 'callbacks': [bug_direction]
  55. },
  56. Rock: {
  57. 'default': rock
  58. }
  59. }
  60. }