;;; ---------------------------------------------------------------------- ;;; One idea to speed up my search (and thereby be able to extend the ;;; number of plies) is to precycle nodes. Precycling will allocate ;;; a bunch of nodes and reuse them instead of always creating "new" ;;; nodes. This will save time spent allocating and garbage collection. ;;; Paul McNamee, 5/95 (let ((*available-nodes* nil) (*used-nodes* nil)) (defun Get-Node (&key (first-players-turn? t) (old-board (node-board *initial-node*))) (unless *available-nodes* (loop repeat 1000 do (push (make-node :board (make-board)) *available-nodes*) )) (let ((node (pop *available-nodes*))) (setf (node-first-players-turn? node) first-players-turn?) ;; Destructively sets (node-board node) (copy-board-into-board old-board (node-board node)) node ; return node )) (defun Restore-Used-Nodes () (setf *available-nodes* (nconc *available-nodes* *used-nodes*)) (setf *used-nodes* nil) ) ) ;End of closure (defmacro With-Node-Precycling (&body forms) "Free up all the precycled nodes. Then excecute forms (which will use up some nodes). Example: (let (move) (With-Node-Precycling (setq move (alpha-beta-search *current-state* ...)) ) ; print board... )" `(progn (restore-used-nodes) (progn ,@forms)) )