# HERB Guards Demo
# Shows how IF conditions filter rule bindings

# === ENTITIES ===
FACT alice is_a player
FACT alice hp 100
FACT alice location forest

FACT bob is_a player
FACT bob hp 0
FACT bob location forest

FACT carol is_a player
FACT carol hp 50
FACT carol location town

FACT goblin is_a monster
FACT goblin hp 30
FACT goblin location forest

# === RULES WITH GUARDS ===

# Rule 1: Visibility - same location, different entities
# The guard (not= ?a ?b) prevents self-visibility
RULE visibility
  WHEN ?a location ?loc
  AND ?b location ?loc
  IF (not= ?a ?b)
  THEN ?a sees ?b

# Rule 2: Combat - only living players can engage monsters
# The guard (> ?hp 0) prevents dead players from fighting
RULE combat_engagement
  WHEN ?p is_a player
  AND ?m is_a monster
  AND ?p location ?loc
  AND ?m location ?loc
  AND ?p hp ?hp
  IF (> ?hp 0)
  THEN ?p in_combat_with ?m

# Rule 3: Alive check - entities with positive HP are alive
RULE alive_status
  WHEN ?e hp ?hp
  IF (> ?hp 0)
  THEN ?e status alive

# Rule 4: Dead check - entities with zero or negative HP are dead
RULE dead_status
  WHEN ?e hp ?hp
  IF (<= ?hp 0)
  THEN ?e status dead
