home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / sol-games / cruel.scm < prev    next >
Encoding:
Text File  |  2006-08-22  |  6.2 KB  |  238 lines

  1. ; AisleRiot - cruel.scm
  2. ; Copyright (C) 2005 Zach Keene <zjkeene@bellsouth.net>
  3. ;
  4. ; This game 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 2, or (at your option)
  7. ; 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, write to the Free Software
  16. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  17. ; USA
  18.  
  19. (define stock 0)
  20. (define foundations '(1 2 3 4))
  21. (define from-list '(5 6 7 8 9 10 11 12 13 14 15 16))
  22. (define to-list '(1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16))
  23. (define original-to-slots '())
  24.  
  25. (def-save-var just-redealt #t)
  26.  
  27. (define (new-game)
  28.   (initialize-playing-area)
  29.   (set-ace-low)
  30.   (make-standard-deck)
  31.   (shuffle-deck)
  32.  
  33.   (add-normal-slot '())
  34.   (add-blank-slot)
  35.   (add-normal-slot '())
  36.   (add-normal-slot '())
  37.   (add-normal-slot '())
  38.   (add-normal-slot '())
  39.   (add-carriage-return-slot)
  40.  
  41.   (add-normal-slot '())
  42.   (add-normal-slot '())
  43.   (add-normal-slot '())
  44.   (add-normal-slot '())
  45.   (add-normal-slot '())
  46.   (add-normal-slot '())
  47.   (add-carriage-return-slot)
  48.  
  49.   (add-normal-slot '())
  50.   (add-normal-slot '())  
  51.   (add-normal-slot '())
  52.   (add-normal-slot '())
  53.   (add-normal-slot '())
  54.   (add-normal-slot '())
  55.  
  56.   (set-cards! stock (remove-aces DECK foundations '()))
  57.   (set! just-redealt #t)
  58.   (cruel-deal 0)
  59.   (give-status)
  60.   (list 6 3)
  61. )
  62.  
  63. (define (remove-aces cards foundation-ids remaining-cards)
  64.   (if (eq? cards '())
  65.       remaining-cards
  66.       (if (= (get-value (car cards)) ace)
  67.           (and (move-n-cards! stock (car foundation-ids) (list (make-visible (car cards))))
  68.                (remove-aces (cdr cards) (cdr foundation-ids) remaining-cards))
  69.           (remove-aces (cdr cards) foundation-ids (cons (car cards) remaining-cards)))))
  70.  
  71. (define (cruel-deal count)
  72.   (if (not (empty-slot? stock))
  73.     (begin
  74.       (deal-cards-face-up stock (list (+ 5 (quotient count 4))))
  75.       (cruel-deal (+ 1 count))
  76.     )
  77.   )
  78. )
  79.  
  80. (define (button-pressed slot-id card-list)
  81.   (and (not (empty-slot? slot-id))
  82.        (> slot-id 4)
  83.   )
  84. )
  85.  
  86. (define (droppable? start-slot card-list end-slot)
  87.   (if (< end-slot 5) 
  88.     (and (not (= end-slot stock))
  89.          (= (get-suit(get-top-card end-slot)) (get-suit(car card-list)))
  90.          (= (+ 1 (get-value(get-top-card end-slot))) (get-value(car card-list)))
  91.     )
  92.     (and (not (empty-slot? end-slot))
  93.          (= (get-suit(get-top-card end-slot)) (get-suit(car card-list)))
  94.          (= (- (get-value(get-top-card end-slot)) 1) (get-value(car card-list)))
  95.     )
  96.   )
  97. )
  98.  
  99. (define (button-released start-slot card-list end-slot)
  100.   (and (not (empty-slot? end-slot))
  101.        (droppable? start-slot card-list end-slot)
  102.        (move-n-cards! start-slot end-slot card-list)
  103.        (set! just-redealt #f)
  104.        (if (< end-slot 5)
  105.           (add-to-score! 1)
  106.        )
  107.   )
  108. )
  109.  
  110. (define (button-clicked slot-id)
  111.   (if (= stock slot-id)
  112.       (redeal)
  113.       #f
  114.   )
  115. )
  116.  
  117. (define (redeal) 
  118.   (for-each
  119.     (lambda (x)
  120.       (if (not (empty-slot? x))
  121.          (flip-deck stock x)
  122.       )
  123.     )
  124.     '(16 15 14 13 12 11 10 9 8 7 6 5)
  125.   )
  126.   (cruel-deal 0)
  127.   (set! just-redealt #t)
  128. )
  129.  
  130. (define (button-double-clicked slot-id)
  131.   (if (and (not (empty-slot? slot-id)) (> slot-id 4))
  132.       (attempt-foundation slot-id foundations)
  133.       #f
  134.   )
  135. )
  136.  
  137. (define (attempt-foundation start-slot end-slots)
  138.   (if (null? end-slots)
  139.       #f
  140.       (if (button-released start-slot
  141.                            (list (get-top-card start-slot))
  142.                            (car end-slots)
  143.           )
  144.           (remove-card start-slot)
  145.           (attempt-foundation start-slot (cdr end-slots))
  146.       )
  147.   )
  148. )
  149.  
  150. (define (give-status)
  151.   (set-statusbar-message (format (_ "Cards remaining: ~a") 
  152.                  (number->string (- 48 (get-score)))))
  153.                          
  154. )
  155.  
  156. (define (game-continuable)
  157.   (give-status)
  158.   (and (not (game-won))
  159.        (or (not just-redealt) (check-moves from-list to-list))
  160.        (not (headbanger?))
  161.   )
  162. )
  163.  
  164. (define (count x y) 
  165.   (if (< x y) 
  166.       (cons x (count (+ x 1) y)) 
  167.       (cons x '()))
  168. )
  169.  
  170. ; Detects the case where, after a redeal, the only possible move is from the
  171. ; last pile to the next-to-last pile when the last pile only contains one
  172. ; card. After this move, the only thing left to do is redeal again, which
  173. ; just leaves us where we started.
  174. (define (headbanger?) 
  175.   (define last-slot (+ 5 (quotient (- 48 (get-score)) 4)))
  176.   (and (not (= 47 (get-score)))
  177.        just-redealt
  178.        (= 1 (modulo (- 48 (get-score)) 4))
  179.        (droppable? last-slot (list (get-top-card last-slot)) (- last-slot 1))
  180.        (not (check-moves (count 5 (- last-slot 1)) to-list))
  181.   )
  182. )
  183.  
  184. (define (game-won)
  185.   (and (= 13 (length (get-cards 1)))
  186.        (= 13 (length (get-cards 2)))
  187.        (= 13 (length (get-cards 3)))
  188.        (= 13 (length (get-cards 4)))
  189.   )
  190. )
  191.  
  192. (define (get-hint)
  193.   (or (check-moves from-list to-list)
  194.       (list 0 (_"Redeal."))
  195.   )
  196. )
  197.  
  198. (define (check-moves from-slots to-slots)
  199.   (set! original-to-slots to-slots)
  200.   (check-move-helper from-slots to-slots)
  201. )
  202.  
  203. (define (check-move-helper from-slots to-slots)
  204.   (if (null? from-slots)
  205.       #f
  206.       (if (null? to-slots)
  207.           (check-move-helper (cdr from-slots) original-to-slots)
  208.           (if (and (not (empty-slot? (car from-slots)))
  209.                    (not (= (car from-slots) (car to-slots)))
  210.                    (droppable? (car from-slots) 
  211.                                (list (get-top-card(car from-slots)))
  212.                                (car to-slots)
  213.                    )
  214.                )              
  215.                (list 1 (get-name(get-top-card(car from-slots))) 
  216.                        (get-name(get-top-card(car to-slots)))
  217.                )
  218.                (check-move-helper from-slots (cdr to-slots))
  219.           )
  220.       )
  221.   )
  222. )
  223.  
  224. (define (get-options) 
  225.   #f)
  226.  
  227. (define (apply-options options) 
  228.   #f)
  229.  
  230. (define (timeout) 
  231.   #f)
  232.  
  233. (set-features droppable-feature)
  234.  
  235. (set-lambda new-game button-pressed button-released button-clicked
  236. button-double-clicked game-continuable game-won get-hint get-options
  237. apply-options timeout droppable?)
  238.