25
Over view on Clips By: Mohsen Faghihi

Over view on Clips By: Mohsen Faghihi. Clips view

Embed Size (px)

Citation preview

Page 1: Over view on Clips By: Mohsen Faghihi. Clips view

Over view on Clips

By: Mohsen Faghihi

Page 2: Over view on Clips By: Mohsen Faghihi. Clips view

Clips view

Page 3: Over view on Clips By: Mohsen Faghihi. Clips view

Facts (cat) (animal cat) (animal dog) (brothers ali mohammad) (polygon (name rectangle) (edge 4))

Page 4: Over view on Clips By: Mohsen Faghihi. Clips view

assert modify retract << fact(s) >>

)

(assert (phase start))

Managing facts

(A)(phase)(phase start) (phase start)

(phase end)

)

(assert

Page 5: Over view on Clips By: Mohsen Faghihi. Clips view

( phase choose-player)>=

( printout t "Who moves first (Compute: c Human: h))" ?( assert (player-select (read)))

)

(defrule Main::player-select

Define rules(defrule rule_name "optional_comment"

(patern_1)..(patern_N)=>(action_1)..(atcion_N)

)

(defrule player-select (phase choose-player) => (printout t "Who moves first (Compute: c Human: h)? ") (assert (player-select (read)) ))

Sample:

(salience N)

Page 6: Over view on Clips By: Mohsen Faghihi. Clips view

reset and clear Clear Reset

(reset)

(clear)

Page 7: Over view on Clips By: Mohsen Faghihi. Clips view

Define facts(deffacts <name>

<fact-1> . . <fact-n>

)

(deffacts initial-phase (phase choose-pile-size))

Sample:

(deffacts take-sticks-information (take-sticks (how-many 1) (for-remainder 1)) (take-sticks (how-many 1) (for-remainder 2)) (take-sticks (how-many 2) (for-remainder 3)) (take-sticks (how-many 3) (for-remainder 0)))

Page 8: Over view on Clips By: Mohsen Faghihi. Clips view

deftemplate(deftemplate <name>

(slot-1) . . (slot-n)

)

(deftemplate take-sticks (slot how-many) (slot for-remainder))

Sample:

(take-sticks (how-many 1) (for-remainder 1) )

Page 9: Over view on Clips By: Mohsen Faghihi. Clips view

Variable ?size ?choice ?pile ?whose-turn

(defrule MAIN::human-lost ?player-turn <- (player-move h) ?pile <- (pile-size ?size) (test (<= ?size 1)) => (retract ?player-turn ?pile) (printout t "You lost !" crlf))

Sample:

Page 10: Over view on Clips By: Mohsen Faghihi. Clips view

Math operators (+ (- (* (/

(+ 1 2 6 98 ?size)

(+ (* 6 7) 3)

Sample:

Page 11: Over view on Clips By: Mohsen Faghihi. Clips view

Logical operators (and (or (not

& | ~

(or (not (integerp ?choice)) (< ?choice 1) (> ?choice 3) (> ?choice ?size))

(player-select ?player&~c&~h)

Sample:

Page 12: Over view on Clips By: Mohsen Faghihi. Clips view

Test and bind Test Bind

(test <boolean-st>)(bind <variable> <value>)

(defrule human-lost ?player-turn <- (player-move h) ?pile <- (pile-size ?size) (test (<= ?size 1)) => (retract ?player-turn ?pile) (printout t "You lost !" crlf))

Sample:

(defrule addition (numbers ?x ?y) => (assert (answer (+ ?x ?y))) (bind ?answer (+ ?x ?y)) (printout t "answer is " ?answer crlf))

Sample:

Page 13: Over view on Clips By: Mohsen Faghihi. Clips view

Run time fact managing assert modify retract(modify

fact-place fact)

(retract fact-place1 . . fact-placeN)

(defrule rain (rain true) ?x <- (floor dry) => (modify ?x (floor wet)))

Sample:

(defrule avg ?student <- (student (std-id ?std)

(average ?avg) ) (lesson (mark ?mark) (std-id ?std) ) => (modify ?student

(average (+ ?avg ?mark)) ))

Sample:

(defrule r-1 ?x <-(student (mark 2) ) => (modify ?x (student (mark 1) (std-id 0)) ))

Sample:

(defrule MAIN::good-player-choice ?phase <- (phase choose-player) ?choice <- (player-select ?player&c|h) => (retract ?phase ?choice) (assert (player-move ?player)))

Sample:

Page 14: Over view on Clips By: Mohsen Faghihi. Clips view

I/O statements (read) (printout t “text”)

Page 15: Over view on Clips By: Mohsen Faghihi. Clips view

Boolean operators (< (> (<= (>= (eq (neq

Page 16: Over view on Clips By: Mohsen Faghihi. Clips view

Example Rule Move-Directly

IF The goal is to move block ?upper on top of block ?lower AND Block ?upper is the top block in its stack AND Block ?lower is the top block in its stack THEN Move block ?upper on top of block ?lower

Rule Clear-Upper-Block IF The goal is to move block ?x AND Block ?x is not the top block in its stack AND Block ?above is on top of block ?x THEN The goal is to move block ?above to the floor

Page 17: Over view on Clips By: Mohsen Faghihi. Clips view

Example Rule Clear-Lower-Block

IF The goal is to move another block on top of block ?x AND Block ?x is not the top block in its stack AND Block ?above is on top of block ?x THEN The goal is to move block ?above to the floor

Rule Move-To-Floor IF The goal is to move block ?upper on top of the floor AND Block ?upper is the top block in its stack THEN Move block ?upper on top of the floor

Page 18: Over view on Clips By: Mohsen Faghihi. Clips view

Example: Facts (on-top-of (upper nothing)(lower A)) (on-top-of (upper A)(lower B)) (on-top-of (upper B)(lower C)) (on-top-of (upper C)(lower floor))

(on-top-of (upper nothing)(lower D)) (on-top-of (upper D)(lower E)) (on-top-of (upper E)(lower F)) (on-top-of (upper F)(lower floor))

(deftemplate on-top-of(slot upper)(slot lower)

)

Page 19: Over view on Clips By: Mohsen Faghihi. Clips view

Example: Facts (block A) (block B) (block C) (block D) (block E) (block F)

Page 20: Over view on Clips By: Mohsen Faghihi. Clips view

Example: Facts (goal (move C)(on-top-of E))

(deftemplate goal(slot move)(slot on-top-of)

)

Page 21: Over view on Clips By: Mohsen Faghihi. Clips view

Example: Rules (defrule Move-Directly

?goal <- (goal (move ?block1)(on-top-of ?block2))(block ?block1)(block ?block2)(on-top-of (upper nothing)(lower ?block1))

?stack-1 <- (on-top-of (upper ?block1)(lower ?block3))?stack-2 <- (on-top-of (upper nothing)(lower ?block2))=>(retract ?goal ?stack-1 ?stack-2)(assert

(on-top-of (upper ?block1)(lower ?block2))(on-top-of (upper nothing)(lower ?block3))

)(printout t ?block1 " moved on top of " ?block2 "." crlf)

)

Rule Move-Directly IF The goal is to move block ?upper on yop of block ?lower AND Block ?upper is the top block in its stack AND Block ?lower is the top block in its stack THEN Move block ?upper on top of block ?lower

Page 22: Over view on Clips By: Mohsen Faghihi. Clips view

Example: Rules (defrule Clear-Upper-Block

(goal (move ?block1))(block ?block1)(on-top-of (upper ?block2)(lower ?block1))(block ?block2)=>(assert

(goal (move ?block2)(on-top-of floor)))

)

Rule Clear-Upper-Block IF The goal is to move block ?x AND Block ?x is not the top block in its stack AND Block ?above is on top of block ?x THEN The goal is to move block ?above to the floor

Page 23: Over view on Clips By: Mohsen Faghihi. Clips view

Example: Rules (defrule Clear-Lower-Block

(goal (on-top-of ?block1))(block ?block1)(on-top-of (upper ?block2)(lower ?block1))=>(assert

(goal (move ?block2)(on-top-of floor)))

)

Rule Clear-Lower-Block IF The goal is to move another block on top of block ?x AND Block ?x is not the top block in its stack AND Block ?above is on top of block ?x THEN The goal is to move block ?above to the floor

Page 24: Over view on Clips By: Mohsen Faghihi. Clips view

Example: Rules (defrule move-to-floor

?goal <- (goal (move ?block1)(on-top-of floor))(block ?block1)(on-top-of (upper nothing)(lower ?block1))?stack <- (on-top-of (upper ?block1)(lower ?block2))=>(retract ?goal ?stack)(assert

(on-top-of (upper ?block1)(lower floor))(on-top-of (upper nothing)(lower ?block2))

)(printout t ?block1 " moved to floor." crlf)

)

Rule Move-To-Floor IF The goal is to move block ?upper on top of the floor AND Block ?upper is the top block in its stack THEN Move block ?upper on top of the floor

Page 25: Over view on Clips By: Mohsen Faghihi. Clips view

Thanks

با تشکر فراوان ازخودم که خیلی زحمت کشیدم

درهمی استاد