;;; -*- Mode: Lisp; Syntax: Common-Lisp; -*- File: search/domains/cognac.lisp ;;;; The Game of Cognac ;;; Definitions for a game of uncertain origin reputed to be played by ;;; bored cognac-tenders in the cellars. Similar to Tic-Tac-Toe but ;;; instead of playing anywhere, one can only play directly above an ;;; existing mark or on the bottom row. ;;;; Top Level Game-Creating Function (defun cognac-game (&key (m 3) (n m) (k m) (players '(X O))) "Define an MxN Cognac game in which the object is to get K in a row." (make-game :initial-state (make-game-state :board (make-array (list m n) :initial-element '-) :players players) :legal-move-fn #'cognac-legal-moves :make-move-fn #'ttt-make-move :terminal-test #'(lambda (state) (ttt-terminal-test state m n k)) :domain "Cognac")) ;;;; Successor Function (defun cognac-legal-moves (state) "Generate all possible (move . new-state) pairs." (let ((board (game-state-board state))) ;; For each column (x position), the one (at most) possible move ;; is the lowest empty y position. (with-collection () (dotimes (x (array-dimension board 0)) (dotimes (y (array-dimension board 1)) (when (eq (aref board x y) '-) (collect (@ x y)) (return) ; out of y loop ))))))