; Blocks World Problem: Demonstration of Hill Climbing
; - Rohit Kumar
; Dt: 7 Nov. 2002

; Currently Solving for 4 blocks only

(defun IsItGoal (State)
	(if (eq car(State) '(a b c d))
		(return-from IsItGoal t)
		(return-from IsItGoal nil)
	)
)

(defun Evaluate (State)
	(let (count1 i count2 j score)
		(setq score 0)
		(setq count1 0)
		(dolist (i State)
			(setq count2 0)
			(dolist (j i)
				(if (eq j 'a)
					(let ()
						(if (eq count2 0)
							(+ score 1)
							(- score 1)
						)
						(if (eq (nth (+ count2 1) i) 'b)
							(+ score 1)
							(- score 1)
						)
					)
				)	
				(if (eq j 'b)
					(let ()
						(if (eq (nth (- count2 1) i) 'a)
							(+ score 1)
							(- score 1)
						)
						(if (eq (nth (+ count2 1) i) 'c)
							(+ score 1)
							(- score 1)
						)
					)
				)
				(if (eq j 'c)
					(let ()
						(if (eq (nth (- count2 1) i) 'b)
							(+ score 1)
							(- score 1)
						)
						(if (eq (nth (+ count2 1) i) 'd)
							(+ score 1)
							(- score 1)
						)
					)
				)
				(if (eq j 'd)
					(let ()
						(if (eq count2 3)
							(+ score 1)
							(- score 1)
						)
						(if (eq (nth (- count2 1) i) 'c)
							(+ score 1)
							(- score 1)
						)
					)
				)	
				(setq count2 (1+ count2))
			)
			(setq count1 (1+ count1))
		)
		(return-from Evaluate score)
	)
)
