trere are 10 chips . I need to reposition they to final-state . Something like that:
(deffacts MAIN::initial-position
(status (search-depth 1)
(parent no-parent)
(last-move no-move)
(chips white black white black white black white black empty empty )
))
(defrule SOLUTION::recognize-solution
(declare (auto-focus TRUE))
?node <- (status (parent ?parent)
(last-move ?move)
(chips black black black black white white white white empty empty))
=>
(retract ?node)
(assert (moves (id ?parent) (moves-list ?move))))
the correct step is to reposition 2 not empty chips, that stay together with to empty chips….i tried to do it like that
(defrule MAIN::move-alone
?node<-(status (search-depth ?num) ;curent state of search
(chips $?chip))
;?choise1<-(member empty $?chip)
;?choise2<-(member ?c2&~empty $?chip) (member ?c2&~empty $?chip)
=>
(bind ?notempty1 (nth$ (- 1(nempty $?chip)) ?chip)) ;find color of first not empty chip
(bind ?notempty2 (nth$ (nempty $?chip) ?chip)) ;find color of second not empty chip
(bind ?notempty1pos (- 1(nempty $?chip))) ;find position of not empty chip
(bind ?notempty2pos (nempty $?chip))
but I don`t know how can I write function nempty, that return position of second not empty chip…
help me please…. i will be thank you very much for any ideas for decision of this problem…..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
(bind ?next (find-nth-occurrence (- ?n 1)
?value
(subseq$ ?list (+ ?position 1) (length$ ?list))))
(if ?next
then
(return (+ ?position ?next))
else
(return ?next)))
CLIPS> (find-nth-occurrence 1 empty (create$ white black empty black black white white empty black empty))
3
CLIPS> (find-nth-occurrence 2 empty (create$ white black empty black black white white empty black empty))
8
CLIPS> (find-nth-occurrence 3 empty (create$ white black empty black black white white empty black empty))
10
CLIPS> (find-nth-occurrence 4 white (create$ white black empty black black white white empty black empty))
FALSE
CLIPS>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thank you very much for yuor comment, but I have one another question about this goal… I need find the answer with the help of 3 method of search : depth first search, breadth first search and someone width cost function, hill climbing fir example)….and I find answer with the help of first method… I know advantage of CLIPS , that it perfect for "breadth first search" and the main idea of this searching, but all the same i can not cjmbine it… for example I know how i can do it with the help of prolog….maybe can someone help me "translate" it for CLIPS?
initial_state([white,black,white,black,white,black,white,black,empty,empty]).final_state([black,black,black,black,white,white,white,white,empty,empty]).main(Decision):-initial_state(State),breadth_search([s(State,[])],[],[],Decision),writeln(Decision).%CurentFront,NextFront,ListOfOpenState,-ListOfMovesFromCurentToFinalStatebreadth_search([s(State,Path)|_],_,_,Path):-final_state(State).breadth_search([s(State,Path)|Fr],NextFr,History,EndPath):-findall(State1-Move,(choise2(State,1,N,X,Y),move(X,Y,N,State,State1,Move)),NextMoves),next_fr_add(NextMoves,NextFr,NextFr1,History,Path),history_add(State,History,History1),breadth_search(Fr,NextFr1,History1,EndPath).breadth_search([],[],_,_):-!,fail.breadth_search([],NextFr,History,Move):-breadth_search(NextFr,[],History,Move).%MoveOfCurentState,CurentFront,AddingFront,PathToCurentStatenext_fr_add([State-Move|NextMoves],NextFr,[s(State,[Move|Path])|NextFr1],History,Path):-not(member(State,History)),!,next_fr_add(NextMoves,NextFr,NextFr1,History,Path).next_fr_add([_|NextMoves],NextFr,NextFr1,History,Path):-next_fr_add(NextMoves,NextFr,NextFr1,History,Path).next_fr_add([],NextFr,NextFr,_,_).%State,History,AddingHistoryhistory_add(State,History,History):-final_state(State),!.history_add(State,History,[State|History]).%criterion_function([S1,S2|State],I,Estimate):-% S1=S2,% I1 is I-1,% criterion_function([S2|State],I1,Estimate).%criterion_function([S1,S2|State],I,Estimate):-%S1\=S2,% criterion_function([S2|State],I,Estimate).%criterion_function([_],I,I).%+List,+Counter,-PositionOfX,-X,-Ychoise2([X,Y|_],I,I,X,Y):-X\=empty,Y\=empty.choise2([_|Xs],I,N,X,Y):-I1isI+1,choise2(Xs,I1,N,X,Y).%+X,+Y,+PositionOfX,+CurentState,-NextState,-Movemove(X,Y,N,State,State1,N-A):-search_empty(State,1,A),rearrange(State,X,Y,A,InterimState),rearrange(InterimState,empty,empty,N,State1).%+list,+Counter,-PositionOfEmptysearch_empty([E|_],I,I):-E=empty.search_empty([E|Es],I,N):-E\=empty,I1isI+1,search_empty(Es,I1,N).%+ListOfCurentState,+Item1,+Item2,+Counter,-ListOfNewStaterearrange([X|Xs],A,B,I,[X|Xn]):-I>1,I1isI-1,rearrange(Xs,A,B,I1,Xn).rearrange([_,_|Xs],A,B,1,[A,B|Xs]).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Forward chaining systems keep running until all position conclusions have been reached from available knowledge. The farmer's dilemma example program, for example, finds all of the possible solutions, rather than stopping when the first is found. Forward chaining systems are not driven in the same way as a backward chaining system such as prolog, so you're not going to find direct translations for functionality in one system that you can use in the other.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
trere are 10 chips . I need to reposition they to final-state . Something like that:
(deffacts MAIN::initial-position
(status (search-depth 1)
(parent no-parent)
(last-move no-move)
(chips white black white black white black white black empty empty )
))
(defrule SOLUTION::recognize-solution
(declare (auto-focus TRUE))
?node <- (status (parent ?parent)
(last-move ?move)
(chips black black black black white white white white empty empty))
=>
(retract ?node)
(assert (moves (id ?parent) (moves-list ?move))))
the correct step is to reposition 2 not empty chips, that stay together with to empty chips….i tried to do it like that
(defrule MAIN::move-alone
?node<-(status (search-depth ?num) ;curent state of search
(chips $?chip))
;?choise1<-(member empty $?chip)
;?choise2<-(member ?c2&~empty $?chip) (member ?c2&~empty $?chip)
=>
(bind ?notempty1 (nth$ (- 1(nempty $?chip)) ?chip)) ;find color of first not empty chip
(bind ?notempty2 (nth$ (nempty $?chip) ?chip)) ;find color of second not empty chip
(bind ?notempty1pos (- 1(nempty $?chip))) ;find position of not empty chip
(bind ?notempty2pos (nempty $?chip))
(bind $?chip1 (replace$ ?chip (member$ empty ?chip) (member$ empty ?chip) ?notempty1)) ; reposition chips
(bind $?chip2 (replace$ ?chip1 (+ 1 (member$ empty ?chip1)) (+ 1 (member$ empty ?chip1) ?notempty2)))
(bind $?chip3 (replace$ ?chip2 ?notempty1pos ?notempty2pos empty))
(duplicate ?node (search-depth (+ 1 ?num)) ;change curent state of search
(parent ?node)
(last-move (member$ empty ?chip) (nempty $?chip))
(chips $?chip3)
))
but I don`t know how can I write function nempty, that return position of second not empty chip…
help me please…. i will be thank you very much for any ideas for decision of this problem…..
I thing it will be something like that, but there is some mistake with circularity
(deffunction nempty ( ?i $?chip)
(if (and (or (eq (first$ ?chip) white)(eq (first$ ?chip) black))(or (eq (first$ (rest$ ?chip)) white)(eq (first$ (rest$ ?chip)) black)))
then (return ?i)
else (nempty (+ 1 ?i) $?chip)))
CLIPS>
(deffunction find-nth-occurrence (?n ?value ?list)
(bind ?position (member$ ?value ?list))
(if (or (not ?position)
(= ?n 1))
then
(return ?position))
(bind ?next (find-nth-occurrence (- ?n 1)
?value
(subseq$ ?list (+ ?position 1) (length$ ?list))))
(if ?next
then
(return (+ ?position ?next))
else
(return ?next)))
CLIPS> (find-nth-occurrence 1 empty (create$ white black empty black black white white empty black empty))
3
CLIPS> (find-nth-occurrence 2 empty (create$ white black empty black black white white empty black empty))
8
CLIPS> (find-nth-occurrence 3 empty (create$ white black empty black black white white empty black empty))
10
CLIPS> (find-nth-occurrence 4 white (create$ white black empty black black white white empty black empty))
FALSE
CLIPS>
thank you very much for yuor comment, but I have one another question about this goal… I need find the answer with the help of 3 method of search : depth first search, breadth first search and someone width cost function, hill climbing fir example)….and I find answer with the help of first method… I know advantage of CLIPS , that it perfect for "breadth first search" and the main idea of this searching, but all the same i can not cjmbine it… for example I know how i can do it with the help of prolog….maybe can someone help me "translate" it for CLIPS?
How can I do in my program function like setof or findall in prolog?
Forward chaining systems keep running until all position conclusions have been reached from available knowledge. The farmer's dilemma example program, for example, finds all of the possible solutions, rather than stopping when the first is found. Forward chaining systems are not driven in the same way as a backward chaining system such as prolog, so you're not going to find direct translations for functionality in one system that you can use in the other.