1; Aisleriot - Thieves
2; Copyright (C) 2001 Robert Brady <rwb197@ecs.soton.ac.uk>
3;                    Rosanna Yuen <zana@webwynk.net>
4;
5; This program is free software: you can redistribute it and/or modify
6; it under the terms of the GNU General Public License as published by
7; the Free Software Foundation, either version 3 of the License, or
8; (at your option) any later version.
9;
10; This program is distributed in the hope that it will be useful,
11; but WITHOUT ANY WARRANTY; without even the implied warranty of
12; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13; GNU General Public License for more details.
14;
15; You should have received a copy of the GNU General Public License
16; along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18(use-modules (aisleriot interface) (aisleriot api))
19
20(define (new-game)
21  (initialize-playing-area)
22  (set-ace-low)
23  (make-joker-deck)
24
25  (shuffle-deck)
26  (add-extended-slot '() down)
27  (add-extended-slot '() down)
28  (add-extended-slot '() down)
29  (add-extended-slot '() down)
30  (add-extended-slot '() down)
31  (add-extended-slot '() down)
32  (add-extended-slot '() down)
33  (add-carriage-return-slot)
34  (add-carriage-return-slot)
35  (add-normal-slot DECK)
36  (add-normal-slot '())
37  (deal-cards-face-up 7 '(0 1 2 3 4 5 6 0 1 2 3 4 5 6 0 1 2 3 4 5 6 0
38			    1 2 3 4 5 6 0 1 2 3 4 5 6 8))
39
40  (give-status-message)
41
42  (list 7 3))
43
44(define (give-status-message)
45  (set-statusbar-message (get-stock-no-string)))
46
47(define (get-stock-no-string)
48  (string-append (_"Stock left:") " "
49		 (number->string (length (get-cards 7)))))
50
51(define (values-match? c1 c2)
52  (or (eq? (get-value c1) joker)
53      (eq? (get-value c2) joker)
54      (eq? (+ 1 (get-value c1)) (get-value c2))
55      (eq? (get-value c1) (+ 1 (get-value c2)))))
56
57(define (score-for card)
58  (cond ((eq? card ace) 8)
59	((eq? card 2) 6)
60	((eq? card 3) 6)
61	((eq? card 4) 4)
62	((eq? card 5) 4)
63	((eq? card 6) 2)
64	((eq? card 7) 2)
65	((eq? card 8) 2)
66	((eq? card 9) 4)
67	((eq? card 10) 4)
68	((eq? card jack) 6)
69	((eq? card queen) 6)
70	((eq? card king) 8)
71	(#t 0)))
72
73(define (can-move-from where)
74  (and (not (empty-slot? where))
75       (not (empty-slot? 8))
76       (values-match? (get-top-card where) (get-top-card 8))))
77
78(define (move-possible)
79  (or (can-move-from 0)
80      (can-move-from 1)
81      (can-move-from 2)
82      (can-move-from 3)
83      (can-move-from 4)
84      (can-move-from 5)
85      (can-move-from 6)))
86
87(define (button-pressed slot-id card-list)
88  (and (< slot-id 7)
89       (not (empty-slot? slot-id))
90       (= (length card-list) 1)))
91
92(define (button-released start-slot card-list end-slot)
93  (and (= end-slot 8)
94       (values-match? (car card-list) (get-top-card 8))
95       (add-to-score! (score-for (get-value (car card-list))))
96       (move-n-cards! start-slot 8 card-list)))
97
98(define (droppable? start-slot card-list end-slot)
99  (and (= end-slot 8)
100       (values-match? (car card-list) (get-top-card 8)) ) )
101
102
103(define (button-clicked slot-id)
104  (if (eq? slot-id 7)
105      (and (not (empty-slot? slot-id))
106	   (deal-cards-face-up 7 '(8)))
107      (and (< slot-id 7)
108	   (not (empty-slot? slot-id))
109	   (values-match? (get-top-card slot-id) (get-top-card 8))
110	   (add-to-score! (score-for (get-value (get-top-card slot-id))))
111	   (deal-cards slot-id '(8)))))
112
113(define (button-double-clicked slot)
114  (button-clicked slot))
115
116(define (game-won)
117  (and (empty-slot? 0)
118       (empty-slot? 1)
119       (empty-slot? 2)
120       (empty-slot? 3)
121       (empty-slot? 4)
122       (empty-slot? 5)
123       (empty-slot? 6)))
124
125(define (game-over)
126  (give-status-message)
127  (if (game-won)
128    #f
129    (if (empty-slot? 7)
130	(move-possible)
131	#t)))
132
133(define (hint-move-from where)
134  (if (or (empty-slot? where)
135          (empty-slot? where)
136	  (not (values-match? (get-top-card where) (get-top-card 8))))
137      #f
138      (hint-move where 1 8)))
139
140(define (get-hint)
141  (or (hint-move-from 0)
142      (hint-move-from 1)
143      (hint-move-from 2)
144      (hint-move-from 3)
145      (hint-move-from 4)
146      (hint-move-from 5)
147      (hint-move-from 6)
148      (list 0 (_"Deal a card from the deck"))))
149
150(define (get-options) #f)
151(define (apply-options options) #f)
152(define (timeout) #f)
153
154(set-features droppable-feature)
155
156(set-lambda new-game button-pressed button-released button-clicked
157  button-double-clicked game-over game-won get-hint get-options apply-options
158  timeout droppable?)
159