Search code examples
debugginglispcommon-lispsbclslime

debug minimax game awele "oware" in lisp


Hello I'm new at lisp and I have as project for the university to develop a game "oware" with a minimax "ai"

and im stuck on this error and im really lost on de debug i have this function

(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))))

where board is a simple number list and all other parameters are numbers but when I test the function I get this error

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 ...)

I would appreciate any help to debug that thanks very much


Solution

  • You are trying to add a number to a list in these lines:

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

    As you can see from the debug:

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

    If you want to extract the first 0 from l-board-score you need caar If you want the first 5 then use cadar, and so on.