1
; AisleRiot - lady_jane.scm
2
; Copyright (C) 1999, 2003 Rosanna Yuen <rwsy@mit.edu>
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/>.
17
(use-modules (aisleriot interface) (aisleriot api))
22
(initialize-playing-area)
27
(add-normal-slot DECK)
37
(add-carriage-return-slot)
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)
50
(set! VERTPOS (+ VERTPOS 0.5))
51
(set! HORIZPOS (+ HORIZPOS 7))
53
(add-carriage-return-slot)
54
(set! HORIZPOS (+ HORIZPOS 7))
56
(add-carriage-return-slot)
57
(set! HORIZPOS (+ HORIZPOS 7))
59
(add-carriage-return-slot)
60
(set! HORIZPOS (+ HORIZPOS 7))
66
(set! HORIZPOS (+ HORIZPOS 7))
69
(add-carriage-return-slot)
70
(set! HORIZPOS (+ HORIZPOS 7))
73
(add-carriage-return-slot)
74
(set! HORIZPOS (+ HORIZPOS 7))
77
(add-carriage-return-slot)
78
(set! HORIZPOS (+ HORIZPOS 7))
82
(deal-cards 0 '(7 8 9 10 11 12 8 9 10 11 12 9 10 11 12 10 11 12
84
(deal-cards-face-up 0 '(6 7 8 9 10 11 12 13 14 15 16 17 18 19 2))
88
(set! BASE-VAL (get-value (get-top-card 2)))
95
(define (give-status-message)
96
(set-statusbar-message (string-append (get-stock-no-string)
100
(define (get-base-string)
101
(cond ((and (> BASE-VAL 1)
103
(string-append (_"Base Card:") " " (number->string BASE-VAL)))
107
(_"Base Card: Jack"))
109
(_"Base Card: Queen"))
111
(_"Base Card: King"))
114
(define (get-stock-no-string)
115
(if (> (length (get-cards 0)) 1)
116
(string-append (_"Stock left:") " "
117
(number->string (length (get-cards 0))))
118
(string-append (_"Stock left: 0"))))
120
(define (button-pressed slot-id card-list)
121
(and (not (empty-slot? slot-id))
122
(is-visible? (car (reverse card-list)))))
124
(define (to-foundation? card end-slot)
125
(if (empty-slot? end-slot)
126
(= (get-value card) BASE-VAL)
127
(and (eq? (get-suit card)
128
(get-suit (get-top-card end-slot)))
129
(or (= (+ 1 (get-value (get-top-card end-slot)))
131
(and (= (get-value (get-top-card end-slot)) king)
132
(= (get-value card) ace))))))
134
(define (to-tableau? card end-slot)
135
(if (empty-slot? end-slot)
136
(or (= (get-value card) (- BASE-VAL 1))
137
(and (= BASE-VAL ace)
138
(= (get-value card) king)))
139
(and (not (eq? (is-red? card)
140
(is-red? (get-top-card end-slot))))
141
(not (= (get-value (get-top-card end-slot)) BASE-VAL))
142
(or (= (get-value (get-top-card end-slot))
143
(+ 1 (get-value card)))
144
(and (= (get-value (get-top-card end-slot)) ace)
145
(= (get-value card) king))))))
147
(define (droppable? start-slot card-list end-slot)
148
(if (not (= start-slot end-slot))
149
(cond ((and (> end-slot 1)
151
(and (= (length card-list) 1)
152
(to-foundation? (car card-list) end-slot)))
155
(and (to-tableau? (car (reverse card-list)) end-slot)))
159
(define (button-released start-slot card-list end-slot)
160
(if (droppable? start-slot card-list end-slot)
161
(cond ((and (> end-slot 1)
163
(and (or (and (> start-slot 5)
165
(not (empty-slot? start-slot))
166
(make-visible-top-card start-slot))
167
(and (> start-slot 1)
172
(move-n-cards! start-slot end-slot card-list)))
175
(and (or (and (> start-slot 1)
178
(and (> start-slot 5)
180
(not (empty-slot? start-slot))
181
(make-visible-top-card start-slot))
183
(move-n-cards! start-slot end-slot card-list)))
187
(define (button-clicked slot-id)
189
(cond ((> (length (get-cards slot-id)) 7)
190
(and (deal-cards-face-up 0 '(13 14 15 16 17 18 19))
191
(give-status-message)))
192
((> (length (get-cards slot-id)) 1)
193
(and (deal-cards-face-up 0 '(1))
194
(make-visible-top-card 0)
195
(give-status-message)))
199
(define (move-to-foundations? card slot-id)
202
((to-foundation? card slot-id)
203
(add-card! slot-id card))
205
(move-to-foundations? card (+ 1 slot-id)))))
207
(define (button-double-clicked slot-id)
208
(if (or (empty-slot? slot-id)
211
(not (is-visible? (get-top-card slot-id))))
213
(and (move-to-foundations? (get-top-card slot-id) 2)
214
(remove-card slot-id)
216
(or (empty-slot? slot-id)
219
(make-visible-top-card slot-id)))))
221
(define (game-continuable)
222
(and (not (game-won))
226
(and (= (length (get-cards 2)) 13)
227
(= (length (get-cards 3)) 13)
228
(= (length (get-cards 4)) 13)
229
(= (length (get-cards 5)) 13)))
232
(and (> (length (get-cards 0)) 1)
233
(list 0 (_"Deal another round"))))
235
(define (check-a-foundation slot1 slot2)
237
(or (to-foundation? (get-top-card slot1) slot2)
238
(check-a-foundation slot1 (+ 1 slot2)))
241
(define (check-to-foundations slot-id)
242
(cond ((> slot-id 19)
245
(check-to-foundations 6))
246
((or (empty-slot? slot-id)
247
(not (is-visible? (get-top-card slot-id))))
248
(check-to-foundations (+ 1 slot-id)))
249
((check-a-foundation slot-id 2)
250
(or (and (= (get-value (get-top-card slot-id)) BASE-VAL)
252
(get-name (get-top-card slot-id))
253
(_"an empty foundation pile")))
255
(get-name (get-top-card slot-id))
257
(make-card (if (= ace
258
(get-value (get-top-card slot-id)))
260
(- (get-value (get-top-card slot-id))
262
(get-suit (get-top-card slot-id)))))))
264
(check-to-foundations (+ 1 slot-id)))))
266
(define (check-a-foundation2 card slot2)
268
(or (to-foundation? card slot2)
269
(check-a-foundation2 card (+ 1 slot2)))
272
(define (stripped card-list card)
273
(if (<= (length card-list) 1)
275
(if (eq? card (car card-list))
277
(if (= (length card-list) 2)
279
(stripped (cdr card-list) card)))))
281
(define (check-a-tableau-with-pile card slot1 card-list slot2 imbedded?)
282
(cond ((or (= (length card-list) 0)
283
(not (is-visible? (car card-list))))
285
((and (not (eq? (is-red? (car card-list))
287
(or (= (+ 1 (get-value (car card-list)))
289
(and (= (get-value (car card-list))
293
(if (or (= (length card-list) 1)
294
(eq? (is-red? (car card-list))
295
(is-red? (cadr card-list)))
297
(not (and (is-visible? (cadr card-list))
298
(or (= (+ 1 (get-value (car card-list)))
299
(get-value (cadr card-list)))
300
(and (= (get-value (car card-list))
302
(= (get-value (cadr card-list))
304
(check-a-foundation2 (cadr card-list) 2)
305
(check-a-tableau-with-pile (get-top-card slot2)
310
(check-a-tableau-with-pile (cadr card-list)
315
(check-a-tableau-with-pile (cadr card-list)
317
(stripped (get-cards slot2)
321
(list 1 (get-name (car card-list)) (get-name card))
323
(check-a-tableau-with-pile card
329
(#t (check-a-tableau-with-pile card slot1 (cdr card-list) slot2 imbedded?))))
331
(define (check-a-tableau r-slot t-slot)
332
(if (and (eq? (is-red? (get-top-card r-slot))
333
(is-black? (get-top-card t-slot)))
334
(or (= (+ 1 (get-value (get-top-card r-slot)))
335
(get-value (get-top-card t-slot)))
336
(and (= (get-value (get-top-card r-slot))
338
(= (get-value (get-top-card t-slot))
341
(get-name (get-top-card r-slot))
342
(get-name (get-top-card t-slot)))
345
(define (check-to-tableau? slot1 slot2)
349
(check-to-tableau? 6 7))
352
(not (is-visible? (get-top-card slot1))))
353
(check-to-tableau? (+ 1 slot1) 6))
354
((and (not (= slot1 slot2))
357
(check-a-tableau-with-pile (get-top-card slot1)
362
(check-a-tableau-with-pile (get-top-card slot1)
367
((and (not (= slot1 slot2))
368
(not (empty-slot? slot2))
371
(check-a-tableau slot1 slot2))
372
(check-a-tableau slot1 slot2))
373
(#t (check-to-tableau? slot1 (+ 1 slot2)))))
375
(define (get-top-visible-card card-list)
376
(if (not (is-visible? (cadr card-list)))
378
(get-top-visible-card (cdr card-list))))
380
(define (find-high-value slot)
385
((and (not (empty-slot? slot))
386
(is-visible? (get-top-card slot))
389
(not (is-visible? (car (reverse (get-cards slot)))))
390
(or (= (get-value (get-top-visible-card (get-cards slot)))
392
(and (= (get-value (get-top-visible-card (get-cards slot)))
396
(get-name (get-top-visible-card (get-cards slot)))
397
(_"an empty tableau slot")))
398
((and (not (empty-slot? slot))
401
(is-visible? (get-top-card slot))
402
(or (= (get-value (get-top-card slot))
404
(and (= (get-value (get-top-card slot))
408
(get-name (get-top-card slot))
409
(_"an empty tableau slot")))
410
(#t (find-high-value (+ 1 slot)))))
412
(define (empty-tableau?)
413
(if (or (empty-slot? 6)
424
(or (check-to-foundations 0)
425
(check-to-tableau? 0 6)
428
(list 0 (_"Try rearranging the cards"))))
430
(define (get-options)
433
(define (apply-options options)
439
(set-features droppable-feature)
441
(set-lambda new-game button-pressed button-released button-clicked
442
button-double-clicked game-continuable game-won get-hint get-options
443
apply-options timeout droppable?)