~ubuntu-branches/debian/jessie/aisleriot/jessie

« back to all changes in this revision

Viewing changes to games/bakers_dozen.scm

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Jeremy Bicha, Jordi Mallach
  • Date: 2012-04-22 12:49:26 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120422124926-gmr0thwstl91jt1n
Tags: 1:3.4.1-1
[ Jeremy Bicha ]
* New upstream release
* debian/control.in: (Build)-depend on guile-2.0
* debian/*.install: Cards files are now stored as zipped .svg's
* debian/patches/99_format-security.patch: Dropped, applied upstream

[ Jordi Mallach ]
* New upstream release.
* Update copyright to final version of the machine-readable 1.0 spec.
* Bump Standards Version to 3.9.3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
; AisleRiot - bakers_dozen.scm
2
 
; Copyright (C) 2001, 2003 Rosanna Yuen <zana@webwynk.net>
3
 
;
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.
8
 
;
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.
13
 
;
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/>.
16
 
 
17
 
(define (new-game)
18
 
  (initialize-playing-area)
19
 
  (set-ace-low)
20
 
  (make-standard-deck)
21
 
  (shuffle-deck)
22
 
 
23
 
  (add-blank-slot)
24
 
  (add-blank-slot)
25
 
  (add-blank-slot)
26
 
 
27
 
  (add-normal-slot DECK)
28
 
  (add-blank-slot)
29
 
  (add-normal-slot '())
30
 
  (add-blank-slot)
31
 
  (add-normal-slot '())
32
 
  (add-blank-slot)
33
 
  (add-normal-slot '())
34
 
 
35
 
  (add-carriage-return-slot)
36
 
 
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)
50
 
 
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))
53
 
  (move-kings-back 4)
54
 
 
55
 
  (deal-cards-face-up 0 '(4 5 6 7 8 9 10 11 12 13 14 15 16))
56
 
  (move-kings-back 4)
57
 
 
58
 
  (deal-cards-face-up 0 '(4 5 6 7 8 9 10 11 12 13 14 15 16))
59
 
  (move-kings-back 4)
60
 
 
61
 
  (list 13 5))
62
 
 
63
 
(define (move-kings-back slot-id)
64
 
  (if (< slot-id 17)
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)))
69
 
      #t))
70
 
 
71
 
(define (button-pressed slot-id card-list)
72
 
  (and (not (empty-slot? slot-id))
73
 
       (= (length card-list) 1)))
74
 
 
75
 
(define (droppable? start-slot card-list end-slot)
76
 
  (cond ((= start-slot end-slot)
77
 
         #f)
78
 
        ((< end-slot 4)
79
 
         (cond ((and (= (get-value (car card-list))
80
 
                        ace)
81
 
                     (empty-slot? end-slot))
82
 
                #t)
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))))
88
 
                #t)
89
 
               (#t #f)))
90
 
        ((and (not (empty-slot? end-slot))
91
 
              (= (get-value (get-top-card end-slot))
92
 
                 (+ 1 (get-value (car card-list)))))
93
 
         #t)
94
 
        (#t #f)))
95
 
 
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)
99
 
       (or (> start-slot 3)
100
 
           (add-to-score! -1))
101
 
       (or (> end-slot 3)
102
 
           (add-to-score! 1))))
103
 
 
104
 
(define (button-clicked slot-id)
105
 
  #f)
106
 
 
107
 
(define (find-empty-foundation a-slot f-slot)
108
 
  (cond ((> f-slot 3)
109
 
         #f)
110
 
        ((empty-slot? f-slot)
111
 
         (deal-cards a-slot (list f-slot)))
112
 
        (#t (find-empty-foundation a-slot (+ 1 f-slot)))))
113
 
 
114
 
(define (find-foundation a-slot f-slot)
115
 
  (cond ((> f-slot 3)
116
 
         #f)
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))
123
 
              (add-to-score! 1)))
124
 
        (#t (find-foundation a-slot (+ 1 f-slot)))))
125
 
 
126
 
 
127
 
(define (button-double-clicked slot-id)
128
 
  (and (> slot-id 3)
129
 
       (not (empty-slot? slot-id))
130
 
       (or (and (= (get-value (get-top-card slot-id))
131
 
                   ace)
132
 
                (find-empty-foundation slot-id 0)
133
 
                (add-to-score! 1))
134
 
           (find-foundation slot-id 0))))
135
 
       
136
 
 
137
 
(define (game-continuable)
138
 
  (and (not (game-won))
139
 
       (get-hint)))
140
 
 
141
 
(define (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)))
146
 
 
147
 
(define (foundation-possible? t-slot f-slot)
148
 
  (cond ((= t-slot 17)
149
 
         #f)
150
 
        ((or (= f-slot 4)
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)))))
160
 
         (list 1 
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)))))
164
 
 
165
 
(define (card-to-foundation-possible? card f-slot)
166
 
  (cond ((= f-slot 4)
167
 
         #f)
168
 
        ((and (not (empty-slot? f-slot))
169
 
              (= (get-suit card)
170
 
                 (get-suit (get-top-card f-slot))))
171
 
         (= (get-value card)
172
 
            (+ 1 (get-value (get-top-card f-slot)))))
173
 
        (#t (card-to-foundation-possible? card (+ 1 f-slot)))))
174
 
 
175
 
(define (tableau-moves? slot1 slot2)
176
 
  (cond ((= slot1 17)
177
 
         #f)
178
 
        ((or (= slot2 17)
179
 
             (empty-slot? slot1))
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)))))
191
 
 
192
 
(define (get-hint)
193
 
  (or (foundation-possible? 4 0)
194
 
      (tableau-moves? 4 5)
195
 
      (list 0 (_"Try rearranging the cards"))))
196
 
 
197
 
(define (get-options) 
198
 
  #f)
199
 
 
200
 
(define (apply-options options) 
201
 
  #f)
202
 
 
203
 
(define (timeout) 
204
 
  #f)
205
 
 
206
 
(set-features droppable-feature)
207
 
 
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?)