neighbor.scm 6.17 KB
Newer Older
1
; AisleRiot - neighbor.scm
2
; Copyright (C) 1998, 2003 Rosanna Yuen <rwsy@mit.edu>
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
(define (new-game)
  (initialize-playing-area)
  (set-ace-low)
  (make-standard-deck)
  (shuffle-deck)
 
  (add-normal-slot DECK) 
  (add-blank-slot)
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-carriage-return-slot)
  (add-blank-slot)
  (add-blank-slot)
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-carriage-return-slot)
  (add-blank-slot)
  (add-blank-slot)
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-carriage-return-slot)
  (add-blank-slot)
  (add-blank-slot)
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-carriage-return-slot)
  (add-blank-slot)
  (add-blank-slot)
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (add-normal-slot '()) 
  (deal-cards-face-up 0 '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
			    19 20 21 22 23 24 25))

67
  (give-status-message)
68

69
  (list 7 5))
70 71 72

(define (give-status-message)
  (set-statusbar-message (get-stock-no-string)))
73

74
(define (get-stock-no-string)
75
  (string-append (_"Stock left:") " " 
76 77
		 (number->string (length (get-cards 0)))))

78 79
(define (button-pressed slot-id card-list)
  (and (not (= slot-id 0))
80 81
       (not (empty-slot? slot-id))
       (not (= (get-value (get-top-card slot-id)) king))))
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

(define (fill-it-up slot-id spaces)
  (cond ((> (+ slot-id spaces) 25)
	 (begin
	   (if (not (empty-slot? 0))
	       (deal-cards-face-up 0 (cons slot-id '()))
	       #t)
	   (if (< slot-id 25)
	       (fill-it-up (+ slot-id 1) spaces)
	       #t)))
	((not (empty-slot? (+ slot-id spaces)))
	 (begin
	   (deal-cards-face-up (+ slot-id spaces) (cons slot-id '()))
	   (if (< slot-id 25)
	       (fill-it-up (+ slot-id 1) spaces)
	       #t)))
	(#t
	 (fill-it-up slot-id (+ 1 spaces)))))

101 102 103 104 105 106 107 108 109 110 111 112 113
(define (droppable? start-slot card-list end-slot)
  (let ((dx (- (modulo (- start-slot 1) 5)
               (modulo (- end-slot 1) 5)))
        (dy (- (quotient (- start-slot 1) 5)
               (quotient (- end-slot 1) 5))))
       (and (not (= start-slot end-slot))
            (not (= end-slot 0))
            (not (empty-slot? end-slot))
            (= 13 (+ (get-value (car card-list))
                     (get-value (get-top-card end-slot))))
            (member dx '(-1 0 1))
            (member dy '(-1 0 1)))))

114
(define (button-released start-slot card-list end-slot)
115 116 117 118
  (and (droppable? start-slot card-list end-slot)
       (add-to-score! +2)
       (remove-card end-slot)
       (fill-it-up (min start-slot end-slot) 1)))
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
	 
(define (button-clicked slot-id)  
  (if (and (not (empty-slot? slot-id))
	   (= (get-value (get-top-card slot-id)) king))
      (begin
	(add-to-score! +1)
	(remove-card slot-id)
	(fill-it-up slot-id 1))
      #f))

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

(define (game-won)
  (empty-slot? 1))

(define (game-over)
136
  (give-status-message)
137 138 139
  (and (not (game-won))
       (get-hint)))

140 141 142 143 144 145
(define (hint-remove-king suit)
  (cond ((eq? suit club) (_"Remove the king of clubs."))
        ((eq? suit diamond) (_"Remove the king of diamonds."))
        ((eq? suit heart) (_"Remove the king of hearts."))
        ((eq? suit spade) (_"Remove the king of spades."))))

146 147
(define (king-check slot-id)
  (cond ((= king (get-value (get-top-card slot-id)))
148
	 (hint-click slot-id (hint-remove-king (get-suit (get-top-card slot-id)))))
149 150 151 152 153 154 155 156 157
	((and (< slot-id 25)
	      (not (empty-slot? (+ 1 slot-id))))
	 (king-check (+ 1 slot-id)))
	(#t #f)))

(define (horizontal-check slot-id)
  (cond ((and (not (= 0 (modulo slot-id 5)))
	      (= 13 (+ (get-value (get-top-card slot-id))
		       (get-value (get-top-card (+ 1 slot-id))))))
158
	 (hint-move slot-id 1 (+ 1 slot-id)))
159 160 161 162 163 164 165 166
	((and (< slot-id 24)
	      (not (empty-slot? (+ 2 slot-id))))
	 (horizontal-check (+ 1 slot-id)))
	(#t #f)))

(define (vertical-check slot-id)
  (cond ((= 13 (+ (get-value (get-top-card slot-id))
		  (get-value (get-top-card (+ 5 slot-id)))))
167
	 (hint-move slot-id 1 (+ 5 slot-id)))
168 169 170 171 172 173 174 175 176
	((and (< slot-id 19)
	      (not (empty-slot? (+ 6 slot-id))))
	 (vertical-check (+ 1 slot-id)))
	(#t #f)))	       

(define (backslash-check slot-id)
  (cond ((and (not (= 0 (modulo slot-id 5)))
	      (= 13 (+ (get-value (get-top-card slot-id))
		       (get-value (get-top-card (+ 6 slot-id))))))
177
	 (hint-move slot-id 1 (+ 6 slot-id)))
178 179 180 181 182 183 184 185 186
	((and (not (empty-slot? (+ 7 slot-id)))
	      (< slot-id 18))
	 (backslash-check (+ 1 slot-id)))
	(#t #f)))

(define (slash-check slot-id)
  (cond ((and (not (= 1 (modulo slot-id 5)))
	      (= 13 (+ (get-value (get-top-card slot-id))
		       (get-value (get-top-card (+ 4 slot-id))))))
187
	 (hint-move slot-id 1 (+ 4 slot-id)))
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
	((and (< slot-id 19)
	      (not (empty-slot? (+ 5 slot-id))))
	 (slash-check (+ 1 slot-id)))
	(#t #f)))

(define (get-hint)
  (or (king-check 1)
      (and (not (empty-slot? 2))
	   (horizontal-check 1))
      (and (not (empty-slot? 6))
	   (vertical-check 1))
      (and (not (empty-slot? 7))
	   (backslash-check 1))
      (and (not (empty-slot? 6))
	   (slash-check 2))))

(define (get-options) #f)

(define (apply-options options) #f)

(define (timeout) #f)

210 211 212
(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?)