Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Over view on Clips By: Mohsen Faghihi. Clips view."— Presentation transcript:

1 Over view on Clips By: Mohsen Faghihi

2 Clips view

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

4  assert  modify  retract > ) (assert (phase start)) Managing facts (A)(phase)(phase start) (phase end) ) (assert

5 (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)

6 reset and clear  Clear  Reset (reset) (clear)

7 Define facts (deffacts.. ) (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)) )

8 deftemplate (deftemplate (slot-1). (slot-n) ) (deftemplate take-sticks (slot how-many) (slot for-remainder) ) Sample: (take-sticks (how-many 1) (for-remainder 1) )

9 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:

10 Math operators  (+  (-  (*  (/ (+ 1 2 6 98 ?size) (+ (* 6 7) 3) Sample:

11 Logical operators  (and  (or  (not &|~&|~ (or (not (integerp ?choice)) ( ?choice 3) (> ?choice ?size)) (player-select ?player&~c&~h) Sample:

12 Test and bind  Test  Bind (test ) (bind ) (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:

13 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:

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

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

16 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

17 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

18 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) )

19 Example:  Facts   (block A)  (block B)  (block C)  (block D)  (block E)  (block F)

20 Example:  Facts   (goal (move C)(on-top-of E)) (deftemplate goal (slot move) (slot on-top-of) )

21 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

22 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

23 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

24 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

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


Download ppt "Over view on Clips By: Mohsen Faghihi. Clips view."

Similar presentations


Ads by Google