From: ···········@gmail.com
Subject: Need help with Minimax Implementation
Date: 
Message-ID: <1130612706.947379.317860@o13g2000cwo.googlegroups.com>
I am trying to implement the minimax algorithm using two functions
"minimax" (when the root node is a min node) and "maximin" (root node
is a max node) which call one another.

The functions should work, however, there is something wrong with the
base case. It seems to not consider cdr L when car L is an atom
(because L is returned)

Can someone help me out with the base case? What will work?

(defun maximin(L)
	(cond ((car L)) L)
              (t (let ((x (maximin (car L)))
                       (y (minimax (cdr L))))
                   (cond ((>= x y) x)
                         (t y))))))

(defun minimax(L)
  (cond ((atom (car L)) L)
        (t (let ((x (minimax (car L)))
                 (y (maximin (cdr L))))
             (cond ((<= x y) x)
                   (t y))))))

Thanks,
Ryan
From: Pascal Bourguignon
Subject: Re: Need help with Minimax Implementation
Date: 
Message-ID: <874q70t8sw.fsf@thalassa.informatimago.com>
···········@gmail.com writes:

> I am trying to implement the minimax algorithm using two functions
> "minimax" (when the root node is a min node) and "maximin" (root node
> is a max node) which call one another.
>
> The functions should work, however, there is something wrong with the
> base case. It seems to not consider cdr L when car L is an atom
> (because L is returned)
>
> Can someone help me out with the base case? What will work?
>
> (defun maximin(L)
> 	(cond ((car L)) L)
>               (t (let ((x (maximin (car L)))
>                        (y (minimax (cdr L))))
>                    (cond ((>= x y) x)
>                          (t y))))))
>
> (defun minimax(L)
>   (cond ((atom (car L)) L)
>         (t (let ((x (minimax (car L)))
>                  (y (maximin (cdr L))))
>              (cond ((<= x y) x)
>                    (t y))))))

And you're implementing a minimax without using min or max?

(defun maximin (l)
  (if (car l)
      l
      (max (maximin (car l)) (minimax (cdr l)))))

(defun minimax(l)
  (if (atom (car l))
      l
      (min (minimax (car l)) (maximin (cdr l)))))

I'm not surprized that it returns L when (atom (car L)), this is
exactly what you wrote.  It may be more obvious when you remove your
obfuscation and use min and max.

Note that maximin is quite wrong: (maximin nil) is an infinite loop.

-- 
__Pascal_Bourguignon__               _  Software patents are endangering
()  ASCII ribbon against html email (o_ the computer industry all around
/\  1962:DO20I=1.100                //\ the world http://lpf.ai.mit.edu/
    2001:my($f)=`fortune`;          V_/   http://petition.eurolinux.org/