1
; AisleRiot - union_square.scm
2
; Copyright (C) 1999 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/>.
18
(initialize-playing-area)
20
(make-standard-double-deck)
23
(add-normal-slot DECK)
28
(add-partially-extended-slot '() right 2)
29
(add-partially-extended-slot '() right 2)
30
(add-partially-extended-slot '() right 2)
31
(add-partially-extended-slot '() right 2)
35
(add-partially-extended-slot '() right 2)
37
(add-carriage-return-slot)
42
(add-partially-extended-slot '() right 2)
43
(add-partially-extended-slot '() right 2)
44
(add-partially-extended-slot '() right 2)
45
(add-partially-extended-slot '() right 2)
49
(add-partially-extended-slot '() right 2)
51
(add-carriage-return-slot)
56
(add-partially-extended-slot '() right 2)
57
(add-partially-extended-slot '() right 2)
58
(add-partially-extended-slot '() right 2)
59
(add-partially-extended-slot '() right 2)
63
(add-partially-extended-slot '() right 2)
64
(add-carriage-return-slot)
69
(add-partially-extended-slot '() right 2)
70
(add-partially-extended-slot '() right 2)
71
(add-partially-extended-slot '() right 2)
72
(add-partially-extended-slot '() right 2)
76
(add-partially-extended-slot '() right 2)
78
(deal-cards-face-up 0 '(2 3 4 5 7 8 9 10 12 13 14 15 17 18 19 20))
85
(define (give-status-message)
86
(set-statusbar-message (get-stock-no-string)))
88
(define (get-stock-no-string)
89
(string-append (_"Stock left:") " "
90
(number->string (length (get-cards 0)))))
93
(define (button-pressed slot-id card-list)
94
(and (not (empty-slot? slot-id))
95
(is-visible? (car card-list))
96
(= (length card-list) 1)
97
(not (or (= slot-id 6)
102
(define (to-foundation? card-list end-slot)
103
(if (empty-slot? end-slot)
104
(and (eq? (get-value (car card-list)) ace)
107
(not (eq? (get-suit (get-top-card 6))
108
(get-suit (car card-list)))))
111
(not (eq? (get-suit (get-top-card 11))
112
(get-suit (car card-list)))))
115
(not (eq? (get-suit (get-top-card 16))
116
(get-suit (car card-list)))))
119
(not (eq? (get-suit (get-top-card 21))
120
(get-suit (car card-list))))))
121
(if (eq? (get-suit (get-top-card end-slot))
122
(get-suit (car card-list)))
123
(cond ((< (length (get-cards end-slot)) 13)
124
(= (+ 1 (get-value (get-top-card end-slot)))
125
(get-value (car card-list))))
126
((= (length (get-cards end-slot)) 13)
127
(= (get-value (car card-list)) 13))
129
(= (get-value (get-top-card end-slot))
130
(+ 1 (get-value (car card-list))))))
133
(define (to-tableau? card-list end-slot)
134
(if (empty-slot? end-slot)
136
(if (eq? (get-suit (get-top-card end-slot))
137
(get-suit (car card-list)))
138
(cond ((= (length (get-cards end-slot)) 1)
139
(or (= (get-value (car card-list))
140
(+ 1 (get-value (get-top-card end-slot))))
141
(= (+ 1 (get-value (car card-list)))
142
(get-value (get-top-card end-slot)))))
143
((= (get-value (get-top-card end-slot))
144
(+ 1 (get-value (cadr (get-cards end-slot)))))
145
(= (get-value (car card-list))
146
(+ 1 (get-value (get-top-card end-slot)))))
147
((= (+ 1 (get-value (get-top-card end-slot)))
148
(get-value (cadr (get-cards end-slot))))
149
(= (+ 1 (get-value (car card-list)))
150
(get-value (get-top-card end-slot))))
154
(define (droppable? start-slot card-list end-slot)
155
(cond ((or (= end-slot start-slot)
163
(to-foundation? card-list end-slot))
165
(to-tableau? card-list end-slot))))
167
(define (button-released start-slot card-list end-slot)
168
(and (droppable? start-slot card-list end-slot)
169
(cond ((or (= end-slot 6)
173
(and (move-n-cards! start-slot end-slot card-list)
176
(move-n-cards! start-slot end-slot card-list)))))
178
(define (button-clicked slot-id)
180
(not (empty-slot? 0))
181
(deal-cards-face-up 0 '(1))))
183
(define (play-foundation-helper start-slot end-slots)
184
(define card (get-top-card start-slot))
185
(if (to-foundation? (list card) (car end-slots))
186
(and (remove-card start-slot)
187
(move-n-cards! start-slot (car end-slots) (list card))
189
(if (eq? (cdr end-slots) '())
191
(play-foundation-helper start-slot (cdr end-slots)))))
193
(define (button-double-clicked slot-id)
194
(cond ((member slot-id '(1 2 3 4 5 7 8 9 10 12 13 14 15 17 18 19 20))
195
(and (not (empty-slot? slot-id))
196
(play-foundation-helper slot-id '(6 11 16 21))))
197
((member slot-id '(6 11 16 21))
198
(autoplay-foundations))
201
(define (autoplay-foundations)
202
(define (autoplay-foundations-tail)
203
(if (or-map button-double-clicked '(1 2 3 4 5 7 8 9 10 12 13 14 15 17 18 19 20))
204
(delayed-call autoplay-foundations-tail)
206
(if (or-map button-double-clicked '(1 2 3 4 5 7 8 9 10 12 13 14 15 17 18 19 20))
207
(autoplay-foundations-tail)
210
(define (game-continuable)
211
(give-status-message)
215
(and (= (length (get-cards 6)) 26)
216
(= (length (get-cards 11)) 26)
217
(= (length (get-cards 16)) 26)
218
(= (length (get-cards 21)) 26)))
220
(define (check-a-foundation card-list end-slot)
223
(if (to-foundation? card-list end-slot)
225
(check-a-foundation card-list (+ 5 end-slot)))))
227
(define (check-to-foundations slot-id)
230
(if (or (empty-slot? slot-id)
234
(not (check-a-foundation (list (get-top-card slot-id)) 6)))
235
(check-to-foundations (+ 1 slot-id))
236
(list 2 (get-name (get-top-card slot-id)) (_"appropriate foundation pile")))))
238
(define (check-imbedded card-list foundation-id)
239
(if (> (length card-list) 0)
240
(if (to-foundation? card-list foundation-id)
242
(check-imbedded (cdr card-list) foundation-id))
245
(define (check-slot-contents slot-id)
246
(cond ((and (not (empty-slot? 6))
247
(eq? (get-suit (get-top-card slot-id))
248
(get-suit (get-top-card 6)))
249
(check-imbedded (get-cards slot-id) 6))
250
(check-imbedded (get-cards slot-id) 6))
251
((and (not (empty-slot? 11))
252
(eq? (get-suit (get-top-card slot-id))
253
(get-suit (get-top-card 11)))
254
(check-imbedded (get-cards slot-id) 11))
255
(check-imbedded (get-cards slot-id) 11))
256
((and (not (empty-slot? 16))
257
(eq? (get-suit (get-top-card slot-id))
258
(get-suit (get-top-card 16)))
259
(check-imbedded (get-cards slot-id) 16))
260
(check-imbedded (get-cards slot-id) 16))
261
((and (not (empty-slot? 21))
262
(eq? (get-suit (get-top-card slot-id))
263
(get-suit (get-top-card 21)))
264
(check-imbedded (get-cards slot-id) 21))
265
(check-imbedded (get-cards slot-id) 21))
266
((and (empty-slot? 6)
267
(check-imbedded (get-cards slot-id) 6))
268
(check-imbedded (get-cards slot-id) 6))
269
((and (empty-slot? 11)
270
(check-imbedded (get-cards slot-id) 11))
271
(check-imbedded (get-cards slot-id) 11))
272
((and (empty-slot? 16)
273
(check-imbedded (get-cards slot-id) 16))
274
(check-imbedded (get-cards slot-id) 16))
275
((and (empty-slot? 21)
276
(check-imbedded (get-cards slot-id) 21))
277
(check-imbedded (get-cards slot-id) 21))
278
((and (> (length (get-cards slot-id)) 1)
279
(or (and (not (= slot-id 2))
280
(not (empty-slot? 2))
281
(to-tableau? (reverse (get-cards slot-id)) 2)
282
(not (= (get-value (cadr (reverse (get-cards slot-id))))
283
(get-value (get-top-card 2)))))
284
(and (not (= slot-id 3))
285
(not (empty-slot? 3))
286
(to-tableau? (reverse (get-cards slot-id)) 3)
287
(not (= (get-value (cadr (reverse (get-cards slot-id))))
288
(get-value (get-top-card 3)))))
289
(and (not (= slot-id 4))
290
(not (empty-slot? 4))
291
(to-tableau? (reverse (get-cards slot-id)) 4)
292
(not (= (get-value (cadr (reverse (get-cards slot-id))))
293
(get-value (get-top-card 4)))))
294
(and (not (= slot-id 5))
295
(not (empty-slot? 5))
296
(to-tableau? (reverse (get-cards slot-id)) 5)
297
(not (= (get-value (cadr (reverse (get-cards slot-id))))
298
(get-value (get-top-card 5)))))
299
(and (not (= slot-id 7))
300
(not (empty-slot? 7))
301
(to-tableau? (reverse (get-cards slot-id)) 7)
302
(not (= (get-value (cadr (reverse (get-cards slot-id))))
303
(get-value (get-top-card 7)))))
304
(and (not (= slot-id 8))
305
(not (empty-slot? 8))
306
(to-tableau? (reverse (get-cards slot-id)) 8)
307
(not (= (get-value (cadr (reverse (get-cards slot-id))))
308
(get-value (get-top-card 8)))))
309
(and (not (= slot-id 9))
310
(not (empty-slot? 9))
311
(to-tableau? (reverse (get-cards slot-id)) 9)
312
(not (= (get-value (cadr (reverse (get-cards slot-id))))
313
(get-value (get-top-card 9)))))
314
(and (not (= slot-id 10))
315
(not (empty-slot? 10))
316
(to-tableau? (reverse (get-cards slot-id)) 10)
317
(not (= (get-value (cadr (reverse (get-cards slot-id))))
318
(get-value (get-top-card 10)))))
319
(and (not (= slot-id 12))
320
(not (empty-slot? 12))
321
(to-tableau? (reverse (get-cards slot-id)) 12)
322
(not (= (get-value (cadr (reverse (get-cards slot-id))))
323
(get-value (get-top-card 12)))))
324
(and (not (= slot-id 13))
325
(not (empty-slot? 13))
326
(to-tableau? (reverse (get-cards slot-id)) 13)
327
(not (= (get-value (cadr (reverse (get-cards slot-id))))
328
(get-value (get-top-card 13)))))
329
(and (not (= slot-id 14))
330
(not (empty-slot? 14))
331
(to-tableau? (reverse (get-cards slot-id)) 14)
332
(not (= (get-value (cadr (reverse (get-cards slot-id))))
333
(get-value (get-top-card 14)))))
334
(and (not (= slot-id 15))
335
(not (empty-slot? 15))
336
(to-tableau? (reverse (get-cards slot-id)) 15)
337
(not (= (get-value (cadr (reverse (get-cards slot-id))))
338
(get-value (get-top-card 15)))))
339
(and (not (= slot-id 17))
340
(not (empty-slot? 17))
341
(to-tableau? (reverse (get-cards slot-id)) 17)
342
(not (= (get-value (cadr (reverse (get-cards slot-id))))
343
(get-value (get-top-card 17)))))
344
(and (not (= slot-id 18))
345
(not (empty-slot? 18))
346
(to-tableau? (reverse (get-cards slot-id)) 18)
347
(not (= (get-value (cadr (reverse (get-cards slot-id))))
348
(get-value (get-top-card 18)))))
349
(and (not (= slot-id 19))
350
(not (empty-slot? 19))
351
(to-tableau? (reverse (get-cards slot-id)) 19)
352
(not (= (get-value (cadr (reverse (get-cards slot-id))))
353
(get-value (get-top-card 19)))))
354
(and (not (= slot-id 20))
355
(not (empty-slot? 20))
356
(to-tableau? (reverse (get-cards slot-id)) 20)
357
(not (= (get-value (cadr (reverse (get-cards slot-id))))
358
(get-value (get-top-card 20)))))))
362
(define (check-a-tslot slot1 slot2)
365
(if (and (not (= slot2 6))
368
(not (empty-slot? slot2))
369
(not (= slot1 slot2))
370
(not (empty-slot? slot1))
371
(to-tableau? (list (get-top-card slot1)) slot2)
373
(= (length (get-cards slot1)) 1)
374
(not (= (get-value (cadr (get-cards slot1)))
375
(get-value (get-top-card slot2))))))
376
(if (and (not (= slot1 1))
377
(not (empty-slot? slot2))
378
(to-tableau? (list (get-top-card slot2)) slot1)
379
(check-slot-contents slot2))
380
(list 1 (get-name (get-top-card slot2))
381
(get-name (get-top-card slot1)))
382
(list 1 (get-name (get-top-card slot1))
383
(get-name (get-top-card slot2))))
384
(check-a-tslot slot1 (+ 1 slot2)))))
386
(define (check-tableau slot-id)
388
(and (not (empty-slot? 1))
390
(if (or (= slot-id 6)
393
(check-tableau (- slot-id 1))
394
(or (check-a-tslot slot-id 2)
395
(check-tableau (- slot-id 1))))))
397
(define (check-for-empty slot-id)
400
(if (and (not (= slot-id 6))
403
(empty-slot? slot-id))
405
(check-for-empty (+ 1 slot-id)))))
407
(define (check-rev-tableau slot1 slot2)
410
(if (or (empty-slot? slot2)
415
(check-rev-tableau slot1 (+ 1 slot2))
416
(if (and (to-tableau? (reverse (get-cards slot1)) slot2)
417
(= (abs (- (get-value (cadr (reverse (get-cards slot1))))
418
(get-value (get-top-card slot2))))
421
(check-rev-tableau slot1 (+ 1 slot2))))))
423
(define (check-for-bottom slot-id)
426
(if (or (empty-slot? slot-id)
427
(= 1 (length (get-cards slot-id)))
431
(check-for-bottom (+ 1 slot-id))
432
(or (check-rev-tableau slot-id 2)
433
(check-for-bottom (+ 1 slot-id))))))
435
(define (contents-check slot-id)
438
(if (and (not (= slot-id 6))
441
(not (empty-slot? slot-id))
442
(check-slot-contents slot-id))
444
(contents-check (+ 1 slot-id)))))
446
(define (check-empty-slot)
447
(if (not (check-for-empty 2))
449
(cond ((contents-check 2)
450
(list 2 (get-name (get-top-card (contents-check 2)))
452
((check-for-bottom 2)
453
(list 2 (get-name (get-top-card (check-for-bottom 2)))
455
((not (empty-slot? 1))
456
(list 2 (get-name (get-top-card 1)) (_"an empty slot")))
460
(if (not (empty-slot? 0))
461
(list 0 (_"Deal a card"))
465
(or (check-to-foundations 1)
470
(define (get-options)
473
(define (apply-options options)
479
(set-features droppable-feature)
481
(set-lambda new-game button-pressed button-released button-clicked
482
button-double-clicked game-continuable game-won get-hint get-options
483
apply-options timeout droppable?)