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

  1. ; AisleRiot - seahaven.scm
  2. ; Copyright (C) 2001 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 foundation '(0 1 6 7))
  22. (define freecells '(2 3 4 5))
  23. (define tableau '(8 9 10 11 12 13 14 15 16 17))
  24.  
  25. (define (new-game)
  26.   (initialize-playing-area)
  27.   (set-ace-low)
  28.   (make-standard-deck)
  29.   (shuffle-deck)
  30.  
  31.   (add-normal-slot DECK)
  32.   (add-normal-slot '())
  33.  
  34.   (add-blank-slot)
  35.  
  36.   (add-normal-slot '())
  37.   (add-normal-slot '())
  38.   (add-normal-slot '())
  39.   (add-normal-slot '())
  40.  
  41.   (add-blank-slot)
  42.  
  43.   (add-normal-slot '())
  44.   (add-normal-slot '())
  45.  
  46.   (add-carriage-return-slot)
  47.  
  48.   (add-extended-slot '() down)
  49.   (add-extended-slot '() down)
  50.   (add-extended-slot '() down)
  51.   (add-extended-slot '() down)
  52.   (add-extended-slot '() down)
  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.  
  59.   (deal-cards-face-up 0 '(8 9 10 11 12 13 14 15 16 17 8 9 10 11 12 13
  60.                 14 15 16 17 8 9 10 11 12 13 14 15 16 17 8
  61.                 9 10 11 12 13 14 15 16 17 8 9 10 11 12 13 
  62.                 14 15 16 17 3 4))
  63.  
  64.   (set! free-reserves 2)
  65.  
  66.   (list 10 4))
  67.  
  68. (define (sequence-matches-slot? card-list slot)
  69.   (and (not (empty-slot? slot))
  70.        (= (get-suit (car card-list))
  71.       (get-suit (get-top-card slot)))
  72.        (= (get-value (car card-list))
  73.       (+ 1 (get-value (get-top-card slot))))))
  74.  
  75. (define (button-pressed slot-id card-list)
  76.   (and (not (empty-slot? slot-id))
  77.        (or (= (length card-list) 1)
  78.        (and (> slot-id 7)
  79.         (< (length card-list) (+ 2 free-reserves))
  80.         (check-same-suit-list card-list)
  81.         (check-straight-descending-list card-list))
  82.        (and (> slot-id 7) ; Move an entire sequence to the foundation
  83.         (check-same-suit-list card-list)
  84.         (check-straight-descending-list card-list)
  85.         (or (sequence-matches-slot? card-list 0)
  86.             (sequence-matches-slot? card-list 1)
  87.             (sequence-matches-slot? card-list 6)
  88.             (sequence-matches-slot? card-list 7))))))
  89.  
  90. (define (droppable? start-slot card-list end-slot)
  91.   (cond ((= start-slot end-slot)
  92.      #f)
  93.     ((> end-slot 7) ; The tableau
  94.      (and (or (and (empty-slot? end-slot)
  95.                (= (get-value (car (reverse card-list)))
  96.               king))
  97.           (and (not (empty-slot? end-slot))
  98.                (= (get-suit (get-top-card end-slot))
  99.               (get-suit (car card-list)))
  100.                (= (get-value (get-top-card end-slot))
  101.               (+ 1 (get-value (car (reverse card-list)))))))
  102.           (or (> start-slot 7)
  103.           (and (> start-slot 1)
  104.                (< start-slot 6)))))
  105.     ((and (> end-slot 1) ; The free reserves
  106.           (< end-slot 6))
  107.      (and (= (length card-list) 1)
  108.           (empty-slot? end-slot)))
  109.     (else ; otherwise it is the foundations
  110.      (cond ((empty-slot? end-slot) 
  111.         (= (get-value (car card-list)) ace))
  112.            (else
  113.         (and (= (get-suit (get-top-card end-slot))
  114.             (get-suit (car card-list)))
  115.              (= (+ 1 (get-value (get-top-card end-slot)))
  116.             (get-value (car card-list)))))))))
  117.  
  118. (define (button-released start-slot card-list end-slot)
  119.   (cond ((= start-slot end-slot)
  120.      #f)
  121.     ((> end-slot 7)
  122.      (and (or (and (empty-slot? end-slot)
  123.                (= (get-value (car (reverse card-list)))
  124.               king)
  125.                (move-n-cards! start-slot end-slot card-list))
  126.           (and (not (empty-slot? end-slot))
  127.                (= (get-suit (get-top-card end-slot))
  128.               (get-suit (car card-list)))
  129.                (= (get-value (get-top-card end-slot))
  130.               (+ 1 (get-value (car (reverse card-list)))))
  131.                (move-n-cards! start-slot end-slot card-list)))
  132.           (or (> start-slot 7)
  133.           (and (> start-slot 1)
  134.                (< start-slot 6)
  135.                (set! free-reserves (+ 1 free-reserves)))
  136.           (add-to-score! -1))))
  137.     ((and (= (length card-list) 1)
  138.           (empty-slot? end-slot)
  139.           (> end-slot 1)
  140.           (< end-slot 6))
  141.      (and (move-n-cards! start-slot end-slot card-list)
  142.           (or (and (> start-slot 1)
  143.                (< start-slot 6))
  144.           (set! free-reserves (- free-reserves 1)))))
  145.     ((and (= (length card-list) 1)
  146.           (or (< end-slot 2)
  147.           (and (> end-slot 5)
  148.                (< end-slot 8))))
  149.      (and (or (and (empty-slot? end-slot)
  150.                (= (get-value (car card-list)) ace))
  151.           (and (not (empty-slot? end-slot))
  152.                (= (get-suit (get-top-card end-slot))
  153.               (get-suit (car card-list)))
  154.                (= (+ 1 (get-value (get-top-card end-slot)))
  155.               (get-value (car card-list)))))
  156.           (move-n-cards! start-slot end-slot card-list)
  157.           (or (and (> start-slot 7)
  158.                (add-to-score! 1))
  159.           (and (> start-slot 1)
  160.                (< start-slot 6)
  161.                (set! free-reserves (+ free-reserves 1))
  162.                (add-to-score! 1))
  163.           #t)))
  164.     ((and (or (< end-slot 2) ; Move an entire sequence to the foundation
  165.           (= end-slot 6)
  166.           (= end-slot 7))
  167.           (check-same-suit-list card-list)
  168.           (check-straight-descending-list card-list)
  169.           (sequence-matches-slot? card-list end-slot)) 
  170.      (and (move-n-cards! start-slot end-slot (reverse card-list))
  171.           (add-to-score! (length card-list))
  172.           #t))
  173.     (#t #f)))
  174.  
  175. (define (button-clicked slot-id)
  176.   #f)
  177.  
  178. (define (move-to-empty-foundation slot f-slot)
  179.   (cond ((= f-slot 2)
  180.      (move-to-empty-foundation slot 6))
  181.     ((= f-slot 8)
  182.      #f)
  183.     ((empty-slot? f-slot)
  184.      (deal-cards slot (list f-slot)))
  185.     (#t (move-to-empty-foundation slot (+ 1 f-slot)))))
  186.  
  187. (define (move-to-foundation slot f-slot)
  188.   (cond ((= f-slot 2)
  189.      (move-to-foundation slot 6))
  190.     ((= f-slot 8)
  191.      #f)
  192.     ((and (not (empty-slot? f-slot))
  193.           (= (get-suit (get-top-card slot))
  194.          (get-suit (get-top-card f-slot))))
  195.      (and (= (get-value (get-top-card slot))
  196.          (+ 1 (get-value (get-top-card f-slot))))
  197.           (deal-cards slot (list f-slot))))
  198.     (#t (move-to-foundation slot (+ 1 f-slot)))))
  199.  
  200. (define (autoplay-foundations)
  201.   (define (autoplay-foundations-tail)
  202.     (if (or-map button-double-clicked (append freecells tableau))
  203.         (delayed-call autoplay-foundations-tail)
  204.         #t))
  205.   (if (or-map button-double-clicked (append freecells tableau))
  206.       (autoplay-foundations-tail)
  207.       #f))
  208.  
  209. (define (button-double-clicked slot-id)
  210.   (or (and (member slot-id foundation)
  211.        (autoplay-foundations))
  212.       (and (not (empty-slot? slot-id))
  213.        (> slot-id 1)
  214.        (or (< slot-id 6)
  215.            (> slot-id 7))
  216.        (or (and (= (get-value (get-top-card slot-id))
  217.                ace)
  218.             (move-to-empty-foundation slot-id 0))
  219.            (move-to-foundation slot-id 0))
  220.        (add-to-score! 1)
  221.        (or (> slot-id 7)
  222.            (set! free-reserves (+ 1 free-reserves))))))
  223.  
  224. (define (game-continuable)
  225.   (and (not (game-won))
  226.        (get-hint)))
  227.  
  228. (define (game-won)
  229.   (and (= (length (get-cards 0)) 13)
  230.        (= (length (get-cards 1)) 13)
  231.        (= (length (get-cards 6)) 13)
  232.        (= (length (get-cards 7)) 13)))
  233.  
  234. (define (check-to-foundations? slot f-slot)
  235.   (cond ((= slot 18)
  236.      #f)
  237.     ((= slot 6)
  238.      (check-to-foundations? 8 0))
  239.     ((= f-slot 2)
  240.      (check-to-foundations? slot 6))
  241.     ((or (empty-slot? slot)
  242.          (= f-slot 8))
  243.      (check-to-foundations? (+ 1 slot) 0))
  244.     ((= (get-value (get-top-card slot)) ace)
  245.      (list 2 (get-name (get-top-card slot)) (_"an empty foundation")))
  246.     ((and (not (empty-slot? f-slot))
  247.           (= (get-suit (get-top-card slot))
  248.          (get-suit (get-top-card f-slot)))
  249.           (= (get-value (get-top-card slot))
  250.          (+ 1 (get-value (get-top-card f-slot)))))
  251.      (list 1 (get-name (get-top-card slot)) (get-name (get-top-card f-slot))))
  252.     (#t (check-to-foundations? slot (+ 1 f-slot)))))
  253.  
  254. (define (check-for-king card-list iter slot)
  255.   (cond ((= (length card-list) 0)
  256.      #f)
  257.     ((and (= (length card-list) 1)
  258.           (> slot 7))
  259.      #f)
  260.     ((= (get-value (car card-list)) king)
  261.      (get-name (car card-list)))
  262.     ((= iter 0)
  263.      #f)
  264.     ((and (> (length card-list)1)
  265.           (= (get-suit (car card-list))
  266.          (get-suit (cadr card-list)))
  267.           (= (+ 1 (get-value (car card-list)))
  268.          (get-value (cadr card-list))))
  269.      (check-for-king (cdr card-list) (- iter 1) slot))
  270.     (#t #f)))
  271.  
  272. (define (check-for-spec-card card-list iter value)
  273.   (cond ((= (length card-list) 0)
  274.      #f)
  275.     ((= (get-value (car card-list)) value)
  276.      #t)
  277.     ((= iter 0)
  278.      #f)
  279.     ((and (> (length card-list) 1)
  280.           (= (get-suit (car card-list))
  281.          (get-suit (cadr card-list)))
  282.           (= (+ 1 (get-value (car card-list)))
  283.          (get-value (cadr card-list))))
  284.      (check-for-spec-card (cdr card-list) (- iter 1) value))
  285.     (#t #f)))
  286.  
  287. (define (check-to-tableau? slot t-slot)
  288.   (cond ((= slot 18)
  289.      #f)
  290.     ((= slot 6)
  291.      (check-to-tableau? 8 9))
  292.     ((or (empty-slot? slot)
  293.          (= t-slot 18))
  294.      (check-to-tableau? (+ 1 slot) 8))
  295.     ((and (not (= slot t-slot))
  296.           (empty-slot? t-slot)
  297.           (check-for-king (get-cards slot) free-reserves slot))
  298.      (list 2 
  299.            (check-for-king (get-cards slot) free-reserves slot) 
  300.            (_"an empty tableau")))
  301.     ((and (not (= slot t-slot))
  302.           (not (empty-slot? t-slot))
  303.           (= (get-suit (get-top-card slot))
  304.          (get-suit (get-top-card t-slot)))
  305.           (check-for-spec-card (get-cards slot) 
  306.                    free-reserves 
  307.                    (- (get-value (get-top-card t-slot)) 1)))
  308.      (list 1 
  309.            (get-name (make-card (- (get-value (get-top-card t-slot)) 1)
  310.                     (get-suit (get-top-card t-slot))))
  311.            (get-name (get-top-card t-slot))))
  312.     (#t (check-to-tableau? slot (+ 1 t-slot)))))
  313.  
  314. (define (check-for-empty-reserve)
  315.   (and (> free-reserves 0)
  316.        (list 0 (_"Move something on to an empty reserve"))))
  317.  
  318. (define (get-hint)
  319.   (or (check-to-foundations? 2 0)
  320.       (check-to-tableau? 2 8)
  321.       (check-for-empty-reserve)))
  322.  
  323. (define (get-options) 
  324.   #f)
  325.  
  326. (define (apply-options options) 
  327.   #f)
  328.  
  329. (define (timeout) 
  330.   #f)
  331.  
  332. (set-features droppable-feature)
  333.  
  334. (set-lambda new-game button-pressed button-released button-clicked
  335. button-double-clicked game-continuable game-won get-hint get-options
  336. apply-options timeout droppable?)
  337.