Author: Steven Edwards
Date: 09:50:51 01/24/04
Here's the slightly revised movepath enumerator code example for 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) (nonminus? 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
((zero? theDepth) 1)
((= theDepth 1) (length (GenerateUnmarked thePos)))
(t
(let ((theSum 0) (theEnv nil) (theML (GenerateUnmarked thePos)))
(dolist (theMove theML)
(Execute theMove thePos theEnv)
(incf theSum (emp-aux thePos (1- theDepth)))
(Retract theMove thePos theEnv))
theSum))))
---------
It works. I don't have exact timings yet, but it runs almost as fast as the
pure C++ equivalent. Here's a copy of the interaction:
kristen:~/tmp sje$ ./x
Symbolic Interactive Command Processor
Copyright (C) 2004 by S. J. Edwards
Revision date 2004.01.24
: test
(load "emp.lsp")
emp-aux
(setf theFEN "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1")
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1"
(setf thePos (PosFromFEN theFEN))
#Pos <rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1>
(emp theFEN 0)
1
(emp theFEN 1)
20
(emp theFEN 2)
400
(emp theFEN 3)
8902
(emp theFEN 4)
197281
(emp theFEN 5)
4865609
(sysinfo)
Env: [Free: 28920 UsedAtom: 19819 UsedCons: 17555 Act: 3]
Act level: 0 Bindings: 245
Act level: 1 Bindings: 24
Act level: 2 Bindings: 4
nil
(gc)
nil
(sysinfo)
Env: [Free: 65860 UsedAtom: 319 UsedCons: 115 Act: 3]
Act level: 0 Bindings: 245
Act level: 1 Bindings: 24
Act level: 2 Bindings: 4
nil
(exit)
nil
: exit
kristen:~/tmp sje$
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.