;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; CS 327: Othello ; Support library written by Dave Musicant ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Function: initialize-board ; ; Parameters: size of board. For a standard Othello board, size should ; always be 8. You might want to make it smaller early on so that ; you can test code more easily. ; ; Return value: Lisp 2-D array containing all zeros, except for the ; center starting positions. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun initialize-board (size) (let ((board (make-array (list (+ size 2) (+ size 2)) :initial-element 0)) (center (1+ (/ size 2)))) (if (not (= center (round center))) nil (progn (setf (aref board center center) -1) (setf (aref board (1- center) (1- center)) -1) (setf (aref board (1- center) center) 1) (setf (aref board center (1- center)) 1) board)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Function: print-board ; Prints out a human readable version of an Othello board ; ; Parameters: Lisp 2-D array containing board position. ; ; Return value: nil ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun print-board (board) (let ((size (array-dimension board 0))) (dotimes (i (- size 2) nil) (dotimes (j (- size 2) nil) (cond ((equal (aref board (1+ i) (1+ j)) 1) (format t "B ")) ((equal (aref board (1+ i) (1+ j)) -1) (format t "W ")) (t (format t ". ")))) (format t "~%"))))