Logo Bolo: a re-envisioning of the classic tank game by Stuart Cheshire in NetLogo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
3.3 KiB

  1. ;; lobo: Logo Bolo
  2. ;; (c) Ben Kurtovic, 2011-2012
  3. to ai-do-cycle
  4. if ai-objective = "nothing" [
  5. set ai-objective ai-get-objective
  6. ]
  7. if ai-objective = "base-run" [
  8. ai-do-base-run
  9. ]
  10. if ai-objective = "place-pill" [
  11. ai-do-place-pill
  12. ]
  13. if ai-objective = "refuel" [
  14. ai-do-refuel
  15. ]
  16. if ai-objective = "capture-pill" [
  17. ai-do-capture-pill
  18. ]
  19. if ai-objective = "capture-base" [
  20. ai-do-capture-base
  21. ]
  22. if ai-objective = "attack-player" [
  23. ai-do-attack-player
  24. ]
  25. end
  26. to-report ai-get-objective
  27. if any? bases with [team = -1] [
  28. report "base-run"
  29. ]
  30. if number-of-pills > 0 [
  31. report "place-pill"
  32. ]
  33. if any? pillboxes with [team != 1] and ammunition > 4 and armor > 6 [
  34. report "capture-pill"
  35. ]
  36. if any? bases with [team = 0] and ammunition > (max-ammo / 2) and armor > 2 [
  37. report "capture-base"
  38. ]
  39. if player != nobody and ammunition > (max-ammo / 2) and armor > 2 [
  40. report "attack-player"
  41. ]
  42. if any? bases with [team = 1] and (ammunition < max-ammo or armor < max-armor) [
  43. report "refuel"
  44. ]
  45. if player != nobody [
  46. report "attack-player"
  47. ]
  48. report "nothing"
  49. end
  50. to ai-do-base-run
  51. let mxcor xcor
  52. let mycor ycor
  53. let target min-one-of (bases with [team = -1]) [distancexy mxcor mycor]
  54. let dist ai-approach-target target 0.1
  55. if dist < 0.1 [
  56. set ai-objective "nothing"
  57. ]
  58. end
  59. to ai-do-place-pill
  60. let mxcor xcor
  61. let mycor ycor
  62. let target min-one-of bases [distancexy mxcor mycor]
  63. let dist ai-approach-target target 1
  64. if dist < 2 [
  65. place-pill
  66. ]
  67. set ai-objective "nothing"
  68. end
  69. to ai-do-refuel
  70. let mxcor xcor
  71. let mycor ycor
  72. let target min-one-of (bases with [team = 1]) [distancexy mxcor mycor]
  73. let dist ai-approach-target target 0.1
  74. if dist < 1 and ammunition > (max-ammo / 2) and armor > (max-armor / 2) [
  75. set ai-objective "nothing"
  76. ]
  77. end
  78. to ai-do-capture-pill
  79. let mxcor xcor
  80. let mycor ycor
  81. let target min-one-of (pillboxes with [team != 1]) [distancexy mxcor mycor]
  82. let dist ai-approach-target target 2
  83. ifelse number-of-pills > 0 or ammunition = 0 [
  84. set ai-objective "nothing"
  85. ] [
  86. if dist < 5 and [armor] of target > 0 [
  87. fire
  88. ]
  89. if [armor] of target = 0 [
  90. set dist ai-approach-target target 0.1
  91. ]
  92. ]
  93. end
  94. to ai-do-capture-base
  95. let mxcor xcor
  96. let mycor ycor
  97. let target min-one-of (bases with [team != 1]) [distancexy mxcor mycor]
  98. let dist ai-approach-target target 2
  99. ifelse target = nobody or ammunition = 0 [
  100. set ai-objective "nothing"
  101. ] [
  102. if dist < 5 and [armor] of target > 0 [
  103. fire
  104. ]
  105. if [armor] of target = 0 [
  106. set dist ai-approach-target target 0.1
  107. ]
  108. ]
  109. end
  110. to ai-do-attack-player
  111. let mxcor xcor
  112. let mycor ycor
  113. ifelse player = nobody [
  114. set ai-objective "nothing"
  115. ] [
  116. let dist ai-approach-target player 1
  117. if ammunition = 0 [
  118. set ai-objective "nothing"
  119. ]
  120. if dist < 5 [
  121. fire
  122. ]
  123. ]
  124. end
  125. to-report ai-approach-target [target min-dist]
  126. if target != nobody [
  127. tank-facexy ([xcor] of target) ([ycor] of target)
  128. set is-accelerating? true
  129. let dist distancexy ([xcor] of target) ([ycor] of target)
  130. if dist < 2 and speed > 0.075 [
  131. decelerate friction * 5
  132. ]
  133. if dist < min-dist [
  134. set is-accelerating? false
  135. set speed speed / 2
  136. ]
  137. report dist
  138. ]
  139. report 0
  140. end