1
; AisleRiot - king's_audience.scm
2
; Copyright (C) 2005 Zach Keene
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) (ice-9 format))
21
(define reserves '(0 1 2 3 4 9 10 13 14 19 20 21 22 23 24 25))
22
(define royal-discards '(5 6 7 8))
23
(define foundations '(15 16 17 18))
25
(def-save-var open-royal 5)
26
(def-save-var open-foundation 15)
29
(initialize-playing-area)
34
(add-normal-slot '()) ; slot 0
35
(add-normal-slot '()) ; slot 1
36
(add-normal-slot '()) ; slot 2
37
(add-normal-slot '()) ; slot 3
38
(add-carriage-return-slot)
40
(add-raised-slot '()) ; slot 4
41
(add-extended-slot '() right) ; slot 5 (discard)
42
(add-extended-slot '() right) ; slot 6 (discard)
43
(add-extended-slot '() right) ; slot 7 (discard)
44
(add-extended-slot '() right) ; slot 8 (discard)
45
(add-raised-slot '()) ; slot 9
46
(add-carriage-return-slot)
48
(add-raised-slot '()) ; slot 10
50
(add-normal-slot DECK) ; slot 11 (stock)
51
(add-normal-slot '()) ; slot 12 (waste)
53
(add-raised-slot '()) ; slot 13
54
(add-carriage-return-slot)
56
(add-raised-slot '()) ; slot 14
57
(add-normal-slot '()) ; slot 15 (foundation)
58
(add-normal-slot '()) ; slot 16 (foundation)
59
(add-normal-slot '()) ; slot 17 (foundation)
60
(add-normal-slot '()) ; slot 18 (foundation)
61
(add-raised-slot '()) ; slot 19
62
(add-carriage-return-slot)
64
(add-raised-slot '()) ; slot 20
65
(add-normal-slot '()) ; slot 21
66
(add-normal-slot '()) ; slot 22
67
(add-normal-slot '()) ; slot 23
68
(add-normal-slot '()) ; slot 24
69
(add-raised-slot '()) ; slot 25
72
(set! open-foundation 15)
74
(deal-cards-face-up stock reserves)
80
(define (add-raised-slot list)
81
(set! VERTPOS (- VERTPOS 0.5))
82
(add-normal-slot list)
83
(set! VERTPOS (+ VERTPOS 0.5))
87
(set-statusbar-message (format #f
88
(_"Stock remaining: ~a")
89
(number->string (length (get-cards stock)))
95
(define (button-pressed slot-id card-list)
96
(member slot-id (append (list waste) reserves))
99
(define (droppable? start-slot card-list end-slot)
100
(and (not (null? (car card-list)))
101
(not (= start-slot end-slot))
102
(not (= end-slot stock))
103
(or (pair? (car card-list) (get-top-card end-slot) king queen)
104
(pair? (car card-list) (get-top-card end-slot) ace jack)
105
(and (not (empty-slot? end-slot))
106
(member end-slot foundations)
107
(= (get-suit (car card-list))
108
(get-suit (get-top-card end-slot)))
109
(= (+ (get-value (car card-list)) 1)
110
(get-value (get-top-card end-slot))
117
(define (pair? card1 card2 rank1 rank2)
118
(and (not (null? card1))
120
(= (get-suit card1) (get-suit card2))
121
(or (and (= rank1 (get-value card1)) (= rank2 (get-value card2)))
122
(and (= rank1 (get-value card2)) (= rank2 (get-value card1)))
127
(define (button-released start-slot card-list end-slot)
128
(if (droppable? start-slot card-list end-slot)
129
(if (member end-slot foundations)
131
(move-n-cards! start-slot end-slot card-list)
135
(if (or (= ace (get-value (car card-list)))
136
(= jack (get-value (car card-list)))
138
(move-pair start-slot card-list end-slot open-foundation)
139
(move-pair start-slot card-list end-slot open-royal)
146
(define (move-pair start-slot card-list end-slot destination)
147
(remove-card end-slot)
148
(if (member destination foundations)
150
(add-card! destination (make-visible
151
(make-card jack (get-suit (car card-list))))
153
(set! open-foundation (+ open-foundation 1))
156
(add-card! destination (make-visible
157
(make-card king (get-suit (car card-list))))
159
(add-card! destination (make-visible
160
(make-card queen (get-suit (car card-list))))
162
(set! open-royal (+ open-royal 1))
169
(define (fill-gaps slot-list)
170
(if (or (and (empty-slot? waste) (empty-slot? stock)) (null? slot-list))
173
(if (empty-slot? (car slot-list))
174
(if (empty-slot? waste)
175
(deal-cards-face-up stock (list (car slot-list)))
176
(deal-cards-face-up waste (list (car slot-list)))
179
(fill-gaps (cdr slot-list))
185
(define (button-clicked slot-id)
186
(if (= slot-id stock)
187
(flip-stock stock waste 0)
192
(define (button-double-clicked slot-id)
193
(if (member slot-id (append (list waste) reserves))
194
(let ((move (check-moves-helper slot-id
195
(append (list waste) reserves foundations)
200
(button-released slot-id (list (remove-card slot-id)) (cadr move))
210
(define (game-continuable)
222
(define move (or (check-moves (append (list waste) reserves) foundations)
223
(check-moves (append (list waste) reserves) reserves))
226
(list 1 (get-name(get-top-card(car move)))
227
(get-name(get-top-card(cadr move)))
229
(and (not (empty-slot? stock)) (list 0 (_"Deal a new card")))
233
(define (check-moves from-list to-list)
234
(if (not (null? from-list))
236
(or (check-moves-helper (car from-list) to-list)
237
(check-moves (cdr from-list) (delete (car from-list) to-list))
244
(define (check-moves-helper item to-list)
245
(if (not (null? to-list))
247
(if (droppable? item (list (get-top-card item)) (car to-list))
248
(list item (car to-list))
249
(check-moves-helper item (cdr to-list))
256
(define (get-options)
259
(define (apply-options options)
265
(set-features droppable-feature)
267
(set-lambda new-game button-pressed button-released button-clicked
268
button-double-clicked game-continuable game-won get-hint get-options
269
apply-options timeout droppable?)