我试图创建一个可以解决LISP游戏策略的玩家。我尝试使用以下嵌套循环在一个辅助函数共同嵌套循环LISP
(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)
)
while循环应该运行,而全局变量*counter*
是小于4内部循环被认为基于钉所需要的长度来猜测颜色(可变长度)。中宏扩展期间,我一直运行到编译错误
(循环while(< COUNTER 4)...)。使用 ;
BREAK-ON-SIGNALS要拦截。
我不熟悉LISP,所以我不确定那个错误代码的含义以及如何解决它。我觉得我用正确的括号正确地嵌套了它,但我并不确定它有什么问题。
Link to Mastermind environment。
整个程序有多大?你可以粘贴它,也可以把它缩小为一个独立的例子吗?我没有看到“分数”或“分析”的定义或者“*计数器*”的声明# –
@GregoryNisbet游戏本身的代码非常大。我编辑了我的帮助函数以及* counter *的声明。分数改为最后回应 – trungnt
我认为'(analyze(last-reponse))))'应该是'(分析last-reponse)))'......似乎还有其他一些错误......我避难无法用'clisp'或'sbcl'重现那个确切的编译错误。 –