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

  1. ; AisleRiot - bakers_game.scm
  2. ; Copyright (C) 2001, 2003 Rosanna Yuen <zana@webwynk.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. (def-save-var free-reserves 0)
  20.  
  21. (define (new-game)
  22.   (initialize-playing-area)
  23.   (set-ace-low)
  24.   (make-standard-deck)
  25.   (shuffle-deck)
  26.  
  27.   (add-normal-slot DECK)
  28.   (add-carriage-return-slot)
  29.   (add-normal-slot '())
  30.   (add-carriage-return-slot)
  31.   (add-normal-slot '())
  32.   (add-carriage-return-slot)
  33.   (add-normal-slot '())
  34.  
  35.  
  36.   (set! VERTPOS 0)
  37.  
  38.   (add-blank-slot)
  39.   (add-normal-slot '())
  40.   (add-normal-slot '())
  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.  
  48.   (add-carriage-return-slot)
  49.  
  50.   (add-blank-slot)
  51.   (add-blank-slot)
  52.  
  53.   (add-extended-slot '() down)
  54.   (add-extended-slot '() down)
  55.   (add-extended-slot '() down)
  56.   (add-extended-slot '() down)
  57.   (add-extended-slot '() down)
  58.   (add-extended-slot '() down)
  59.   (add-extended-slot '() down)
  60.   (add-extended-slot '() down)
  61.  
  62.   (deal-cards-face-up 0 '(12 13 14 15 16 17 18 19 12 13 14 15 16 17 18
  63.                  19 12 13 14 15 16 17 18 19 12 13 14 15 16
  64.                  17 18 19 12 13 14 15 16 17 18 19 12 13 14 
  65.                  15 16 17 18 19 4 5 6 7))
  66.  
  67.   (set! free-reserves 4)
  68.  
  69.   (list 10 4))
  70.  
  71. (define (button-pressed slot-id card-list)
  72.   (and (not (empty-slot? slot-id))
  73.        (or (= (length card-list) 1)
  74.        (and (> slot-id 11)
  75.         (< (length card-list) (+ 2 free-reserves))
  76.         (check-same-suit-list card-list)
  77.         (check-straight-descending-list card-list)))))
  78.  
  79. (define (droppable? start-slot card-list end-slot)
  80.   (cond ((= start-slot end-slot)
  81.      #f)
  82.     ((> end-slot 11)
  83.      (and (or (and (empty-slot? end-slot)
  84.                (= (get-value (car (reverse card-list)))
  85.               king))
  86.           (and (not (empty-slot? end-slot))
  87.                (= (get-suit (get-top-card end-slot))
  88.               (get-suit (car card-list)))
  89.                (= (get-value (get-top-card end-slot))
  90.               (+ 1 (get-value (car (reverse card-list)))))))))
  91.     ((and (= (length card-list) 1)
  92.           (empty-slot? end-slot)
  93.           (> end-slot 3)
  94.           (< end-slot 12))
  95.      #t)
  96.     ((and (= (length card-list) 1)
  97.           (< end-slot 4))
  98.      (and (or (and (empty-slot? end-slot)
  99.                (= (get-value (car card-list)) ace))
  100.           (and (not (empty-slot? end-slot))
  101.                (= (get-suit (get-top-card end-slot))
  102.               (get-suit (car card-list)))
  103.                (= (+ 1 (get-value (get-top-card end-slot)))
  104.               (get-value (car card-list)))))))
  105.     (#t #f)))
  106.  
  107. (define (button-released start-slot card-list end-slot)
  108.   (and (droppable? start-slot card-list end-slot)
  109.        (move-n-cards! start-slot end-slot card-list)
  110.        (or (< start-slot 4)
  111.            (> start-slot 11)
  112.            (set! free-reserves (+ free-reserves 1)))
  113.        (or (< end-slot 4)
  114.            (> end-slot 11)
  115.            (set! free-reserves (- free-reserves 1)))
  116.        (or (> start-slot 3)
  117.            (add-to-score! -1))
  118.        (or (> end-slot 3)
  119.            (add-to-score! 1))))
  120.  
  121. (define (button-clicked slot-id)
  122.   #f)
  123.  
  124. (define (move-to-empty-foundation slot f-slot)
  125.   (cond ((= f-slot 4)
  126.      #f)
  127.     ((empty-slot? f-slot)
  128.      (deal-cards slot (list f-slot)))
  129.     (#t (move-to-empty-foundation slot (+ 1 f-slot)))))
  130.  
  131. (define (move-to-foundation slot f-slot)
  132.   (cond ((= f-slot 4)
  133.      #f)
  134.     ((and (not (empty-slot? f-slot))
  135.           (= (get-suit (get-top-card slot))
  136.          (get-suit (get-top-card f-slot))))
  137.      (and (= (get-value (get-top-card slot))
  138.          (+ 1 (get-value (get-top-card f-slot))))
  139.           (deal-cards slot (list f-slot))))
  140.     (#t (move-to-foundation slot (+ 1 f-slot)))))
  141.  
  142. (define (button-double-clicked slot-id)
  143.   (and (not (empty-slot? slot-id))
  144.        (> slot-id 3)
  145.        (or (and (= (get-value (get-top-card slot-id))
  146.            ace)
  147.         (move-to-empty-foundation slot-id 0))
  148.        (move-to-foundation slot-id 0))
  149.        (add-to-score! 1)
  150.        (or (> slot-id 11)
  151.        (set! free-reserves (+ 1 free-reserves)))))
  152.  
  153. (define (game-continuable)
  154.   (and (not (game-won))
  155.        (get-hint)))
  156.  
  157. (define (game-won)
  158.   (and (= (length (get-cards 0)) 13)
  159.        (= (length (get-cards 1)) 13)
  160.        (= (length (get-cards 2)) 13)
  161.        (= (length (get-cards 3)) 13)))
  162.  
  163. (define (check-to-foundations? slot f-slot)
  164.   (cond ((= slot 20)
  165.      #f)
  166.     ((or (empty-slot? slot)
  167.          (= f-slot 4))
  168.      (check-to-foundations? (+ 1 slot) 0))
  169.     ((= (get-value (get-top-card slot)) ace)
  170.      (list 2 (get-name (get-top-card slot)) (_"an empty foundation")))
  171.     ((and (not (empty-slot? f-slot))
  172.           (= (get-suit (get-top-card slot))
  173.          (get-suit (get-top-card f-slot)))
  174.           (= (get-value (get-top-card slot))
  175.          (+ 1 (get-value (get-top-card f-slot)))))
  176.      (list 1 (get-name (get-top-card slot)) (get-name (get-top-card f-slot))))
  177.     (#t (check-to-foundations? slot (+ 1 f-slot)))))
  178.  
  179. (define (check-for-king card-list iter slot)
  180.   (cond ((= (length card-list) 0)
  181.      #f)
  182.     ((and (= (length card-list) 1)
  183.           (> slot 11))
  184.      #f)
  185.     ((= (get-value (car card-list)) king)
  186.      (get-name (car card-list)))
  187.     ((= iter 0)
  188.      #f)
  189.     ((and (> (length card-list)1)
  190.           (= (get-suit (car card-list))
  191.          (get-suit (cadr card-list)))
  192.           (= (+ 1 (get-value (car card-list)))
  193.          (get-value (cadr card-list))))
  194.      (check-for-king (cdr card-list) (- iter 1) slot))
  195.     (#t #f)))
  196.  
  197. (define (check-for-spec-card card-list iter value)
  198.   (cond ((= (length card-list) 0)
  199.      #f)
  200.     ((= (get-value (car card-list)) value)
  201.      #t)
  202.     ((= iter 0)
  203.      #f)
  204.     ((and (> (length card-list) 1)
  205.           (= (get-suit (car card-list))
  206.          (get-suit (cadr card-list)))
  207.           (= (+ 1 (get-value (car card-list)))
  208.          (get-value (cadr card-list))))
  209.      (check-for-spec-card (cdr card-list) (- iter 1) value))
  210.     (#t #f)))
  211.  
  212. (define (check-to-tableau? slot t-slot)
  213.   (cond ((= slot 20)
  214.      #f)
  215.     ((or (empty-slot? slot)
  216.          (= t-slot 20))
  217.      (check-to-tableau? (+ 1 slot) 12))
  218.     ((and (not (= slot t-slot))
  219.           (empty-slot? t-slot)
  220.           (check-for-king (get-cards slot) free-reserves slot))
  221.      (list 2 
  222.            (check-for-king (get-cards slot) free-reserves slot) 
  223.            (_"an empty tableau")))
  224.     ((and (not (= slot t-slot))
  225.           (not (empty-slot? t-slot))
  226.           (= (get-suit (get-top-card slot))
  227.          (get-suit (get-top-card t-slot)))
  228.           (check-for-spec-card (get-cards slot) 
  229.                    free-reserves 
  230.                    (- (get-value (get-top-card t-slot)) 1)))
  231.      (list 1 
  232.            (get-name (make-card (- (get-value (get-top-card t-slot)) 1)
  233.                     (get-suit (get-top-card t-slot))))
  234.            (get-name (get-top-card t-slot))))
  235.     (#t (check-to-tableau? slot (+ 1 t-slot)))))
  236.  
  237. (define (check-for-empty-reserve)
  238.   (and (> free-reserves 0)
  239.        (list 0 (_"Move something on to an empty reserve"))))
  240.  
  241. (define (get-hint)
  242.   (or (check-to-foundations? 4 0)
  243.       (check-to-tableau? 4 12)
  244.       (check-for-empty-reserve)))
  245.  
  246. (define (get-options) 
  247.   #f)
  248.  
  249. (define (apply-options options) 
  250.   #f)
  251.  
  252. (define (timeout) 
  253.   #f)
  254.  
  255. (set-features droppable-feature)
  256.  
  257. (set-lambda new-game button-pressed button-released button-clicked
  258. button-double-clicked game-continuable game-won get-hint get-options
  259. apply-options timeout droppable?)
  260.