我正在尝试用LISP编写一个玩家来解决游戏策划者。在这种环境中:http://pastebin.com/8XW8HZza
我试图让玩家仔细检查每种颜色,并在将其分类到正确位置之前进行单色猜测。这就是我到目前为止所做的:
(defvar *counter* 0)
(defvar *ElementsViewed* -1)
(defvar *CorrectColors* NIL)
(defun ith-element (list)
(nth *ElementsViewed* list))
;analyze the score to determine whether points need to be added to counter
(defun analyze (last-response colors)
(cond ((equal last-response nil)
(setf *counter* 0)))
(cond ((equal last-response nil)
(setf *ElementsViewed* -1)))
(cond ((equal last-response nil)
(setf *CorrectColors* NIL)))
(cond ((equal last-response nil) NIL)
((= (first last-response) 0))
(T (setf *counter* (+ (first last-response) *counter*))))
(cond ((equal last-response nil))
((= (first last-response) 0))
(T (loop for i from 1 to (first last-response) do (setf *CorrectColors* (cons (ith-element colors) *CorrectColors*)))))
)
;helper function for finding correct color
(defun guess-color (length colors)
(print (ith-element colors))
(loop for i from 1 to length collect (ith-element colors))
)
(defun sort-color (length)
(loop for i from 1 to length
for item in *CorrectColors*
collect item))
;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)
(analyze last-response colors)
(print *counter*)
(if (= *counter* board)
(sort-color board))
(setf *ElementsViewed* (1+ *ElementsViewed*))
(guess-color board colors)
)
玩家首先猜测代码中的正确颜色。每次进行猜测时,系统都会返回一个响应(#correct #other#guess-so-far),其中#correct是正确挂钉位置的正确颜色数,而#other在错误的挂钩中颜色正确位置。虽然玩家每次将#correct添加到列表*CorrectColors*
时都会添加正确的颜色,但它还会添加一个计数器来确定它是否收集了所有正确的颜色。如果它完成了所有正确的颜色,当我尝试玩游戏时,它会转到函数sort-color
,但它似乎没有正确运行该函数,因为我有以下示例输出:
HOLYGUACAMOLE
NIL
0
A
(0 0 1)
0
B
(0 0 2)
0
C
(0 0 3)
0
D
(2 0 4)
2
E
(0 0 5)
2
F
(0 0 6)
2
G
(0 0 7)
2
H
(1 0 8)
3
我
(0 0 9)
3
J
(1 0 10)
4
NIL
(SCORE -2)
(0 0 1)
在这个游戏的情况下,我正在玩4个钉子和10个可能的颜色。一旦计数器达到4,它应该从*CorrectColors*
收集答案。但是,它从来没有回应过。我究竟做错了什么?我尝试使用
(defun sort-color (length)
(loop for i from 1 to length
for item in *CorrectColors*
do (print item)))
测试它是否正确循环并且它会打印出所有正确的颜色。但是,它似乎没有返回系统的答案。