(defvar table) (defun tic-tac-toe () (setf table '((0 1 2) (3 4 5) (6 7 8))) (let ((n nil)) (format t "~a~%" "welcome to tic-tac-toe!") (do () (nil) (setq n (read)) (cond ((eq n 'quit) (return-from tic-tac-toe)) (t (tic-insert n table 'X) (tic-my-play table) (tic-print table)))))) (defun tic-print (table) (dolist (n table) (dolist (m n) (format t "~a " m)) (format t "~%"))) (defun tic-insert (n table sym) (multiple-value-bind (line pos) (floor (/ n 3)) (setq pos (* 3 pos)) (setf (nth pos (nth line table)) sym))) (defun tic-my-play (table) (let ((space nil)) (dolist (sub table) (dolist (i sub) (if (numberp i) (push i space)))) (let ((place (nth (random (length space)) space))) (tic-insert place table '-))))