#+TITLE: Chess Trace

*Chess Trace

This is a library that I created to display traces of famous
backtracking algorithms. I have include gif-eight-queens and
gif-knights-tour as examples.

http://www.jeremyenglish.org/packs/chess-trace.tgz

** Functions

make-chess-board will create a new chess board. You can pass a custom
set of chess pieces to it and the number of row or columns. The chess
board is always square.

start-frame will add a new working frame to the animation.

end-frame will close the current frame and add it to the animation.

add-frame-delay will let you add a custom delay to any frame.

output-board writes the animation to a gif file.

blocks returns the number of blocks in a row or column.

put-piece-xy put a chess piece on the chess board. You can pass it the
name of the piece, x and y positions and the pieces color. The names or
keyword and can be
either :king :queen :pawn :rook :knight :bishop :cross or :dot. The
names :cross and :dot names of the extra symbols used to mark off a
block. For an NxN chess board (0,0) will be the top left block and
(n,n) will be on the bottom right.


** Usage

You will need to have [[http:www.xach.com/lisp/skippy/][skippy]] and [[http://www.jeremyenglish.org/xpm-to-gif.html][xpm-to-gif]] to uses the library. Once
you have those packages, put a link to chess-trace.asd somewhere asdf
can find it.

(asdf:oos 'asdf:load-op 'chess-trace)

Will load the project.

@<img src="http://www.jeremyenglish.org/pixs/rooks.gif" />
(use-package :chess-trace)

(defun move-rooks ()
  (let ((cb (make-chess-board :blocks 5)))
    (dotimes (n (blocks cb))
      (start-frame cb)
      (when (> n 0)
        (dotimes (m n)
              (put-piece-xy cb :name :dot :x 0 :y m)
              (put-piece-xy cb :name :dot :x m :y 0)))
      (put-piece-xy cb :name :rook :x 0 :y n :color :black)
      (put-piece-xy cb :name :rook :x n :y 0 :color :black)
      (end-frame cb :delay-time 20))
    (add-frame-delay 300 cb)
    (output-board cb #p"rooks.gif")))

Will create a 5 by 5 chess board with a rook moving towards white and
one moving along the back row.


See gif-knights-tour.lisp and gif-eight-queens.lisp for some more
examples.


Jeremy English 28-June-2007
