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

« back to all changes in this revision

Viewing changes to games/bear_river.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 - Bear River
2
 
; Copyright (C) 2009 Vincent Povirk
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
 
 
18
 
 
19
 
(define tableau '(4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21))
20
 
(define foundation '(0 1 2 3))
21
 
(define hole '(9 15 21))
22
 
 
23
 
(define BASE-VAL 0)
24
 
 
25
 
(define (new-game)
26
 
  (initialize-playing-area)
27
 
  (set-ace-low)
28
 
 
29
 
  (make-standard-deck)
30
 
  (shuffle-deck)
31
 
 
32
 
  (add-blank-slot)
33
 
  (add-normal-slot DECK)
34
 
  (add-normal-slot '())
35
 
  (add-normal-slot '())
36
 
  (add-normal-slot '())
37
 
  (add-carriage-return-slot)
38
 
 
39
 
  (add-extended-slot '() right)
40
 
  (add-extended-slot '() right)
41
 
  (add-extended-slot '() right)
42
 
  (add-extended-slot '() right)
43
 
  (add-extended-slot '() right)
44
 
  (set! HORIZPOS (+ HORIZPOS 0.18))
45
 
  (add-extended-slot '() right)
46
 
  (add-carriage-return-slot)
47
 
 
48
 
  (add-extended-slot '() right)
49
 
  (add-extended-slot '() right)
50
 
  (add-extended-slot '() right)
51
 
  (add-extended-slot '() right)
52
 
  (add-extended-slot '() right)
53
 
  (set! HORIZPOS (+ HORIZPOS 0.18))
54
 
  (add-extended-slot '() right)
55
 
  (add-carriage-return-slot)
56
 
 
57
 
  (add-extended-slot '() right)
58
 
  (add-extended-slot '() right)
59
 
  (add-extended-slot '() right)
60
 
  (add-extended-slot '() right)
61
 
  (add-extended-slot '() right)
62
 
  (set! HORIZPOS (+ HORIZPOS 0.18))
63
 
  (add-extended-slot '() right)
64
 
  (add-carriage-return-slot)
65
 
 
66
 
  (deal-to-tableau 0 tableau)
67
 
  (flip-top-card 0)
68
 
 
69
 
  (set! BASE-VAL (get-value (get-top-card 0)))
70
 
 
71
 
  (list 6.3 4))
72
 
 
73
 
(define (deal-to-tableau deck piles)
74
 
  (if (null? piles)
75
 
      #t
76
 
      (begin
77
 
        (deal-cards-face-up deck (list (car piles) (car piles)))
78
 
        (and (not (member (car piles) hole))
79
 
             (deal-cards-face-up deck (list (car piles))))
80
 
        (deal-to-tableau deck (cdr piles)))))
81
 
 
82
 
(define (give-status-message)
83
 
  (set-statusbar-message (get-base-string)))
84
 
 
85
 
(define (get-base-string)
86
 
  (cond ((and (> BASE-VAL 1)
87
 
              (< BASE-VAL 11))
88
 
         (string-append (_"Base Card: ") (number->string BASE-VAL)))
89
 
        ((= BASE-VAL 1)
90
 
         (_"Base Card: Ace"))
91
 
        ((= BASE-VAL 11)
92
 
         (_"Base Card: Jack"))
93
 
        ((= BASE-VAL 12)
94
 
         (_"Base Card: Queen"))
95
 
        ((= BASE-VAL 13)
96
 
         (_"Base Card: King"))
97
 
        (#t "")))
98
 
 
99
 
(define (button-pressed slot-id card-list)
100
 
  (and (member slot-id tableau)
101
 
       (= (length card-list) 1)))
102
 
 
103
 
(define (value-offset? offset card1 card2)
104
 
  (= offset
105
 
     (modulo (- (get-value card2) (get-value card1)) 13)))
106
 
 
107
 
(define (droppable? start-slot card-list end-slot)
108
 
  (if (member end-slot foundation)
109
 
      (if (empty-slot? end-slot)
110
 
          (= (get-value (car card-list)) BASE-VAL)
111
 
          (and (suit-eq? (car card-list) (get-top-card end-slot))
112
 
               (value-offset? 1 (get-top-card end-slot) (car card-list))))
113
 
      (and (not (= start-slot end-slot))
114
 
           (if (empty-slot? end-slot)
115
 
               (member end-slot hole)
116
 
               (and (< (length (get-cards end-slot)) 3)
117
 
                    (suit-eq? (get-top-card end-slot) (car card-list))
118
 
                    (or (value-offset? 1 (get-top-card end-slot) (car card-list))
119
 
                        (value-offset? 1 (car card-list) (get-top-card end-slot))))))))
120
 
 
121
 
(define (button-released start-slot card-list end-slot)
122
 
  (and (droppable? start-slot card-list end-slot)
123
 
       (move-n-cards! start-slot end-slot card-list)))
124
 
 
125
 
(define (button-clicked slot-id)
126
 
  #f)
127
 
 
128
 
(define (try-to-foundations from-slot to-slots)
129
 
  (if (null? to-slots)
130
 
      #f
131
 
      (if (droppable? from-slot (list (get-top-card from-slot)) (car to-slots))
132
 
          (deal-cards from-slot (list (car to-slots)))
133
 
          (try-to-foundations from-slot (cdr to-slots)))))
134
 
 
135
 
(define (button-double-clicked slot-id)
136
 
  (and (member slot-id tableau)
137
 
       (not (empty-slot? slot-id))
138
 
       (try-to-foundations slot-id foundation)))
139
 
 
140
 
(define (game-continuable)
141
 
  (give-status-message)
142
 
  (and (not (game-won))
143
 
       (get-hint)))
144
 
 
145
 
(define (count-cards slots acc)
146
 
  (if (null? slots)
147
 
      acc
148
 
      (count-cards (cdr slots) (+ acc (length (get-cards (car slots)))))))
149
 
 
150
 
(define (update-score)
151
 
  (set-score! (count-cards foundation 0)))
152
 
 
153
 
(define (game-won)
154
 
  (= (update-score) 52))
155
 
 
156
 
(define (hint-slot-to-foundation from-slot to-slots)
157
 
  (cond ((null? to-slots) #f)
158
 
        ((droppable? from-slot (list (get-top-card from-slot)) (car to-slots))
159
 
         (if (empty-slot? (car to-slots))
160
 
             (list 2 (get-name (get-top-card from-slot)) (_"an empty foundation slot"))
161
 
             (list 1 (get-name (get-top-card from-slot)) (get-name (get-top-card (car to-slots))))))
162
 
        (else (hint-slot-to-foundation from-slot (cdr to-slots)))))
163
 
 
164
 
(define (hint-to-foundation from-slots to-slots)
165
 
  (cond ((null? from-slots) #f)
166
 
        ((empty-slot? (car from-slots))
167
 
         (hint-to-foundation (cdr from-slots) to-slots))
168
 
        (else (or (hint-slot-to-foundation (car from-slots) to-slots)
169
 
                  (hint-to-foundation (cdr from-slots) to-slots)))))
170
 
 
171
 
(define (hint-slot-to-tableau from-slot to-slots)
172
 
  (cond ((null? to-slots) #f)
173
 
        ((empty-slot? (car to-slots)) (hint-slot-to-tableau from-slot (cdr to-slots)))
174
 
        ((droppable? from-slot (list (get-top-card from-slot)) (car to-slots))
175
 
         (list 1 (get-name (get-top-card from-slot)) (get-name (get-top-card (car to-slots)))))
176
 
        (else (hint-slot-to-tableau from-slot (cdr to-slots)))))
177
 
 
178
 
(define (hint-within-tableau from-slots to-slots)
179
 
  (cond ((null? from-slots) #f)
180
 
        ((or (< (length (get-cards (car from-slots))) 2)
181
 
             (let ((card1 (get-top-card (car from-slots)))
182
 
                   (card2 (cadr (get-cards (car from-slots)))))
183
 
                  (and (suit-eq? card1 card2)
184
 
                       (value-offset? 1 card1 card2))))
185
 
         (hint-within-tableau (cdr from-slots) to-slots))
186
 
        (else (or (hint-slot-to-tableau (car from-slots) to-slots)
187
 
                  (hint-within-tableau (cdr from-slots) to-slots)))))
188
 
 
189
 
(define (hint-empty-hole from-slots to-slots)
190
 
  (cond ((null? from-slots) #f)
191
 
        ((not (= (length (get-cards (car from-slots))) 1))
192
 
         (hint-empty-hole (cdr from-slots) to-slots))
193
 
        (else (or (hint-slot-to-tableau (car from-slots) to-slots)
194
 
                  (hint-empty-hole (cdr from-slots) to-slots)))))
195
 
 
196
 
; Last resort hint: Find any possible tableau move, even unpleasant ones that were skipped earlier.
197
 
(define (hint-last-resort from-slots to-slots)
198
 
  (if (null? from-slots)
199
 
      #f
200
 
      (or (and (not (empty-slot? (car from-slots)))
201
 
               (hint-slot-to-tableau (car from-slots) to-slots))
202
 
          (hint-last-resort (cdr from-slots) to-slots))))
203
 
 
204
 
(define (get-hint)
205
 
  (or (hint-to-foundation tableau foundation)
206
 
      (hint-empty-hole hole tableau)
207
 
      (hint-within-tableau tableau tableau)
208
 
      (and (any-slot-empty? hole)
209
 
           (list 0 (_"Move something onto an empty right-hand tableau slot")))
210
 
      (hint-last-resort tableau tableau)))
211
 
 
212
 
(define (get-options) 
213
 
  #f)
214
 
 
215
 
(define (apply-options options) 
216
 
  #f)
217
 
 
218
 
(define (timeout) 
219
 
  #f)
220
 
 
221
 
(set-features droppable-feature)
222
 
 
223
 
(set-lambda new-game button-pressed button-released button-clicked
224
 
button-double-clicked game-continuable game-won get-hint get-options
225
 
apply-options timeout droppable?)