visualisation.py 5.1KB

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