在lisp中调试minimax游戏awele“oware”

时间:2014-10-27 13:51:46

标签: debugging lisp common-lisp sbcl slime

你好我是lisp的新人,我有大学开发游戏的项目 "西非播棋"使用minimax" ai"

并且我坚持这个错误,我真的失去了调试我有这个功能

(defun alpha-beta (player board n-score s-score alpha beta depth)
  (if (or (= depth 0) (game-over player board n-score s-score))
    (eval-s player n-score s-score)
    (let* ((moves (valid-list player board))
           (b-move (first moves)))
      (loop for move in moves do
            (let* ((l-board-score (multiple-value-list (make-move move (copy-seq board) player)))
                   (board2 (car l-board-score))
                   (val (- (alpha-beta (opponent player) board2 
                                       (if (= player north ) (+ n-score (cdar l-board-score)) n-score)
                                       (if (= player south ) (+ s-score (cdar l-board-score)) s-score)
                                       (- alpha) (- beta) 
                                       (1- depth)))))
              (when (> val alpha)
                (setf alpha val)
                (setf b-move move)))
            until (>= alpha beta))
      (values alpha b-move))))

其中board是一个简单的数字列表,所有其他参数都是数字,但是当我测试函数时,我得到了这个错误

Argument Y is not a NUMBER: (5 5 5 5 4 4 4 4 4 4 4)
   [Condition of type SIMPLE-TYPE-ERROR]

Restarts:
....

Backtrace:
  0: (SB-KERNEL:TWO-ARG-+ 0 (5 5 5 5 4 4 ...))
      Locals:
        SB-DEBUG::ARG-0 = 0
        SB-DEBUG::ARG-1 = (5 5 5 5 4 4 ...)
  1: (ALPHA-BETA 0 (4 4 4 4 4 4 ...) 0 0 -200 200 6)
      Locals:
        ALPHA = -200
        B-MOVE = 0
        BETA = 200
        BOARD = (4 4 4 4 4 4 ...)
        BOARD2 = (0 5 5 5 5 4 ...)
        DEPTH = 6
        L-BOARD-SCORE = ((0 5 5 5 5 4 ...) 0)
        #:LOOP-LIST-157 = (1 2 3 4 5)
        MOVE = 0
        MOVES = (0 1 2 3 4 5)
        N-SCORE = 0
        PLAYER = 0
        S-SCORE = 0
  2: (SB-DEBUG::TRACE-CALL #<SB-DEBUG::TRACE-INFO ALPHA-BETA> #<FUNCTION ALPHA-BETA> 0 (4 4 4 4 4 4 ...) 0 0 -200 200 6)
      Locals:
        FUNCTION = #<FUNCTION ALPHA-BETA>
        INFO = #<SB-DEBUG::TRACE-INFO ALPHA-BETA>
        #:REST-CONTEXT-737 = 70368649080632
        #:REST-COUNT-738 = 7
        MORE = (0 (4 4 4 4 4 4 ...) 0 0 -200 200 ...)
  3: (SB-INT:SIMPLE-EVAL-IN-LEXENV (ALPHA-BETA 0 *BOARD* 0 0 -200 ...) #<NULL-LEXENV>)
      Locals:
        SB-DEBUG::ARG-0 = (ALPHA-BETA 0 *BOARD* 0 0 -200 ...)
        SB-DEBUG::ARG-1 = #<NULL-LEXENV>
  4: (EVAL (ALPHA-BETA 0 *BOARD* 0 0 -200 ...))
      Locals:
        SB-DEBUG::ARG-0 = (ALPHA-BETA 0 *BOARD* 0 0 -200 ...)

我非常感谢任何帮助调试,非常感谢

1 个答案:

答案 0 :(得分:2)

您正尝试在这些行中为列表添加数字:

(if (= player north ) (+ n-score (cdar l-board-score)) n-score)
(if (= player south ) (+ s-score (cdar l-board-score)) s-score)

从调试中可以看出:

L-BOARD-SCORE = ((0 5 5 5 5 4 ...) 0)

如果您想从[{1}}中提取第一个0,则需要l-board-score如果您想要第一个caar,请使用5,依此类推。