summaryrefslogtreecommitdiff
path: root/lisp/ouat/scrabble-debug.lisp
diff options
context:
space:
mode:
authorJason Katz-Brown <jason@airbnb.com>2013-08-25 02:17:13 -0700
committerJason Katz-Brown <jason@airbnb.com>2013-08-25 02:17:13 -0700
commit9306cb60c32082c5403931de0823a9fd5daa196c (patch)
treeca1b6eb695fdf3f0c2294e92416b272164bae642 /lisp/ouat/scrabble-debug.lisp
parent8fb2c681cecc01b46b0f4ba02d5cc177c4747b1c (diff)
Initial git commit.
Diffstat (limited to 'lisp/ouat/scrabble-debug.lisp')
-rw-r--r--lisp/ouat/scrabble-debug.lisp55
1 files changed, 55 insertions, 0 deletions
diff --git a/lisp/ouat/scrabble-debug.lisp b/lisp/ouat/scrabble-debug.lisp
new file mode 100644
index 0000000..d7fb79d
--- /dev/null
+++ b/lisp/ouat/scrabble-debug.lisp
@@ -0,0 +1,55 @@
+(in-package :ouat)
+
+;; generalize this and make *english* default
+(defun print-board (board &optional (str t))
+ (let* ((squares (board-pretty-squares board *english*
+ *standard-letter-mul-texts*
+ *standard-word-mul-texts*))
+ (layout (board-layout board)))
+ (labels ((horizontal-border ()
+ (format str " ")
+ (dotimes (i (i1- (i* 2 (layout-width layout))))
+ (format str "-"))
+ (format str "~%")))
+ (format str " ")
+ (loop
+ for col below (layout-width layout)
+ for label = (code-char (i+ (char-code #\A) col))
+ do (format str "~a " label))
+ (format str "~%")
+ (horizontal-border)
+ (loop
+ for row below (layout-height layout)
+ for row-squares in squares
+ for pretty-row = (i1+ row)
+ do
+ (if (i> 10 pretty-row)
+ (format str " ~a|" pretty-row)
+ (format str "~a|" pretty-row))
+ (loop
+ for (square . rest) on row-squares
+ do
+ (format str "~a" square)
+ (if rest
+ (format str " ")
+ (format str "|~%"))))
+ (horizontal-border))))
+
+;; only supports single character per tile
+;; assumes that string-upcase is a reasonable thing to do
+(defun new-rack (string &key (capacity 7) (tiles *english*))
+ (let* ((tile-array (make-array (list capacity)
+ :element-type 'fixnum
+ :initial-element +empty+))
+ (size 0))
+ (loop
+ for text-char across (string-upcase string)
+ for text = (format nil "~a" text-char)
+ for tile = (text-tile text tiles)
+ do (if tile
+ (progn
+ (setf (aref tile-array size) tile)
+ (iincf size))
+ (format t "Unknown tile: ~a~%" text)))
+ (make-rack :capacity capacity
+ :tiles (adjust-array tile-array `(,size))))) \ No newline at end of file