You are on page 1of 4

1.

Set of exercises taken from “Clips the Game”


(https://md5crypt.github.io/clipsgame/)

The following exercises follow the CLIPS syntax to define rules and facts. They can be solved
either on paper or (preferably) using CLIPS. The solution is defined by a fact or set of facts that
have to be added to the production system, taking into account that there are some prohibited
facts.

Level 1 “The Hungry Tiger”


The tiger is hungry! You have to feed it!

Goal
Add (is tiger fed) to the fact table using only one assertion.

Restricted facts

• (is tiger fed)

Definitions

(deffacts initial-facts
(is tiger animal)
(is grass plant)
(eats tiger animal)
(eats plant light)
)

(defrule things-can-be-fed
(is ?what eatable)
(is ?what ?food)
(eats ?target ?food)
=>
(assert (is ?target fed))
)

1
Level 2 “Harry’s bow”
Archer Harry needs to win a battle. Give him a hand.

Goal
Add (wins harry) to the fact table using only two assertions.

Restricted facts

• (wins ?)
• (distance ?)
• (range bow small)

Definitions

(defrule weapon-wins
(weapon ?item)
(range ?item ?type)
(distance ?type)
=>
(assert (wins ?item))
)

(defrule battle
(warrior ?person)
(has ?person ?weapon)
(wins ?weapon)
=>
(assert (wins ?person))
)

(deffacts inital-facts
(warrior harry)
(has harry bow)
(weapon bow)
(range bow large)
(distance small)
)

2
Level 3 “The cycle of life”

Help Bob survive in the jungle of a modern urban city.

Goal
Add (person bob) to the fact table and make it stay there.

Strategy
Assume that rules are selected according to the following strategy: refraction principle +
higher priority to rules defined before

Definitions
(defrule get-drunk
?status <- (got-cash ?who)
(person ?who)
=>
(retract ?status)
(assert (drunk ?who))
)

(defrule die-in-accident
?life <- (person ?who)
(drunk ?who)
(stressed ?who)
=>
(retract ?life)
)

(defrule sleep-it-out
?status <- (drunk ?who)
?action <- (sleep ?who)
(person ?who)
=>
(retract ?action ?status)
)

(defrule get-cash
?status <- (work ?who)
(not (drunk ?who))
(person ?who)
=>
(retract ?status)
(assert
(got-cash ?who)
(stressed ?who)
)
)

(defrule cycle-of-life
(person ?who)
(not (work ?who))
=>
(assert
(sleep ?who)
(work ?who)
)
)

3
Level 4 “The perfect wife”

Help caveman Bob find happiness with his love, Alice. To do so he will need to outwit his rival
Steve.

Goal
Add (married alice to bob) to the fact table using any number of assertions.

Strategy
Assume that rules are selected according to the following strategy: refraction principle + rules
with more recent facts have more priority

Restricted facts

• (married alice to bob)


• (has bob food)

Definitions

(defrule hunt-food
(village has weapon)
(male ?person)
=>
(assert (has ?person food))
)

(defrule find-mate
(male ?man)
(has ?man food)
(female ?woman)
(not (married ?woman to ?))
=>
(assert (married ?woman to ?man))
)

(defrule terrible-mistake
(psychopath ?woman)
(married ?woman to ?man)
?corpse <- (male ?man)
=>
(retract ?corpse)
)

(deffacts initial-facts
(female alice)
(male bob)
(male steve)
)

You might also like