1
; AisleRiot - bakers_dozen.scm
2
; Copyright (C) 2001, 2003 Rosanna Yuen <zana@webwynk.net>
4
; This program is free software: you can redistribute it and/or modify
5
; it under the terms of the GNU General Public License as published by
6
; the Free Software Foundation, either version 3 of the License, or
7
; (at your option) any later version.
9
; This program is distributed in the hope that it will be useful,
10
; but WITHOUT ANY WARRANTY; without even the implied warranty of
11
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
; GNU General Public License for more details.
14
; You should have received a copy of the GNU General Public License
15
; along with this program. If not, see <http://www.gnu.org/licenses/>.
18
(initialize-playing-area)
27
(add-normal-slot DECK)
35
(add-carriage-return-slot)
37
(add-extended-slot '() down)
38
(add-extended-slot '() down)
39
(add-extended-slot '() down)
40
(add-extended-slot '() down)
41
(add-extended-slot '() down)
42
(add-extended-slot '() down)
43
(add-extended-slot '() down)
44
(add-extended-slot '() down)
45
(add-extended-slot '() down)
46
(add-extended-slot '() down)
47
(add-extended-slot '() down)
48
(add-extended-slot '() down)
49
(add-extended-slot '() down)
51
(deal-cards-face-up 0 '(4 5 6 7 8 9 10 11 12 13 14 15 16 4 5 6 7 8 9
52
10 11 12 13 14 15 16))
55
(deal-cards-face-up 0 '(4 5 6 7 8 9 10 11 12 13 14 15 16))
58
(deal-cards-face-up 0 '(4 5 6 7 8 9 10 11 12 13 14 15 16))
63
(define (move-kings-back slot-id)
65
(begin (and (= (get-value (get-top-card slot-id)) king)
66
(set-cards! slot-id (append (cdr (get-cards slot-id))
67
(list (get-top-card slot-id)))))
68
(move-kings-back (+ 1 slot-id)))
71
(define (button-pressed slot-id card-list)
72
(and (not (empty-slot? slot-id))
73
(= (length card-list) 1)))
75
(define (droppable? start-slot card-list end-slot)
76
(cond ((= start-slot end-slot)
79
(cond ((and (= (get-value (car card-list))
81
(empty-slot? end-slot))
83
((and (not (empty-slot? end-slot))
84
(= (get-suit (get-top-card end-slot))
85
(get-suit (car card-list)))
86
(= (+ 1 (get-value (get-top-card end-slot)))
87
(get-value (car card-list))))
90
((and (not (empty-slot? end-slot))
91
(= (get-value (get-top-card end-slot))
92
(+ 1 (get-value (car card-list)))))
96
(define (button-released start-slot card-list end-slot)
97
(and (droppable? start-slot card-list end-slot)
98
(move-n-cards! start-slot end-slot card-list)
104
(define (button-clicked slot-id)
107
(define (find-empty-foundation a-slot f-slot)
110
((empty-slot? f-slot)
111
(deal-cards a-slot (list f-slot)))
112
(#t (find-empty-foundation a-slot (+ 1 f-slot)))))
114
(define (find-foundation a-slot f-slot)
117
((and (not (empty-slot? f-slot))
118
(= (get-suit (get-top-card a-slot))
119
(get-suit (get-top-card f-slot)))
120
(= (get-value (get-top-card a-slot))
121
(+ 1 (get-value (get-top-card f-slot)))))
122
(and (deal-cards a-slot (list f-slot))
124
(#t (find-foundation a-slot (+ 1 f-slot)))))
127
(define (button-double-clicked slot-id)
129
(not (empty-slot? slot-id))
130
(or (and (= (get-value (get-top-card slot-id))
132
(find-empty-foundation slot-id 0)
134
(find-foundation slot-id 0))))
137
(define (game-continuable)
138
(and (not (game-won))
142
(and (= (length (get-cards 0)) 13)
143
(= (length (get-cards 1)) 13)
144
(= (length (get-cards 2)) 13)
145
(= (length (get-cards 3)) 13)))
147
(define (foundation-possible? t-slot f-slot)
151
(empty-slot? t-slot))
152
(foundation-possible? (+ 1 t-slot) 0))
153
((= (get-value (get-top-card t-slot)) ace)
154
(list 2 (get-name (get-top-card t-slot)) (_"an empty foundation")))
155
((and (not (empty-slot? f-slot))
156
(= (get-suit (get-top-card t-slot))
157
(get-suit (get-top-card f-slot)))
158
(= (get-value (get-top-card t-slot))
159
(+ 1 (get-value (get-top-card f-slot)))))
161
(get-name (get-top-card t-slot))
162
(get-name (get-top-card f-slot))))
163
(#t (foundation-possible? t-slot (+ 1 f-slot)))))
165
(define (card-to-foundation-possible? card f-slot)
168
((and (not (empty-slot? f-slot))
170
(get-suit (get-top-card f-slot))))
172
(+ 1 (get-value (get-top-card f-slot)))))
173
(#t (card-to-foundation-possible? card (+ 1 f-slot)))))
175
(define (tableau-moves? slot1 slot2)
180
(tableau-moves? (+ 1 slot1) 4))
181
((and (not (= slot1 slot2))
182
(not (empty-slot? slot2))
183
(> (length (get-cards slot1)) 1)
184
(= (+ 1 (get-value (get-top-card slot1)))
185
(get-value (get-top-card slot2)))
186
(or (not (= (get-value (get-top-card slot2))
187
(get-value (cadr (get-cards slot1)))))
188
(card-to-foundation-possible? (cadr (get-cards slot1)) 0)))
189
(list 1 (get-name (get-top-card slot1)) (get-name (get-top-card slot2))))
190
(#t (tableau-moves? slot1 (+ 1 slot2)))))
193
(or (foundation-possible? 4 0)
195
(list 0 (_"Try rearranging the cards"))))
197
(define (get-options)
200
(define (apply-options options)
206
(set-features droppable-feature)
208
(set-lambda new-game button-pressed button-released button-clicked
209
button-double-clicked game-continuable game-won get-hint get-options
210
apply-options timeout droppable?)