[Bese-devel] Backtracking help

William Halliburton whalliburton at gmail.com
Fri Aug 5 03:18:05 UTC 2005


Hello.

I am just beginning to use UCW. The following example does not
backtrack properly.
What would be the proper way to write this. 

Thank you.
William Halliburton


;;; tictactoe

(defun tictactoe-copy-state (state)
  (let ((array (make-array 9 :element-type 'fixnum)))
    (dotimes (x 9) (setf (aref array x) (aref state x)))
    array))

(defcomponent tictactoe (widget-component)
  ((state :backtrack #'tictactoe-copy-state
	  :initform (make-array 9 :element-type 'fixnum) :initarg :state)))

(defaction tictactoe-select ((tictactoe tictactoe) index)
  (with-slots (state) tictactoe
     (setf (aref state index) 1)))

(defmethod render-on ((res response) (tictactoe tictactoe))
  (with-slots (state) tictactoe
     (flet ((state-out (index)
       (let ((val (aref state index)))
	 (case val
	   (0 (<ucw:a :action (tictactoe-select tictactoe index) (<:as-is " ")))
	   (1 (<:as-is "X"))
	   (2 (<:as-is "O"))))))
       (<:pre 
	(dotimes (x 9) 
	  (state-out x)
	  (if (or (= x 2) (= x 5))
	      (progn
		(<:as-is #\Newline)
		(<:as-html "---------")
		(<:as-is #\Newline))
	    (if (= x 8) (<:as-is #\Newline)
	      (<:as-html " | "))))))))



More information about the bese-devel mailing list