I'm currently learning Common Lisp and, as part of the process, am trying to implement a generic tic-tac-toe game where the board can be any odd numbered size (so there's a center square). I got to where I'm checking for winners and am working on this function to check if a row or column have a winner.
(defun straight-winner-p (board start size)
(let ((row-player (aref board start 0))
(row-count 0)
(col-player (aref board 0 start))
(col-count 0))
(loop for step from 0 to (- size 1) do
(if (equal
(aref board start step)
row-player)
(incf row-count))
(if (equal
(aref board step start)
col-player)
(incf col-count))
)
(format t "row ~a, col ~a~%" row-count col-count)))
The format call would eventually be replaced with a check if the player is nil and count equals size. Anyway, I wanted to replace the two ifs with a macro. So, it would be something like
(check row start step)
And the macro would generate the if statement
(if (equal
(aref board start step)
row-player)
(incf row-count))
Then call the same macro with (check col step start). I can't seem to get the macro to generate row-count and row-player from row. How would you do that?
do
? I added one in my indented version. – Spenser Truex