1
; AisleRiot - straight_up.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))
20
(initialize-playing-area)
23
(set! DECK (make-deck-list-ace-high 3 3 club))
26
(add-normal-slot DECK 'stock)
27
(add-normal-slot '() 'waste)
31
(add-normal-slot (list (make-visible (make-card 2 club))) 'foundation)
32
(add-normal-slot (list (make-visible (make-card 2 diamond))) 'foundation)
33
(add-normal-slot (list (make-visible (make-card 2 heart))) 'foundation)
34
(add-normal-slot (list (make-visible (make-card 2 spade))) 'foundation)
36
(add-carriage-return-slot)
38
(add-normal-slot '() 'reserve)
43
(add-extended-slot '() down 'tableau)
44
(add-extended-slot '() down 'tableau)
45
(add-extended-slot '() down 'tableau)
46
(add-extended-slot '() down 'tableau)
48
(deal-cards 0 '(6 6 6 6 6 6 6 6 6 6 6 6))
49
(deal-cards-face-up 0 '(6 7 8 9 10))
56
(define (give-status-message)
57
(set-statusbar-message (string-append (get-stock-no-string)
59
(get-reserve-no-string)
61
(get-redeals-string))))
63
(define (get-stock-no-string)
64
(string-append (_"Stock left:") " "
65
(number->string (length (get-cards 0)))))
67
(define (get-reserve-no-string)
68
(string-append (_"Reserve left:") " "
69
(number->string (length (get-cards 6)))))
71
(define (get-redeals-string)
72
(string-append (_"Redeals left:") " "
73
(number->string (- 2 FLIP-COUNTER))))
75
(define (button-pressed slot-id card-list)
76
(and (not (empty-slot? slot-id))
80
(define (droppable? start-slot card-list end-slot)
81
(cond ((= start-slot end-slot) #f)
84
(and (eq? (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)))))
89
(or (and (empty-slot? end-slot)
92
(and (not (empty-slot? end-slot))
93
(eq? (get-suit (get-top-card end-slot))
94
(get-suit (car card-list)))
95
(= (get-value (get-top-card end-slot))
96
(+ 1 (get-value (car (reverse card-list))))))))
99
(define (button-released start-slot card-list end-slot)
100
(cond ((= start-slot end-slot) #f)
103
(and (eq? (get-suit (get-top-card end-slot))
104
(get-suit (car card-list)))
105
(= (+ 1 (get-value (get-top-card end-slot)))
106
(get-value (car card-list)))
107
(add-to-score! (length card-list))
108
(move-n-cards! start-slot end-slot (reverse card-list))
109
(check-reserve start-slot)))
111
(or (and (empty-slot? end-slot)
114
(move-n-cards! start-slot end-slot card-list))
115
(and (not (empty-slot? end-slot))
116
(eq? (get-suit (get-top-card end-slot))
117
(get-suit (car card-list)))
118
(= (get-value (get-top-card end-slot))
119
(+ 1 (get-value (car (reverse card-list)))))
120
(move-n-cards! start-slot end-slot card-list)
121
(check-reserve start-slot))))
124
(define (check-reserve start-slot)
128
(and (= 6 start-slot)
129
(make-visible-top-card 6))
130
(not (empty-slot? start-slot))
131
(and (deal-cards 6 (list start-slot))
133
(make-visible-top-card 6))))
134
(give-status-message)))
136
(define (button-clicked slot-id)
139
(give-status-message)))
141
(define (check-up slot-id foundation-id)
142
(if (eq? (get-suit (get-top-card slot-id))
143
(get-suit (get-top-card foundation-id)))
144
(and (= (get-value (get-top-card slot-id))
145
(+ 1 (get-value (get-top-card foundation-id))))
146
(move-n-cards! slot-id
148
(list (get-top-card slot-id)))
150
(remove-card slot-id)
151
(check-reserve slot-id))
152
(check-up slot-id (+ 1 foundation-id))))
154
(define (button-double-clicked slot-id)
155
(and (not (empty-slot? slot-id))
156
(is-visible? (get-top-card slot-id))
157
(check-up slot-id 2)))
162
(define (do-deal-next-cards)
163
(and (flip-stock 0 1 2)
164
(give-status-message)))
166
(define (game-continuable)
167
(and (not (game-won))
171
(and (= (length (get-cards 2)) 13)
172
(= (length (get-cards 3)) 13)
173
(= (length (get-cards 4)) 13)
174
(= (length (get-cards 5)) 13)))
176
(define (check-a-foundation slot-id foundation-id)
177
(cond ((= foundation-id 6)
179
((eq? (get-suit (get-top-card slot-id))
180
(get-suit (get-top-card foundation-id)))
181
(and (= (get-value (get-top-card slot-id))
182
(+ 1 (get-value (get-top-card foundation-id))))
184
(#t (check-a-foundation slot-id (+ 1 foundation-id)))))
186
(define (to-foundations slot-id)
187
(cond ((= slot-id 11)
191
((and (not (empty-slot? slot-id))
192
(check-a-foundation slot-id 2))
193
(hint-move slot-id 1 (check-a-foundation slot-id 2)))
195
(to-foundations (+ 1 slot-id)))))
197
(define (check-a-tableau slot-id t-slot)
200
((and (not (empty-slot? t-slot))
201
(not (= slot-id t-slot))
202
(eq? (get-suit (get-top-card slot-id))
203
(get-suit (get-top-card t-slot)))
204
(or (and (< slot-id 7)
205
(= (get-value (get-top-card t-slot))
206
(+ 1 (get-value (get-top-card slot-id)))))
208
(= (get-value (get-top-card t-slot))
211
(car (reverse (get-cards slot-id)))))))))
213
(#t (check-a-tableau slot-id (+ 1 t-slot)))))
215
(define (to-tableau slot-id)
216
(cond ((= slot-id 11)
220
((and (not (empty-slot? slot-id))
221
(check-a-tableau slot-id 7))
223
(hint-move slot-id 1 (check-a-tableau slot-id 7))
224
(hint-move slot-id (length (get-cards slot-id)) (check-a-tableau slot-id 7))))
225
(#t (to-tableau (+ 1 slot-id)))))
227
(define (empty-tableau? slot-id)
228
(cond ((or (empty-slot? 1)
231
((empty-slot? slot-id)
232
(hint-move 1 1 slot-id))
233
(#t (empty-tableau? (+ 1 slot-id)))))
236
(or (to-foundations 1)
239
(if (not (empty-slot? 0))
240
(list 0 (_"Deal a new card from the deck"))
241
(if (and (< FLIP-COUNTER 2)
242
(not (empty-slot? 1)))
243
(list 0 (_"Move waste back to stock"))
246
(define (get-options)
249
(define (apply-options options)
255
(set-features droppable-feature dealable-feature)
257
(set-lambda new-game button-pressed button-released button-clicked
258
button-double-clicked game-continuable game-won get-hint get-options
259
apply-options timeout droppable? dealable?)