visualisation.py 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. from synergine_xyz.display.object.pygame.PygameImage import PygameImage
  2. from synergine_xyz.display.object.pygame.DirectionnedImage import DirectionnedImage
  3. from intelligine.synergy.object.Bug import Bug
  4. from intelligine.synergy.object.Food import Food
  5. from intelligine.synergy.object.Hole import Hole
  6. from intelligine.synergy.object.ant.Ant import Ant
  7. from intelligine.sandbox.colored.BlueAnt import BlueAnt
  8. from intelligine.sandbox.colored.RedAnt import RedAnt
  9. from intelligine.sandbox.colored.GreenAnt import GreenAnt
  10. from intelligine.synergy.object.Rock import Rock
  11. from intelligine.synergy.object.ant.Egg import Egg
  12. from os import getcwd
  13. from synergine_xyz.cst import PREVIOUS_DIRECTION
  14. SURFACE_PHEROMONE_HOME = 'pheromone_home'
  15. SURFACE_PHEROMONE_EXPLORATION = 'pheromone_exploration'
  16. # TODO: Analyser les procedes ici pour proposer des outils dans le framework
  17. ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/ant.png')
  18. food = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/food.png')
  19. hole = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/hole.png')
  20. dead_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_ant.png')
  21. red_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/red_ant.png')
  22. green_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/green_ant.png')
  23. blue_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/blue_ant.png')
  24. dead_red_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_red_ant.png')
  25. dead_green_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_green_ant.png')
  26. dead_blue_ant = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/dead_blue_ant.png')
  27. bug = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/ant.png')
  28. rock = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/rock.png')
  29. egg = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg.png')
  30. eggc2 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c2.png')
  31. eggc3 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c3.png')
  32. eggc4 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c4.png')
  33. eggc5 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c5.png')
  34. eggc7 = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/egg_c7.png')
  35. phee = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/phee.png')
  36. pheh = PygameImage.from_filepath(getcwd()+'/intelligine/display/pygame/image/pheh.png')
  37. directions_ant = DirectionnedImage(ant)
  38. directions_red_ant = DirectionnedImage(red_ant)
  39. directions_blue_ant = DirectionnedImage(blue_ant)
  40. directions_green_ant = DirectionnedImage(green_ant)
  41. def bug_direction(bug, context):
  42. if bug.get_life_points() <= 0:
  43. return dead_ant
  44. try:
  45. previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  46. except KeyError:
  47. previous_direction = 14
  48. return directions_ant.get_for_direction(previous_direction)
  49. def red_ant_direction(bug, context):
  50. if bug.get_life_points() <= 0:
  51. return dead_red_ant
  52. try:
  53. previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  54. except KeyError:
  55. previous_direction = 14
  56. return directions_red_ant.get_for_direction(previous_direction)
  57. def blue_ant_direction(bug, context):
  58. if bug.get_life_points() <= 0:
  59. return dead_blue_ant
  60. try:
  61. previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  62. except KeyError:
  63. previous_direction = 14
  64. return directions_blue_ant.get_for_direction(previous_direction)
  65. def green_ant_direction(bug, context):
  66. if bug.get_life_points() <= 0:
  67. return dead_green_ant
  68. try:
  69. previous_direction = context.metas.value.get(PREVIOUS_DIRECTION, bug.get_id())
  70. except KeyError:
  71. previous_direction = 14
  72. return directions_green_ant.get_for_direction(previous_direction)
  73. def for_position(position, objects, context):
  74. # TODO: DEV TMP: refact, etc
  75. eggs = []
  76. for obj in objects:
  77. if isinstance(obj, Egg):
  78. eggs.append(obj)
  79. if len(eggs) == 2:
  80. return (eggc2, eggs)
  81. if len(eggs) == 3:
  82. return (eggc3, eggs)
  83. if len(eggs) == 4:
  84. return (eggc4, eggs)
  85. if len(eggs) > 4:
  86. return (eggc7, eggs)
  87. return (None, [])
  88. visualisation = {
  89. 'window': {},
  90. 'callbacks': {
  91. 'position': for_position
  92. },
  93. 'surfaces': {
  94. SURFACE_PHEROMONE_EXPLORATION: {
  95. 'default': phee,
  96. 'callbacks': []
  97. },
  98. SURFACE_PHEROMONE_HOME: {
  99. 'default': pheh,
  100. 'callbacks': []
  101. },
  102. },
  103. 'objects': {
  104. RedAnt: {
  105. 'default': red_ant,
  106. 'callbacks': [red_ant_direction]
  107. },
  108. BlueAnt: {
  109. 'default': blue_ant,
  110. 'callbacks': [blue_ant_direction]
  111. },
  112. GreenAnt: {
  113. 'default': green_ant,
  114. 'callbacks': [green_ant_direction]
  115. },
  116. Ant: {
  117. 'default': ant,
  118. 'callbacks': [bug_direction]
  119. },
  120. Bug: {
  121. 'default': bug,
  122. 'callbacks': [bug_direction]
  123. },
  124. Egg: {
  125. 'default': egg
  126. },
  127. Rock: {
  128. 'default': rock
  129. },
  130. Food: {
  131. 'default': food
  132. },
  133. Hole: {
  134. 'default': hole
  135. }
  136. }
  137. }