Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 7th, 2012  |  syntax: Lisp  |  size: 1.14 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. (deftemplate unit "combat unit for game AI"
  2.   (slot hitpoints (type NUMBER))
  3.   (slot movespeed (type NUMBER))
  4.   (slot name)
  5.   (multislot 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 fire-rockets))
  29.   (attack
  30.     (name fire-rifle)
  31.     (damage 1))
  32.   (attack
  33.     (name fire-20mm)
  34.     (damage 5))
  35.   (attack
  36.     (name fire-rockets)
  37.     (damage 12))
  38. )
  39.  
  40. (defrule resolve-attack
  41.   (resolve ?unit1 ?attack ?unit2) ;unit1 does attack to unit2
  42.   (unit (name ?u1) (hitpoints ?h1) (attack ?attack $?a1) (movespeed ?m1))
  43.   (attack (name ?attack) (damage ?d))
  44.   ?uf1 <- (unit (name ?u1) (hitpoints ?h2) (attack ?attack $?a2) (movespeed ?m1))
  45.   =>
  46.   (retract ?uf1)
  47.   (if (< (- ?h2 ?d) 0) then
  48.     (assert ((unit (name ?u1) (hitpoints (- ?h2 ?d)) (attack ?attack $?a2) (movespeed ?m1)))))
  49. )