I'm trying to created a player that would solve the game Mastermind in LISP. I tried using the following nested loop in a helper function
(defparameter *counter* 0)
;analyze the score to determine whether points need to be added to counter
(defun analyze (last-response)
(if (> (first last-response) 0)
(setf *counter* (+ (first last-response) *counter*))))
;helper function for finding correct color
(defun guessColor (length colors last-response)
(loop while (< *counter* 4) do
(loop for i from 1 to length
collect (first colors)
(setf colors (rest colors)))
(analyze (last-reponse))))
;baseline Holyguacamole player will guess all colors before trying all combinations of correct color
(defun HolyGuacamole (board colors SCSA last-response)
(declare (ignore SCSA))
;(print last-response)
(guessColor board colors last-response)
(print *counter*)
;(sortColor)
)
The while loop is supposed to run while the global variable *counter* is less than 4. The inside loop is supposed to guess colors based on the length of pegs required (variable length). I've been running into the compilation error
during macroexpansion of (LOOP WHILE (< COUNTER 4) ...). Use ;
BREAK-ON-SIGNALS to intercept.
I'm unfamiliar with LISP so I'm not sure what that error code means and how to fix it. I felt like I nested it correctly with the proper parenthesis, but I'm not actually sure what's wrong with it.
Link to Mastermind environment.
scoreoranalyzeor the declaration of*counter*(analyze (last-reponse))))should be(analyze last-reponse)))... There also seem to be some other errors... I haven't been able to reproduce that exact compiler error withclisporsbcl.(SETF...)in the inner loop. Only one form is allowed in aCOLLECT-clause. You probably should put it in aDO-clause. Or you could usePOPinsted ofFIRSTand remove theSETF. I'm not sure what you expect the inner loop to achieve though. It collects the firstLENGTHelements fromCOLORS, but its return value is just discarded by the outer loop.