This is a library that I created to display traces of famous backtracking algorithms. I have included gif-eight-queens and gif-knights-tour as examples.
"make-chess-board" will create a new chess board. You can pass a custom set of chess pieces to it and you can modify the number of rows and 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" puts a chess piece on the chess board. You can pass it the name of the piece, x and y positions and the piece's color. The names are keywords and can be either :king, :queen, :pawn, :rook, :knight, :bishop, :cross or :dot. The names :cross and :dot name 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.
You will need to have skippy and xpm-to-gif to use 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)
This command will load the project.
(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"))) (move-rooks)
This function will create a 5 by 5 chess board with a rook moving toward white and another one moving along the back row. It will look like this:
See gif-knights-tour.lisp and gif-eight-queens.lisp for some more examples.
Date: 2007/06/28 08:11:11 PM