Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Symbolic: code example

Author: Tord Romstad

Date: 08:52:47 01/22/04

Go up one level in this thread


Hi Steven!

On January 22, 2004 at 10:03:55, Steven Edwards wrote:

>Here's some example code for the ChessLisp intepreter in my program Symbolic:
>
>;;;; emp.lsp: Enumerate movepaths
>
>(defun emp (theFEN theDepth)
> "Enumerate distinct movepaths from a FEN string to a depth"
> (cond
>  ((not (string? theFEN))
>    "Error: first argument must be a FEN string")
>  ((not (and (integer? theDepth) (nonnegative? theDepth)))
>    "Error: second argument must be a nonnegative integer")
>  (t
>   (let ((thePos (PosFromFEN theFEN)))
>    (if (null? thePos)
>     "Error: invalid position"
>     (emp-aux thePos theDepth))))))
>
>(defun emp-aux (thePos theDepth)
> "Enumerate distinct movepaths from a position to a depth"
> (cond
>  ((= theDepth 0) 1)
>  ((= theDepth 1) (length (Generate thePos)))
>  (t
>   (let ((theSum 0) (theEnv nil) (theMove nil) (theML (Generate thePos)))
>    (dolist (theMove theML)
>     (Execute theMove thePos theEnv)
>     (incf theSum (emp-aux thePos (1- theDepth)))
>     (Retract theMove thePos theEnv))
>    theSum))))

From the code above, it looks like you generate moves into a list rather
than an array.  Isn't this terribly slow?  And another question:  What
is the purpose of the (theMove nil) in the LET bindings of the EMP-AUX
function?  Is this necessary because of some quirk in your Lisp dialect?

Otherwise, the code looks straighforward and clean.  I personally detest
the convention of using question marks to denote predicates, but that's
of course a matter of taste.

Tord



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.