visualisation.py 5.2KB

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