📄 rx7.clp
字号:
;;###################################################
;;###################################################
;; RX7.CLP ##
;; Mazda RX-7 rotary engine troubleshooter. ##
;; ##
;;###################################################
;;###################################################
;;
;; Operating instructions:
;; 1.) Execute the CLIPS interpreter.
;; 2.) From the CLIPS prompt, type (load "rx7.clp").
;; 3.) Type (reset) and then (run) to execute the program.
;;
;;**********************************
;; Set up initial facts for testing.
;;**********************************
;;
(deffacts init
(troubleshoot-mode engine)
(menu-level engine main))
;;
;;****************************************************
;; Clear the screen and present the main menu. *
;; *
;; Variables: *
;; ?ml - used for retracting the menu level. *
;; ?response - used for binding in the users input.*
;;****************************************************
;;
(defrule main-menu
(declare (salience 500))
(troubleshoot-mode engine)
?ml <- (menu-level engine main)
=>
(retract ?ml)
;;** print 25 crlf's to clear screen **
(printout t crlf crlf crlf)
(printout t
" Choose one of the problem areas listed below" crlf
" by typing a letter and pressing the return key." crlf crlf
" 1.) Difficult starting." crlf
" 2.) Poor idling." crlf
" 3.) Insufficient power." crlf
" 4.) Abnormal combustion." crlf
" 5.) Excessive oil consumption." crlf
" 6.) Engine noise." crlf
" 7.) Quit the program." crlf crlf
" Choice: " )
(bind ?response (read))
(assert (problem-response engine ?response))
(printout t crlf))
;;
;;
;;***************************************
;; If the user enters a response of 7 *
;; from the main menu, *
;; Then print ending message and clear *
;; the fact base. *
;;***************************************
(defrule user-quits
(troubleshoot-mode engine)
(problem-response engine 7)
=>
(printout t "You have QUIT the program." crlf)
(halt))
;;
;;*******************************
;; If the user selects 1 *
;; Then assert that the problem *
;; is DIFFICULT STARTING. *
;; *
;; Variables: *
;; ?pr - for retracting the *
;; numeric problem *
;; response. *
;;*******************************
(defrule difficult-starting
(troubleshoot-mode engine)
?pr <- (problem-response engine 1)
=>
(retract ?pr)
(assert (menu-level engine possible-causes-1-1))
(assert (problem engine difficult-starting)))
;;
;;*******************************
;; If the user selects 2 *
;; Then assert that the problem *
;; is POOR IDLING. *
;; *
;; Variables: *
;; ?pr - for retracting the *
;; numeric problem *
;; response. *
;;*******************************
(defrule poor-idling
(troubleshoot-mode engine)
?pr <- (problem-response engine 2)
=>
(retract ?pr)
(assert (menu-level engine possible-causes-1-1))
(assert (problem engine poor-idling)))
;;
;;*******************************
;; If the user selects 3 *
;; Then assert that the problem *
;; is INSUFFICIENT POWER. *
;; *
;; Variables: *
;; ?pr - for retracting the *
;; numeric problem *
;; response. *
;;*******************************
(defrule insufficient-power
(troubleshoot-mode engine)
?pr <- (problem-response engine 3)
=>
(retract ?pr)
(assert (menu-level engine possible-causes-1-1))
(assert (problem engine insufficient-power)))
;;
;;*******************************
;; If the user selects 4 *
;; Then assert that the problem *
;; is ABNORMAL COMBUSTION. *
;; *
;; Variables: *
;; ?pr - for retracting the *
;; numeric problem *
;; response. *
;;*******************************
(defrule abnormal-combustion
(troubleshoot-mode engine)
?pr <- (problem-response engine 4)
=>
(retract ?pr)
(assert (menu-level engine possible-causes-1-2))
(assert (problem engine abnormal-combustion)))
;;
;;*************************************
;; If the user selects 5 *
;; Then assert that the problem *
;; is EXCESSIVE OIL CONSUMPTION. *
;; *
;; Variables: *
;; ?pr - for retracting the *
;; numeric problem *
;; response. *
;;*************************************
(defrule excessive-oil-consumption
(troubleshoot-mode engine)
?pr <- (problem-response engine 5)
=>
(retract ?pr)
(assert (menu-level engine possible-causes-1-3))
(assert (problem engine excessive-oil-consumption)))
;;
;;*******************************
;; If the user selects 6 *
;; Then assert that the problem *
;; is ENGINE NOISE. *
;; *
;; Variables: *
;; ?pr - for retracting the *
;; numeric problem *
;; response. *
;;*******************************
(defrule engine-noise
(troubleshoot-mode engine)
?pr <- (problem-response engine 6)
=>
(retract ?pr)
(assert (menu-level engine possible-causes-1-4))
(assert (problem engine engine-noise)))
;;
;;********************************************
;; Clear the screen and present the possible *
;; causes for DIFFICULT STARTING, or *
;; POOR IDLING, or INSUFFICIENT POWER *
;; depending on the variable ?problem. *
;; *
;; Variables: *
;; ?problem - the problem selected by the *
;; user. *
;; ?response - used for binding in the *
;; users input. *
;;********************************************
;;
(defrule possible-causes-1-1
(troubleshoot-mode engine)
(menu-level engine possible-causes-1-1)
(problem engine ?problem&difficult-starting|poor-idling|insufficient-power)
=>
(printout t crlf crlf crlf)
(printout t
" You selected " ?problem " as the problem you would" crlf
" like to solve. If you change your mind and would like" crlf
" to review the main menu, press 0 now, otherwise select one" crlf
" of the possible causes of " ?problem " listed below."
crlf crlf
" 0.) Return to main menu." crlf
" 1.) Insufficient compression." crlf
" 2.) Malfunction of fuel system." crlf
" 3.) Malfunction of electrical system." crlf crlf
" Choice: " )
(bind ?response (read))
(assert (possible-cause ?problem ?response))
(printout t crlf))
;;
;;********************************************
;; Clear the screen and present the possible *
;; causes for ABNORMAL COMBUSTION. *
;; *
;; Variables: *
;; ?response - used for binding in the *
;; users response. *
;;********************************************
(defrule possible-causes-1-2
(troubleshoot-mode engine)
(menu-level engine possible-causes-1-2)
(problem engine abnormal-combustion)
=>
(printout t crlf crlf crlf)
(printout t
" You selected abnormal-combustion as the problem you would" crlf
" like to solve. If you change your mind and would like" crlf
" to review the main menu, press 0 now, otherwise select one" crlf
" of the possible causes of abnormal-combustion listed below."
crlf crlf
" 0.) Return to main menu." crlf
" 1.) Malfunction in combustion chamber." crlf
" 2.) Malfunction of fuel system." crlf
" 3.) Malfunction of ignition system." crlf
" Choice: ")
(bind ?response (read))
(assert (possible-cause abnormal-combustion ?response))
(printout t crlf))
;;
;;********************************************
;; Clear the screen and present the possible *
;; causes for EXCESSIVE OIL CONSUMPTION. *
;; *
;; Variables: *
;; ?response - used for binding in the *
;; users response. *
;;********************************************
(defrule possible-causes-1-3
(troubleshoot-mode engine)
(menu-level engine possible-causes-1-3)
(problem engine excessive-oil-consumption)
=>
(printout t crlf crlf crlf)
(printout t
" You selected excessive-oil-consumption as the problem you" crlf
" would like to solve. If you change your mind and would like" crlf
" to review the main menu, press 0 now, otherwise select one" crlf
" of the possible causes of excessive-oil-consumption listed below."
crlf crlf
" 0.) Return to main menu." crlf
" 1.) Leakage into combustion chamber." crlf
" 2.) Leakage into coolant passages." crlf
" 3.) Leakage to outside of engine." crlf
" 4.) Malfunction of lubricating system." crlf
" Choice: ")
(bind ?response (read))
(assert (possible-cause excessive-oil-consumption ?response))
(printout t crlf))
;;
;;********************************************
;; Clear the screen and present the possible *
;; causes for ENGINE NOISE. *
;; *
;; Variables: *
;; ?response - used for binding in the *
;; users response. *
;;********************************************
(defrule possible-causes-1-4
(troubleshoot-mode engine)
(menu-level engine possible-causes-1-4)
(problem engine engine-noise)
=>
(printout t crlf crlf crlf)
(printout t
" You selected engine-noise as the problem you would like" crlf
" to solve. If you change your mind and would like to" crlf
" review the main menu, press 0 now, otherwise select one" crlf
" of the possible causes of engine-noise listed below."
crlf crlf
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -