blob: d7fb79d8388d1c223a91577b588f3ff642ef834d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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)))))
|