pileon.scm 5.9 KB
Newer Older
1
; AisleRiot - pileon.scm
2
; Copyright (C) 1998 Nick Lamb <njl195@zepler.org.uk>
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 7
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
8 9 10 11 12 13 14
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; 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
(use-modules (aisleriot interface) (aisleriot api))

19 20 21 22 23 24 25
(define (new-game)
  (initialize-playing-area)
  (set-ace-low)
  (make-standard-deck)
  (shuffle-deck)

  (add-partially-extended-slot '() right 4)
Callum McKenzie's avatar
Callum McKenzie committed
26
  (set! HORIZPOS (+ HORIZPOS 1))
27
  (add-partially-extended-slot '() right 4)
Callum McKenzie's avatar
Callum McKenzie committed
28
  (set! HORIZPOS (+ HORIZPOS 1))
29
  (add-partially-extended-slot '() right 4)
Callum McKenzie's avatar
Callum McKenzie committed
30
  (set! HORIZPOS (+ HORIZPOS 1))
31 32 33 34
  (add-partially-extended-slot '() right 4)
  (add-carriage-return-slot)

  (add-partially-extended-slot '() right 4)
Callum McKenzie's avatar
Callum McKenzie committed
35
  (set! HORIZPOS (+ HORIZPOS 1))
36
  (add-partially-extended-slot '() right 4)
Callum McKenzie's avatar
Callum McKenzie committed
37
  (set! HORIZPOS (+ HORIZPOS 1))
38
  (add-partially-extended-slot '() right 4)
Callum McKenzie's avatar
Callum McKenzie committed
39
  (set! HORIZPOS (+ HORIZPOS 1))
40 41 42 43
  (add-partially-extended-slot '() right 4)
  (add-carriage-return-slot)

  (add-partially-extended-slot '() right 4)
Callum McKenzie's avatar
Callum McKenzie committed
44
  (set! HORIZPOS (+ HORIZPOS 1))
45
  (add-partially-extended-slot '() right 4)
Callum McKenzie's avatar
Callum McKenzie committed
46
  (set! HORIZPOS (+ HORIZPOS 1))
47
  (add-partially-extended-slot '() right 4)
Callum McKenzie's avatar
Callum McKenzie committed
48
  (set! HORIZPOS (+ HORIZPOS 1))
49 50 51 52
  (add-partially-extended-slot '() right 4)
  (add-carriage-return-slot)

  (add-partially-extended-slot '() right 4)
Callum McKenzie's avatar
Callum McKenzie committed
53
  (set! HORIZPOS (+ HORIZPOS 1))
54
  (add-partially-extended-slot '() right 4)
Callum McKenzie's avatar
Callum McKenzie committed
55
  (set! HORIZPOS (+ HORIZPOS 1))
56 57 58 59 60 61
  (add-partially-extended-slot '() right 4)
  (add-carriage-return-slot)

  (deal-cards-face-up-from-deck DECK
   '(0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 6 6 6 6 7 7 7 7 8 8 8 8 9 9 9 9 10 10 10 10 11 11 11 11 12 12 12 12))

62 63
  (freeze-slots-if-complete '(0 1 2 3 4 5 6 7 8 9 10 11 12))

Callum McKenzie's avatar
Callum McKenzie committed
64
  (list 8 4))
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80

(define (check-same-value-list card-list)
  (if (< (length card-list) 2)
      #t
      (if (= (get-value (car card-list)) (get-value (cadr card-list)))
          (check-same-value-list (cdr card-list))
          #f)))

(define (freeze-slot slot-id)
   (flip-top-card slot-id)
   (add-to-score! 4))

(define (button-pressed slot-id card-list)
   (and (check-same-value-list card-list)
        (is-visible? (car card-list))))

81 82 83 84 85 86 87 88 89 90 91
(define (freeze-if-complete slot-id)
  (and (= (length (get-cards slot-id)) 4)
       (check-same-value-list (get-cards slot-id))
       (freeze-slot slot-id))
  #t)

(define (freeze-slots-if-complete slots)
  (and (not (null? slots))
       (freeze-if-complete (car slots))
       (freeze-slots-if-complete (cdr slots))))

92 93
(define (complete-transaction start-slot card-list end-slot)
  (move-n-cards! start-slot end-slot card-list)
94
  (freeze-if-complete end-slot))
95

96 97 98
(define (droppable? start-slot card-list end-slot)
  (and (not (= start-slot end-slot))
       (or (empty-slot? end-slot)
99 100
           (eq? (get-value (car (get-cards end-slot)))
                (get-value (car card-list))))
101 102 103 104
       (< (+ (length (get-cards end-slot)) (length card-list)) 5)))

(define (button-released start-slot card-list end-slot)
  (and (droppable? start-slot card-list end-slot)
105 106 107 108 109 110
       (complete-transaction start-slot card-list end-slot)))

(define (button-clicked slot-id) #f)

(define (button-double-clicked slot) #f)

111 112 113
(define (game-over) 
  (and (not (game-won))
       (get-hint)))
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

(define (done-or-empty slot-id)
  (or (empty-slot? slot-id)
      (not (is-visible? (car (get-cards slot-id))))))

(define (game-won) 
  (and (done-or-empty 0)
       (done-or-empty 1)
       (done-or-empty 2)
       (done-or-empty 3)
       (done-or-empty 4)
       (done-or-empty 5)
       (done-or-empty 6)
       (done-or-empty 7)
       (done-or-empty 8)
       (done-or-empty 9)
       (done-or-empty 10)
       (done-or-empty 11)
       (done-or-empty 12)
       (done-or-empty 13)
       (done-or-empty 14))
)

137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
(define (check-number slot-id)
  (cond ((and (> (length (get-cards slot-id)) 1)
	      (not (= (get-value (get-top-card slot-id))
		      (get-value (cadr (get-cards slot-id))))))
	 1)
	((and (> (length (get-cards slot-id)) 2)
	      (not (= (get-value (get-top-card slot-id))
		      (get-value (caddr (get-cards slot-id))))))
	 2)
	((and (> (length (get-cards slot-id)) 3)
	      (not (= (get-value (get-top-card slot-id))
		      (get-value (cadddr (get-cards slot-id))))))
	 3)
	(#t 1)))

(define (check-a-slot slot-id number-to-move to-slot)
  (if (> to-slot 14)
      #f
      (if (= slot-id to-slot)
	  (check-a-slot slot-id number-to-move (+ 1 to-slot))
	  (cond ((empty-slot? slot-id)
158
		 (list 2 (_"something") (_"an empty slot")))
159
		((empty-slot? to-slot)
160
		 (list 2 (_"something") (_"an empty slot")))
161 162 163 164 165 166 167 168 169
		((= 4 (length (get-cards to-slot)))
		 (check-a-slot slot-id number-to-move (+ 1 to-slot)))
		((= (get-value (get-top-card to-slot))
		    (get-value (get-top-card slot-id)))
		 (if (> number-to-move (- 4 (length (get-cards to-slot))))
		     (check-a-slot slot-id 
				   (- number-to-move 
				      (- 4 (length (get-cards to-slot))))
				   (+ 1 to-slot))
170
		     (hint-move slot-id 1 to-slot)))
171 172 173 174 175 176 177 178 179 180
		(#t (check-a-slot slot-id number-to-move (+ 1 to-slot)))))))

(define (check-slots slot-id to-slot)
  (if (> slot-id 14)
      #f
      (or (check-a-slot slot-id (check-number slot-id) to-slot)
	  (check-slots (+ 1 slot-id) 0))))

(define (get-hint)
  (check-slots 0 1))
181 182 183 184 185 186 187

(define (get-options) #f)

(define (apply-options options) #f)

(define (timeout) #f)

188 189 190
(set-features droppable-feature)

(set-lambda new-game button-pressed button-released button-clicked button-double-clicked game-over game-won get-hint get-options apply-options timeout droppable?)