expert system - CLIPS defrule checking if multiple sides of a box are taken -


i working on program tell me moves make in dots-and-boxes game. trying implement defrule check see if box has 2 of possible 4 sides taken. if case don't want take 1 of remaining 2 lines, give opponent free point.

(defrule player_move_no_box_1_1 (next_turn p) (turn_num ?t_num) (test(> ?t_num 3)) (line ?l1&~1) (not(line 1)) => (if    (not(or(and(any-factp ((?l line)) (member$ (+ ?l1 3) ?l:implied))(any-factp ((?l line)) (member$ (+ ?l1 4) ?l:implied)))        (and(any-factp ((?l line)) (member$ (+ ?l1 3) ?l:implied))(any-factp ((?l line)) (member$ (+ ?l1 7) ?l:implied)))        (and(any-factp ((?l line)) (member$ (+ ?l1 4) ?l:implied))(any-factp ((?l line)) (member$ (+ ?l1 7) ?l:implied)))))    (printout t "take line #1" crlf)    (assert(line 1))    (assert(next_turn c)))) 

i've been trying lot of different things, last code tried use, no success. piece of code i'm looking @ line 1 (clockwise starting top of box boxes numbered: x, x+4, x+7, x+3). there simpler way of making check, or way work , i've messed code somewhere?

i suggest explicitly representing each possible line fact , denote in fact whether line has been taken. pattern matching in conditions of rules rather actions.

clips>   (deftemplate line    (slot id)    (slot taken (default no)))      clips>        (defrule player_move_top_line    ?take <- (line (id ?l1) (taken no))    (line (id =(+ ?l1 3)) (taken ?t3))    (line (id =(+ ?l1 4)) (taken ?t4))    (line (id =(+ ?l1 7)) (taken ?t7))    (test (not (or (and (eq ?t3 yes) (eq ?t4 yes) (eq ?t7 no))                   (and (eq ?t3 yes) (eq ?t4 no) (eq ?t7 yes))                   (and (eq ?t3 no) (eq ?t4 yes) (eq ?t7 yes)))))    =>    (printout t "take line #" ?l1 crlf)    (modify ?take (taken yes))) clips> 

i've stripped out turn information original rule make easier test it.

clips> (assert (line (id 0)) (line (id 3)) (line (id 4)) (line (id 7))) <fact-4> clips> (agenda) 0      player_move_top_line: f-1,f-2,f-3,f-4 total of 1 activation. clips> (reset) clips> (assert (line (id 0)) (line (id 3)) (line (id 4)) (line (id 7) (taken yes))) <fact-4> clips> (agenda) 0      player_move_top_line: f-1,f-2,f-3,f-4 total of 1 activation. clips> (reset) clips> (assert (line (id 0)) (line (id 3)) (line (id 4) (taken yes)) (line (id 7))) <fact-4> clips> (agenda) 0      player_move_top_line: f-1,f-2,f-3,f-4 total of 1 activation. clips> (reset) clips> (assert (line (id 0)) (line (id 3) (taken yes)) (line (id 4)) (line (id 7))) <fact-4> clips> (agenda) 0      player_move_top_line: f-1,f-2,f-3,f-4 total of 1 activation. clips> (reset) clips> (assert (line (id 0)) (line (id 3) (taken yes)) (line (id 4) (taken yes)) (line (id 7))) <fact-4> clips> (agenda) clips> (reset) clips> (assert (line (id 0)) (line (id 3) (taken yes)) (line (id 4)) (line (id 7) (taken yes))) <fact-4> clips> (agenda) clips> (reset) clips> (assert (line (id 0)) (line (id 3)) (line (id 4) (taken yes)) (line (id 7) (taken yes))) <fact-4> clips> (agenda) clips> (reset) clips> (assert (line (id 0)) (line (id 3) (taken yes)) (line (id 4) (taken yes)) (line (id 7) (taken yes))) <fact-4> clips> (agenda) 0      player_move_top_line: f-1,f-2,f-3,f-4 total of 1 activation. clips>  

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -