visualisation.py 5.8KB

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