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

  1. ; AisleRiot - yukon.scm
  2. ; Copyright (C) 1998, 2003 Rosanna Yuen <rwsy@mit.edu>
  3. ; This game is free software; you can redistribute it and/or modify
  4. ; it under the terms of the GNU General Public License as published by
  5. ; the Free Software Foundation; either version 2, or (at your option)
  6. ; any later version.
  7. ;
  8. ; This program is distributed in the hope that it will be useful,
  9. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. ; GNU General Public License for more details.
  12. ;
  13. ; You should have received a copy of the GNU General Public License
  14. ; along with this program; if not, write to the Free Software
  15. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  16. ; USA
  17.  
  18.  
  19. (define (new-game)
  20.   (initialize-playing-area)
  21.  
  22.                     ;set up the cards
  23.   (make-standard-deck)
  24.   (shuffle-deck)
  25.   
  26.                     ;set up the board
  27.   (add-normal-slot DECK)
  28.   (add-blank-slot)
  29.   (add-extended-slot '() down)
  30.   (add-extended-slot '() down)
  31.   (add-extended-slot '() down)
  32.   (add-extended-slot '() down)
  33.   (add-extended-slot '() down)
  34.   (add-extended-slot '() down)
  35.   (add-extended-slot '() down)
  36.   (add-carriage-return-slot)
  37.   (add-normal-slot '())
  38.   (add-carriage-return-slot)
  39.   (add-normal-slot '())
  40.   (add-carriage-return-slot)
  41.   (add-normal-slot '())
  42.  
  43.  
  44.   (deal-cards 0 '(1 2 3 4 5 6 7 2 3 4 5 6 7 3 4 5 6 7 4 5 6 7 5 6 7 6 7 7))
  45.  
  46.   (flip-top-card 1)
  47.   (flip-top-card 2)
  48.   (flip-top-card 3)
  49.   (flip-top-card 4)
  50.   (flip-top-card 5)
  51.   (flip-top-card 6)
  52.   (flip-top-card 7)
  53.  
  54.   (deal-cards 0 '(2 3 4 5 6 7))
  55.   (flip-top-card 2)
  56.   (flip-top-card 3)
  57.   (flip-top-card 4)
  58.   (flip-top-card 5)
  59.   (flip-top-card 6)
  60.   (flip-top-card 7)
  61.   (deal-cards 0 '(2 3 4 5 6 7))
  62.   (flip-top-card 2)
  63.   (flip-top-card 3)
  64.   (flip-top-card 4)
  65.   (flip-top-card 5)
  66.   (flip-top-card 6)
  67.   (flip-top-card 7)
  68.   (deal-cards 0 '(2 3 4 5 6 7))
  69.   (flip-top-card 2)
  70.   (flip-top-card 3)
  71.   (flip-top-card 4)
  72.   (flip-top-card 5)
  73.   (flip-top-card 6)
  74.   (flip-top-card 7)
  75.   (deal-cards 0 '(2 3 4 5 6 7))
  76.   (flip-top-card 2)
  77.   (flip-top-card 3)
  78.   (flip-top-card 4)
  79.   (flip-top-card 5)
  80.   (flip-top-card 6)
  81.   (flip-top-card 7)
  82.  
  83.   (list 9 4))
  84.  
  85. (define (button-pressed slot-id card-list)
  86.   (if (and card-list
  87.        (> slot-id 0)
  88.        (< slot-id 8)
  89.        (is-visible? (car (reverse card-list))))
  90.       #t
  91.       #f))
  92.       
  93. (define (complete-transaction start-slot card-list end-slot)
  94.   (move-n-cards! start-slot end-slot card-list)
  95.   (if (or (= end-slot 0)
  96.       (> end-slot 7))
  97.       (add-to-score! 1))
  98.   (if (not (empty-slot? start-slot))
  99.       (make-visible-top-card start-slot)))
  100.  
  101. (define (droppable? start-slot card-list end-slot)
  102.   (cond ((= start-slot end-slot) #f)
  103.     ((and (= (length card-list) 1)
  104.           (or (= end-slot 0)
  105.           (> end-slot 7)))
  106.      (cond ((and (= (get-value (car card-list)) ace)
  107.              (empty-slot? end-slot))
  108.         #t)
  109.            ((and (not (empty-slot? end-slot))
  110.              (= (get-suit (get-top-card end-slot))
  111.             (get-suit (car card-list)))
  112.              (= (+ 1 (get-value (get-top-card end-slot)))
  113.             (get-value (car card-list))))
  114.         #t)
  115.            (#t #f)))
  116.     ((and (> end-slot 0)
  117.           (< end-slot 8))
  118.      (cond ((and (empty-slot? end-slot)
  119.              (= (get-value (car (reverse card-list))) king))
  120.         #t)
  121.            ((empty-slot? end-slot) #f)
  122.            ((and (eq? (is-black? (car (reverse card-list)))
  123.               (is-red? (get-top-card end-slot)))
  124.              (= (get-value (get-top-card end-slot))
  125.             (+ 1 (get-value (car (reverse card-list))))))
  126.         #t)
  127.            (#t #f)))
  128.     (#t #f)))
  129.  
  130. (define (button-released start-slot card-list end-slot)
  131.   (and (droppable? start-slot card-list end-slot)
  132.        (complete-transaction start-slot card-list end-slot)))
  133.  
  134. (define (button-clicked slot-id)
  135.   #f)
  136.  
  137. (define (button-double-clicked slot)
  138.   (cond ((or (empty-slot? slot)
  139.          (= slot 0)
  140.          (> slot 7))
  141.      #f)
  142.     ((= (get-value (get-top-card slot)) ace)
  143.      (let ((top-card (get-top-card slot)))
  144.        (remove-card slot)
  145.        (cond ((empty-slot? 0)
  146.           (complete-transaction slot (list top-card) 0))
  147.          ((empty-slot? 8)
  148.           (complete-transaction slot (list top-card) 8))
  149.          ((empty-slot? 9)
  150.           (complete-transaction slot (list top-card) 9))
  151.          (#t
  152.           (complete-transaction slot (list top-card) 10)))))
  153.           ((and (not (empty-slot? 0))
  154.           (= (get-suit (get-top-card 0))
  155.          (get-suit (get-top-card slot)))
  156.           (= (+ 1 (get-value (get-top-card 0)))
  157.          (get-value (get-top-card slot))))
  158.      (let ((top-card (get-top-card slot)))
  159.        (remove-card slot)
  160.        (complete-transaction slot (list top-card) 0)))
  161.     ((and (not (empty-slot? 8))
  162.           (= (get-suit (get-top-card 8))
  163.          (get-suit (get-top-card slot)))
  164.           (= (+ 1 (get-value (get-top-card 8)))
  165.          (get-value (get-top-card slot))))
  166.      (let ((top-card (get-top-card slot)))
  167.        (remove-card slot)
  168.        (complete-transaction slot (list top-card) 8)))
  169.     ((and (not (empty-slot? 9))
  170.           (= (get-suit (get-top-card 9))
  171.          (get-suit (get-top-card slot)))
  172.           (= (+ 1 (get-value (get-top-card 9)))
  173.          (get-value (get-top-card slot))))
  174.      (let ((top-card (get-top-card slot)))
  175.        (remove-card slot)
  176.        (complete-transaction slot (list top-card) 9)))
  177.     ((and (not (empty-slot? 10))
  178.           (= (get-suit (get-top-card 10))
  179.          (get-suit (get-top-card slot)))
  180.           (= (+ 1 (get-value (get-top-card 10)))
  181.          (get-value (get-top-card slot))))
  182.      (let ((top-card (get-top-card slot)))
  183.        (remove-card slot)
  184.        (complete-transaction slot (list top-card) 10)))
  185.     (#t #f)))
  186.  
  187. (define (game-over)
  188.   (and (not (game-won))
  189.        (get-hint)))
  190.  
  191. (define (game-won)
  192.   (if (and (= 13 (length (get-cards 0)))
  193.        (= 13 (length (get-cards 8)))
  194.        (= 13 (length (get-cards 9)))
  195.        (= 13 (length (get-cards 10))))
  196.       #t
  197.       #f))
  198.  
  199. (define (here-kingy-kingy card-list)
  200.   (cond ((or (= (length card-list) 0)
  201.          (= (length card-list) 1)
  202.          (not (is-visible? (car card-list))))
  203.      #f)
  204.     ((= (get-value (car card-list)) king)
  205.      (list 2 (get-name (car card-list)) (_"an empty slot")))
  206.     (#t (here-kingy-kingy (cdr card-list)))))
  207.  
  208. (define (king-avail? slot-id)
  209.   (cond ((= slot-id 8)
  210.      #f)
  211.     ((and (not (empty-slot? slot-id))
  212.           (here-kingy-kingy (get-cards slot-id)))
  213.      (here-kingy-kingy (get-cards slot-id)))
  214.     (#t (king-avail? (+ 1 slot-id)))))
  215.  
  216. (define (check-for-empty)
  217.   (and (or (empty-slot? 1)
  218.        (empty-slot? 2)
  219.        (empty-slot? 3)
  220.        (empty-slot? 4)
  221.        (empty-slot? 5)
  222.        (empty-slot? 6)
  223.        (empty-slot? 7))
  224.        (king-avail? 1)))
  225.  
  226. (define (check-a-foundation card slot-id)
  227.   (cond ((= slot-id 11)
  228.      #f)
  229.     ((= slot-id 1)
  230.      (check-a-foundation card 8))
  231.     ((and (not (empty-slot? slot-id))
  232.           (eq? (get-suit card)
  233.            (get-suit (get-top-card slot-id)))
  234.           (= (get-value card)
  235.          (+ 1 (get-value (get-top-card slot-id)))))
  236.      #t)
  237.     (#t (check-a-foundation card (+ 1 slot-id)))))
  238.  
  239. (define (check-to-foundations? slot-id)
  240.   (cond ((= slot-id 8)
  241.      #f)
  242.     ((empty-slot? slot-id)
  243.      (check-to-foundations? (+ 1 slot-id)))
  244.     ((= (get-value (get-top-card slot-id)) ace)
  245.      (list 2 (get-name (get-top-card slot-id)) (_"an empty foundation")))
  246.     ((check-a-foundation (get-top-card slot-id) 0)
  247.      (list 1 
  248.            (get-name (get-top-card slot-id))
  249.            (get-name (make-card (- (get-value (get-top-card slot-id)) 1)
  250.                     (get-suit (get-top-card slot-id))))))
  251.     (#t (check-to-foundations? (+ 1 slot-id)))))
  252.  
  253. (define (stripped card-list card)
  254.   (if (<= (length card-list) 1)
  255.       '()
  256.       (if (eq? card (car card-list))
  257.       (cdr card-list)
  258.       (if (= (length card-list) 2)
  259.           '()
  260.           (stripped (cdr card-list) card)))))
  261.  
  262. (define (check-a-tableau card slot1 card-list slot2)
  263.   (cond ((or (= (length card-list) 0)
  264.          (not (is-visible? (car card-list))))
  265.      #f)
  266.     ((and (not (eq? (is-red? (car card-list))
  267.             (is-red? card)))
  268.           (= (+ 1 (get-value (car card-list)))
  269.          (get-value card)))
  270.      (if (or  (= (length card-list) 1)
  271.                   (not (is-visible? (cadr card-list)))
  272.           (eq? (is-red? (car card-list))
  273.                (is-red? (cadr card-list)))
  274.           (not (= (+ 1 (get-value (car card-list)))
  275.               (get-value (cadr card-list))))
  276.           (check-a-foundation (cadr card-list) 0)
  277.           (check-a-tableau (get-top-card slot2)
  278.                    slot1    
  279.                    (cdr card-list)
  280.                    slot2)
  281.           (check-a-tableau (cadr card-list)
  282.                    slot2
  283.                    (get-cards slot1)
  284.                    slot1)
  285.           (check-a-tableau (cadr card-list)
  286.                    slot2
  287.                    (stripped (get-cards slot2)
  288.                          (car card-list))
  289.                    slot2))
  290.          (list 1 (get-name (car card-list)) (get-name card))
  291.          (check-a-tableau card 
  292.                   slot1 
  293.                   (cdr card-list) 
  294.                   slot2)))
  295.     (#t (check-a-tableau card slot1 (cdr card-list) slot2))))
  296.  
  297. (define (check-to-tableau? slot1 slot2)
  298.   (cond ((= slot1 8)
  299.      #f)
  300.     ((or (= slot2 8)
  301.          (empty-slot? slot1))
  302.      (check-to-tableau? (+ 1 slot1) 1))
  303.     ((and (not (= slot1 slot2))
  304.           (check-a-tableau (get-top-card slot1) 
  305.                    slot1 
  306.                    (get-cards slot2) 
  307.                    slot2))
  308.      (check-a-tableau (get-top-card slot1) 
  309.               slot1 
  310.               (get-cards slot2) 
  311.               slot2))
  312.     (#t (check-to-tableau? slot1 (+ 1 slot2)))))
  313.  
  314. (define (get-hint)
  315.   (or (check-to-foundations? 1)
  316.       (check-to-tableau? 1 2)
  317.       (check-for-empty)))
  318.  
  319. (define (get-options) #f)
  320.  
  321. (define (apply-options options) #f)
  322.  
  323. (define (timeout) #f)
  324.  
  325. (set-features droppable-feature)
  326.  
  327. (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?)
  328.