gpt4 book ai didi

debugging - 在 lisp 中调试 minimax game awele "oware"

转载 作者:太空宇宙 更新时间:2023-11-03 18:59:05 37 4
gpt4 key购买 nike

你好,我是 lisp 的新手,我有一个项目要为大学开发一个游戏“oware”与极小极大“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 ...)

非常感谢任何调试帮助

最佳答案

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

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

如果你想从 l-board-score 中提取第一个 0 你需要 caar 如果你想要第一个 5 然后使用 cadar,依此类推。

关于debugging - 在 lisp 中调试 minimax game awele "oware",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26589093/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com