Re: -2 is not a real number?!?
- From: Ken Tilton <kentilton@xxxxxxxxx>
- Date: Tue, 27 Feb 2007 20:11:02 -0500
cdombroski wrote:
I'm currently working on a class project in Lisp, and I've run into a
problem. I'm trying to write a tic-tac-toe program that uses alpha-beta
searching for an AI player. Whenever the AI takes a turn the program blows
up saying that a particular variable is "not a real number". Further
proding shows that the variable is an integer whose value is -2
As this class is my first experience in Lisp, I'm at a loss of what the
problem could be. I tried emailing the teacher and didn't get very far.
Here's the function where the error occurs and the GNU CLISP interpreter
output of the error:
(defun min-value(turns turn alpha beta)
(let ((v most-positive-fixnum)
(best-move -1))
(if (evaluate turns)
(return-from min-value (list (evaluate turns))))
(dolist (x (find-moves))
(setf (aref *board* (floor x 3) (mod x 3)) (if turn "X" "O"))
(setf v (min v (car (max-value (+ turns 1) (not turn) alpha beta))))
(setf (aref *board* (floor x 3) (mod x 3)) " ")
(if (<= v alpha) (return-from min-value '(v x)))
Ah, one of my favorite rants! It's not your fault. You have been sandbagged by introductory Lisp texts, which like to use the very convenient notation '(1 2) to avoid the more verbose (list 1 2), but neglect to make clear they are using the equivalent of (quote (1 2)), and the whole story of what quote does, namely take (let ((x 42)) '(x)) and return a list of the symbol x.
hth, kt
--
Well, I've wrestled with reality for 35 years, Doctor, and
I'm happy to state I finally won out over it.
-- Elwood P. Dowd
In this world, you must be oh so smart or oh so pleasant.
-- Elwood's Mom
.
- References:
- -2 is not a real number?!?
- From: cdombroski
- -2 is not a real number?!?
- Prev by Date: Re: sexp-aware theory of patches and "meta common lisp"
- Next by Date: A style question
- Previous by thread: Re: -2 is not a real number?!?
- Next by thread: Re: -2 is not a real number?!?
- Index(es):