(defun make-unit ()
(make-instance 'unit :cells (make-list 0)))
-(defun set-parents-of-cell (unit)
+;;; Given a unit, make sure this unit is the
+;;; parent of all its cells.
+(defun add-parent-to-cells-of-unit (unit)
(loop for cell in (cells unit)
do (push unit (parents cell))))
(defun make-cell (board-width)
(make-instance 'cell
- :parents (make-list 0)
- :possibilities (make-array board-width :element-type 'bit :initial-element 1)))
+ :parents '()
+ :possibilities (make-array board-width
+ :element-type 'bit
+ :initial-element 1)))
(defun erase-possibilities (cell)
(loop for i from 0 below (length (possibilities cell))
(defun set-possibilities (cell index value)
(setf (aref (possibilities cell) index) value))
+;;; return a true value if and only if there is more than one
+;;; possible value for the cell.
(defun check-hole (cell)
- (when (/= (symbolset-cardinality (possibilities cell)) 1)
- (return-from check-hole t))
- nil)
+ (/= (symbolset-cardinality (possibilities cell)) 1)
(defun find-possibilities (cell)
(let* ((leng (length (possibilities cell)))
(make-instance 'game
:symbols (make-array board-width)
:cells (make-array (list board-width board-width))
- :units (make-list 0)))
+ :units '()))
(defun create-mapping-vector (board-width)
(let ((v (make-array board-width)))
do (let ((unit (make-unit)))
(copy-rectangle-to-unit game row 1 0 board-width unit)
(push unit (units game))
- (set-parents-of-cell unit)))
+ (add-parent-to-cells-of-unit unit)))
;; Create unit instances corresponding to columns
(loop for col from 0 below board-width
do (let ((unit (make-unit)))
(copy-rectangle-to-unit game 0 board-width col 1 unit)
(push unit (units game))
- (set-parents-of-cell unit)))
+ (add-parent-to-cells-of-unit unit)))
;; Create unit instances corresponding to small squares
(loop for row from 0 below board-width by sqrt-board-width
do (loop for col from 0 below board-width by sqrt-board-width
do (let ((unit (make-unit)))
(copy-rectangle-to-unit game row sqrt-board-width col sqrt-board-width unit)
(push unit (units game))
- (set-parents-of-cell unit))))
+ (add-parent-to-cells-of-unit unit))))
(return-from create-game game)))
(defun copy-game (game)