; Обявление шаблона фрейма для описания модели предметной области
(deftemplate vcard
		(slot parametr (type SYMBOL))
		(slot status (type SYMBOL))
		(slot brand (type SYMBOL))
		(slot pref (type NUMBER)(default 0)))
		
; Объявление функций для формулирования дополнительных вопросов
(deffunction ask_vram()
		(printout t "Насколько важен для Вас этот параметр?" crlf
		"1. Не очень важен. (Ответ-1)" crlf
		"2. Очень важен. (Ответ-2)" crlf
		"Ваш ответ: "))

(deffunction ask_cool()
	   (printout t "Укажите важность для Вас этого параметра." crlf
		"1. Есть параметры и поважней. (Ответ-1)" crlf
		"2. СО - самый главный атрибут видеокарты. (Ответ-2)" crlf
		"Ваш ответ: "))

(deffunction ask_mass()
		(printout t "Насколько важны для Вас эти параметры?" crlf
		"1. Не очень важны. (Ответ-1)" crlf
		"2. Очень важны. (Ответ-2)" crlf
		"Ваш ответ: "))

(deffunction ask_prog_test()
(printout t "Насколько важны для Вас результаты     
 тестирования?" crlf
	"1. Принимаю к сведению. (Ответ-1)" crlf
	"2. Только тестирование дает представление об истинном" crlf
	    "качестве видеокарты. (Ответ-2)" crlf
	    "Ваш ответ: "))

; Правила, создающие модель предметной области
(defrule overclock
		(initial-fact)
		=>
		(printout t crlf "Вы любитель разгона? (yes/no): ")
		(bind ?overclock (read))
		(if (eq ?overclock yes) then
		(printout t "Насколько важен для Вас этот параметр?" crlf
		  "1. Чистое любопытство. (Ответ-1)" crlf
		  "2. Без разгона не могу. (Ответ-2)" crlf
		  "Ваш ответ: ")
	(assert (vcard (parametr overclock)(status yes)(brand GeForce)
									        (pref (read))))
		else
	(assert (vcard (parametr overclock)(status no)(brand Radeon))))
	(assert (overclock done)))
		
;--------------------------------------------------------------------------------

(defrule modding
		?overclock <- (overclock done)
		=>
		(printout t crlf "Вы любитель моддинга? (yes/no): ")
		(bind ?modding (read))
		(if (eq ?modding yes) then
		(printout t "Насколько важен для Вас этот параметр?" crlf
		 "1. Хорошо, если есть. (Ответ-1)" crlf
		 "2. Без моддинга не могу. (Ответ-2)" crlf
		 "Ваш ответ: ")
	(assert (vcard (parametr modding)(status yes)(brand GeForce)
									     (pref (read))))
		else
	(assert (vcard (parametr modding)(status no)(brand Radeon))))
		(retract ?overclock)
		(assert (modding done)))

;---------------------------------------------------------------------------------

(defrule mount
		?modding <- (modding done)
		=>
	(printout t crlf "Вы будете сами установливать видеокарту? 
   (yes/no): ")
	(bind ?mount (read))
	(if (eq ?mount yes) then
	(printout t "Насколько важна для Вас эта операция?" crlf
	"1. Не обижусь, если придется повозиться. (Ответ-1)" crlf
	"2. Легкость установки - вопрос принципиальный. (Ответ-2)" crlf
	"Ваш ответ: ")
	(assert (vcard (parametr mount)(status yes)(brand Radeon)
								        (pref (read))))
	else
	(assert (vcard (parametr mount)(status no)(brand Radeon))))
	(retract ?modding)
	(assert (mount done)))

;---------------------------------------------------------------------------------

(defrule vram
		?mount <- (mount done)
		=>
	(printout t crlf "Какой объем видеопамяти Вас устроит?" crlf
		"1. 256 MB - это то, что надо. (Ответ-1)" crlf
		"2. 128 MB - вполне достаточно. (Ответ-2)" crlf
		"3. Затрудняюсь ответить. (Ответ-3)" crlf
		"Ваш ответ: ")
		(bind ?vram (read))
		(if (eq ?vram 1) then
			(ask_vram)
		(assert (vcard (parametr vram)(status yes)(brand Radeon)
									      (pref (read)))))
		(if (eq ?vram 2) then
			(ask_vram)
		(assert (vcard (parametr vram)(status yes)(brand GeForce)
										 (pref (read)))))
		(if (eq ?vram 3) then
		(assert (vcard (parametr vram)(status no)(brand GeForce))))
			(retract ?mount)
			(assert (vram done)))

;---------------------------------------------------------------------------------

(defrule cool
		?vram <- (vram done)
		=>
	(printout t crlf "Ваши требования к системе охлаждения?" crlf
		"1. Малошумная. (Ответ-1)" crlf
		"2. Более шумная, но интеллектуальная. (Ответ-2)" crlf
		"3. Затрудняюсь ответить. (Ответ-3)" crlf
		"Ваш ответ: ")
		(bind ?cool (read))
		(if (eq ?cool 1) then
			(ask_cool)
		(assert (vcard (parametr cool)(status yes)(brand Radeon)
									      (pref (read)))))
		(if (eq ?cool 2) then
			(ask_cool)
		(assert (vcard (parametr cool)(status yes)(brand GeForce)
										 (pref (read)))))
		(if (eq ?cool 3) then
		(assert (vcard (parametr cool)(status no)(brand GeForce))))
			(retract ?vram)
			(assert (cool done)))

;---------------------------------------------------------------------------------

(defrule mass
		?cool <- (cool done)
		=>
(printout t crlf "Ваши требования к габаритам и массе видеокарты?" crlf
		"1. Носить видеокарту с собой не собираюсь," crlf
		"но поменьше и полегче - это хорошо. (Ответ-1)" crlf
		"2. Чем больше и массивней, тем надежней. (Ответ-2)" crlf
		"3. А черт его знает. (Ответ-3)" crlf
		"Ваш ответ: ")
		(bind ?mass (read))
		(if (eq ?mass 1) then
			(ask_mass)
		(assert (vcard (parametr mass)(status yes)(brand Radeon)
									      (pref (read)))))
		(if (eq ?mass 2) then
			(ask_mass)
		(assert (vcard (parametr mass)(status yes)(brand GeForce)
										  (pref (read)))))
		(if (eq ?mass 3) then
		(assert (vcard (parametr mass)(status no)(brand Radeon))))
			(retract ?cool)
			(assert (mass done)))

;---------------------------------------------------------------------------------			

(defrule prog_test
		?mass <- (mass done)
		=>
	(printout t crlf "Тестам какой программы Вы отдаете 
   предпочтение" crlf
            	        "при выборе видеокарты?" crlf
		"1. 3DMark. (Ответ-1)" crlf
		"2. Unreal Tournament. (Ответ-2)" crlf
		"3. Понятия не имею. (Ответ-3)" crlf
		"Ваш ответ: ")
		(bind ?prog_test (read))
		(if (eq ?prog_test 1) then
			(ask_prog_test)
	(assert (vcard (parametr prog_test)(status yes)(brand GeForce)
										  (pref (read)))))
		(if (eq ?prog_test 2) then
			(ask_prog_test)
	(assert (vcard (parametr prog_test)(status yes)(brand Radeon)
										  (pref (read)))))
		(if (eq ?prog_test 3) then
	(assert (vcard (parametr prog_test)(status no)(brand Radeon))))
			(retract ?mass)
			(assert (knowledge done)))