This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Use of "reverse" Function in Lisp for minimax-alpha-beta

2 posts · 1252 views

I have a function that the minimax-alpha-beta performs, the fact is that it reads from left to right and I would like it to read backwards and I thought about the "reverse" function but I can not get it to work for me.

The code is the following:
(defun minimax-alpha-beta (nodo alpha beta)
     (cond
      ((hoja nodo)
       (let ((val (evalua nodo)))
         (format t "~A " val)
         val))
   ((nodo-min nodo)
    (let ((beta-tmp beta))
      (do ((ch (hijos nodo) (cdr ch)))
      ((or (null ch) (<= beta-tmp alpha)) beta-tmp)
    (let ((r (minimax-alpha-beta (car ch) alpha beta-tmp)))
      (if (< r beta-tmp) (setf beta-tmp r))))))
   ((nodo-max nodo)
    (let ((alpha-tmp alpha))
     (do ((ch (hijos nodo) (cdr ch)))
      ((or (null ch) (<= beta alpha-tmp)) alpha-tmp)
   (let ((r (minimax-alpha-beta (car ch) alpha-tmp beta)))
     (if (< alpha-tmp r) (setf alpha-tmp r))))))))

And I have an example tree implemented like this:
(defparameter *tree-001*
   '(max ((min ((max ((min (15 14))
          (min (13 12))))
        (max ((min (11 10))
          (min (9 8))))))
   (min ((max ((min (7 6))
          (min (5 4))))
        (max ((min (3 2))
          (min (1 0)))))))))

Where would I have to put the "reverse" so that I would do it the other way around?

Re: Use of "reverse" Function in Lisp for minimax-alpha-beta

I'm afraid that I'm struggling a little with following the logic here due to the missing DEFUNs and the Spanish(?) identifiers, but if I'm reading it correctly, you could call REVERSE on the result of HIJOS (which I assume means children?)