Saturday, March 18, 2006

Nearly playable...



Managed to find some time for some more fiddling. I've made the board display a bit prettier and it detects mouse presses and updates it all. It's dog slow at the moment though - is actually unplayable unless I compile it. Guess it's time to learn about profiling and optimising in lisp.

A couple of useful macros came out of it:

  • with-board-geometry sets up an environment where a bunch of useful variables are defined - cell-width, total-width, total board area, etc. So the mouse click detection and board drawing code both use this.
  • do-all-cells iterates over all the cells in the board and evaluates the given form on them.
  • do-surrounding-cells iterates over all the cells surrounding a given cell
  • do-steps is a simple wrapper around do that increments a given variable by a certain amount for a given number of times. This is used when drawing the board.
So it is nice to have code that looks like this:


(do-all-cells (ix iy board)
(update-cell-visibility board ix iy))


(defun add-counts-for-mine (board mine-x mine-y)
"Increment the mine counts for all cells surrounding mine-x mine-y"
(let ((cells (board-cells board)))
(do-surrounding-cells (ix iy board mine-x mine-y)
(when (cell-mine-count (aref cells ix iy))
(incf (cell-mine-count (aref cells ix iy)))))))

0 Comments:

Post a Comment

<< Home