Guest User

Untitled

a guest
Sep 15th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.06 KB | None | 0 0
  1. (deftemplate unit "combat unit for game AI"
  2.   (slot hitpoints (type NUMBER))
  3.   (slot movespeed (type NUMBER))
  4.   (slot name)
  5.   (slot attack)
  6. )
  7.  
  8. (deftemplate attack "combat weapon for game AI"
  9.   (slot name)
  10.   (slot damage (type NUMBER))
  11. )
  12.  
  13. (deffacts
  14.   (unit
  15.     (name infantry-1)
  16.     (hitpoints 1)
  17.     (movespeed 3)
  18.     (attack fire-rifle))
  19.   (unit
  20.     (name infantry-2)
  21.     (hitpoints 1)
  22.     (movespeed 3)
  23.     (attack fire-rifle))
  24.   (unit
  25.     (name tank-1)
  26.     (hitpoints 10)
  27.     (movespeed 1)
  28.     (attack fire-20mm))
  29.   (attack
  30.     (name fire-rifle)
  31.     (damage 1))
  32.   (attack
  33.     (name fire-20mm)
  34.     (damage 5))
  35. )
  36.  
  37. (defrule resolve-attack
  38.   (resolve ?unit1 ?attack ?unit2) ;unit1 does attack to unit2
  39.   (unit (name ?u1) (hitpoints ?h1) (abilities ?attack) (movespeed ?m1))
  40.   (attack (name ?attack) (damage ?d))
  41.   ?uf1 <- (unit (name ?u1) (hitpoints ?h2) (abilities ?attack) (movespeed ?m1))
  42.   =>
  43.   (retract ?uf1)
  44.   (if (< (- ?h2 ?d) 0) then
  45.     (assert ((unit (name ?u1) (hitpoints (- ?h2 ?d)) (abilities ?attack) (movespeed ?m1)))))
  46. )
Add Comment
Please, Sign In to add comment