<commit_before>;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Package: CLIM-DEMO; Base: 10; Lowercase: Yes -*-

;; $fiHeader: puzzle.lisp,v 1.23 1993/07/27 01:46:05 colin Exp $

(in-package :clim-demo)

"Copyright (c) 1989, 1990, 1991, 1992 Symbolics, Inc.  All rights reserved."

(define-application-frame puzzle ()
    ((puzzle :initform (make-array '(4 4))
	     :accessor puzzle-puzzle))
  (:panes
    (display :application
	     :display-function 'draw-puzzle
	     :text-style (make-text-style :fix :bold :very-large)
	     :incremental-redisplay t
	     :text-cursor nil
	     :width :compute :height :compute
	     :end-of-page-action :allow
	     :end-of-line-action :allow))
  (:layouts
    (:default display)))

(defmethod frame-standard-input ((puzzle puzzle))
  (get-frame-pane puzzle 'display))

(defmethod frame-standard-output ((puzzle puzzle))
  (get-frame-pane puzzle 'display))

(defmethod run-frame-top-level :before ((puzzle puzzle) &key)
  (initialize-puzzle puzzle))

(defmethod read-frame-command ((puzzle puzzle) &key (stream *standard-input*))
  (let ((abort-chars #+genera '(#\Abort #\End)
		     #-genera nil))
    (let ((command (read-command-using-keystrokes
		     (frame-command-table puzzle) abort-chars
		     :stream stream)))
      (if (characterp command)
	  (frame-exit puzzle)
	  command))))

(define-presentation-type puzzle-cell ()
  :inherit-from '(integer 1 15))

(define-presentation-method highlight-presentation ((type puzzle-cell) record stream state)
  state
  (multiple-value-bind (xoff yoff)
      (climi::convert-from-relative-to-absolute-coordinates
       stream (output-record-parent record))
    (with-bounding-rectangle* (left top right bottom) record
      (draw-rectangle* stream
		       (+ left xoff) (+ top yoff)
		       (+ right xoff) (+ bottom yoff)
		       :ink +flipping-ink+))))

(defun encode-puzzle-cell (row column)
  (+ (* row 4) column))

(defun decode-puzzle-cell (encoding)
  (floor encoding 4))

(defmethod initialize-puzzle ((puzzle puzzle))
  (let ((puzzle-array (puzzle-puzzle puzzle)))
    (dotimes (row 4)
      (dotimes (column 4)
	(setf (aref puzzle-array row column) (mod (1+ (encode-puzzle-cell row column)) 16))))))

(defmethod draw-puzzle ((puzzle puzzle) stream &key max-width max-height)
  (declare (ignore max-width max-height))
  (let ((puzzle-array (puzzle-puzzle puzzle)))
    (formatting-table (stream)
      (dotimes (row 4)
	(formatting-row (stream)
	  (dotimes (column 4)
	    (let* ((value (aref puzzle-array row column))
		   (cell-id (encode-puzzle-cell row column)))
	      (updating-output (stream :unique-id cell-id 
				       :cache-value value)
		(formatting-cell (stream :align-x :right)
		  (unless (zerop value)
		    (with-output-as-presentation 
			(stream cell-id 'puzzle-cell)
		      (format stream "~2D" value))))))))))))

(defun find-open-cell (puzzle)
  (dotimes (row 4)
    (dotimes (column 4)
      (when (zerop (aref puzzle row column))
	(return (encode-puzzle-cell row column))))))

(defun cell-adjacent-to-open-cell (puzzle r c)<commit_msg>Examples/puzzle: no longer uses non exported symbols<commit_after>;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Package: CLIM-DEMO; Base: 10; Lowercase: Yes -*-

;; $fiHeader: puzzle.lisp,v 1.23 1993/07/27 01:46:05 colin Exp $

(in-package :clim-demo)

"Copyright (c) 1989, 1990, 1991, 1992 Symbolics, Inc.  All rights reserved."

(define-application-frame puzzle ()
    ((puzzle :initform (make-array '(4 4))
	     :accessor puzzle-puzzle))
  (:panes
    (display :application
	     :display-function 'draw-puzzle
	     :text-style (make-text-style :fix :bold :very-large)
	     :incremental-redisplay t
	     :text-cursor nil
	     :width :compute :height :compute
	     :end-of-page-action :allow
	     :end-of-line-action :allow))
  (:layouts
    (:default display)))

(defmethod frame-standard-input ((puzzle puzzle))
  (get-frame-pane puzzle 'display))

(defmethod frame-standard-output ((puzzle puzzle))
  (get-frame-pane puzzle 'display))

(defmethod run-frame-top-level :before ((puzzle puzzle) &key)
  (initialize-puzzle puzzle))

(defmethod read-frame-command ((puzzle puzzle) &key (stream *standard-input*))
  (let ((abort-chars #+genera '(#\Abort #\End)
		     #-genera nil))
    (let ((command (read-command-using-keystrokes
		     (frame-command-table puzzle) abort-chars
		     :stream stream)))
      (if (characterp command)
	  (frame-exit puzzle)
	  command))))

(define-presentation-type puzzle-cell ()
  :inherit-from '(integer 1 15))

(define-presentation-method highlight-presentation ((type puzzle-cell) record stream state)
  (with-bounding-rectangle* (left top right bottom) record
    (draw-rectangle* stream
		     left top right bottom
		     :ink +flipping-ink+)))

(defun encode-puzzle-cell (row column)
  (+ (* row 4) column))

(defun decode-puzzle-cell (encoding)
  (floor encoding 4))

(defmethod initialize-puzzle ((puzzle puzzle))
  (let ((puzzle-array (puzzle-puzzle puzzle)))
    (dotimes (row 4)
      (dotimes (column 4)
	(setf (aref puzzle-array row column) (mod (1+ (encode-puzzle-cell row column)) 16))))))

(defmethod draw-puzzle ((puzzle puzzle) stream &key max-width max-height)
  (declare (ignore max-width max-height))
  (let ((puzzle-array (puzzle-puzzle puzzle)))
    (formatting-table (stream)
      (dotimes (row 4)
	(formatting-row (stream)
	  (dotimes (column 4)
	    (let* ((value (aref puzzle-array row column))
		   (cell-id (encode-puzzle-cell row column)))
	      (updating-output (stream :unique-id cell-id 
				       :cache-value value)
		(formatting-cell (stream :align-x :right)
		  (unless (zerop value)
		    (with-output-as-presentation
			(stream cell-id 'puzzle-cell)
		      (format stream "~2D" value))))))))))))

(defun find-open-cell (puzzle)
  (dotimes (row 4)
    (dotimes (column 4)
      (when (zerop (aref puzzle row column))
	(return (encode-puzzle-cell row column))))))

(defun cell-adjacent-to-open-cell (puzzle r c)
{'fraction_non_alphanumeric': 0.1522322927156764, 'fraction_numerical': 0.01745552198724404, 'mean_word_length': 3.4939668174962293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5589437', 'n_tokens_mistral': 2235, 'n_tokens_neox': 1992, 'n_words': 539}