I am a beginner in CLIPS and cannot figure out how to get the above code to work right despite spending hours on it. Any help would be appreciated.Thank you.
(deftemplate gem
(players <number_robots>)
(Goal_posts <number_goal_posts>)
(Field <dimension>)
(players goalkeeper <number_goalkeepers> <goalkeeper_linear_speed> <goalkeeper_angular_speed> {static, running})
(players defenders <number_defenders> <defender_linear_speed> <defender_angular_speed> {static, running})
(players midfielder <number_midfielders> <midfielder_linear_speed> <midfielder_angular_speed> {static, running})
(players striker <number_strikers> <striker_linear_speed> <striker_angular_speed> {static, running})
(ball <poz_x> <poz_y)
(oponents <nume> <poz_oponents_x> <poz_oponents_y>))
(deffacts initial-state
(player goalkeeper 1 10 6 static)
(player defenders number_defenders 15 10 running)
(player midfielders number_midfielders 17 12 running)
(player strikers number_strikers 9 10 running)
(ball 5 5)
(oponents Robot1 1 2)
(oponents Robot2 2 4)
(oponents Robot3 7 2)
(oponents Robot4 10 20)
(oponents Robot5 11 8)
(oponents Robot6 20 10)
(oponents Robot7 5 9)
)
;The number of robots per team must be variable and the user has to be able to set or adjust it.
(defrule number_of_robots
=>
(printout t "Type the number of robots per team"
crlf)
(assert (number_robots (read)))
(printout t "Type the number of goal posts" crlf)
(assert (number_goal_posts (read))))
(defrule check-input
?number_robots <-
(number ?number_robots)
(test (integerp ?number_robots))
=>
(retract ?number_robots)
(printout t "Correct number of robots" crlf))
(defrule check-input1
?number_goal_posts <-
(number ?number_goal_posts)
(test (integerp ?number_goal_posts))
=>
(retract ?number_goal_posts)
(printout t "Correct number of goal posts" crlf))
;The user will initially input data on the dimension of the fotball field and goal post.
(defrule dimension_field
=>
(printout t "Type the football field dimension" crlf)
(assert (dimension (read))))
(defrule check-input1
?dimension <-
(number ?dimension)
(test (integerp ?dimension))
=>
(retract ?dimension)
(printout t "Correct dimension of footbal field" crlf))
;Each team must have a goalkeeper, while the number of defenders, midfielders and strikers is to be set by the user to match the stated number of players
(defrule reading-input
=>
printout t "Type the number of defenders" crlf
(assert (number_defenders(read)))
printout t "Type the number of midfielders" crlf
(assert (number_midfielders(read)))
printout t "Type the number of strikers" crlf
(assert (number_strikers(read)))
)
(defrule check-input2
?number_defenders <-
(number ?number_defenders)
(test (integerp ?number_defenders))
=>
(retract ?number_defenders)
(printout t "Correct number of defenders " crlf))
(defrule check-input3
?number_midfielders <-
(number ?number_midfielders)
(test (integerp ?number_midfielders))
=>
(retract ?number_midfielders)
(printout t "Correct number of midfielders " crlf))
(defrule check-input4
?number_strikers <-
(number ?number_strikers)
(test (integerp ?number_strikers))
=>
(retract ?number_strikers)
(printout t "Correct number of strikers " crlf))
)
My errors after running the code are:
[PRNTUTIL2] Syntax Error: Check appropriate syntax for deftemplate.
ERROR: (deftemplate MAIN::gem (players
[CSTRCPSR1] WARNING: Redefining deffacts: initial-state
[CSTRCPSR1] WARNING: Redefining defrule: number_of_robots +j Defining defrule: check-input =j+j
[CSTRCPSR1] WARNING: Redefining defrule: check-input1 =j+j
[CSTRCPSR1] WARNING: Redefining defrule: dimension_field +j
[CSTRCPSR1] WARNING: Redefining defrule: check-input1 =j+j
[CSTRCPSR1] WARNING: Redefining defrule: reading-input +j
[CSTRCPSR1] WARNING: Redefining defrule: check-input2 =j+j
[CSTRCPSR1] WARNING: Redefining defrule: check-input3 =j+j
[CSTRCPSR1] WARNING: Redefining defrule: check-input4 =j+j
[CSTRCPSR1] Expected the beginning of a construct.