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

  1. ; AisleRiot - kansas.scm
  2. ; Copyright (C) 1999, 2003 Rosanna Yuen <rwsy@mit.edu>
  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 BASE-VAL 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.  
  29.   (add-normal-slot '())
  30.  
  31.   (set! HORIZPOS (+ HORIZPOS 0.5))
  32.  
  33.   (add-normal-slot '())
  34.   (add-normal-slot '())
  35.   (add-normal-slot '())
  36.   (add-normal-slot '())
  37.  
  38.   (add-carriage-return-slot)
  39.  
  40.   (add-normal-slot '())
  41.  
  42.   (add-blank-slot)
  43.   (add-blank-slot)
  44.  
  45.   (set! HORIZPOS (+ HORIZPOS 0.5))
  46.  
  47.   (add-extended-slot '() down)
  48.   (add-extended-slot '() down)
  49.   (add-extended-slot '() down)
  50.  
  51.   (deal-cards 0 '(6 6 6 6 6 6 6 6 6 6 6))
  52.   (deal-cards-face-up 0 '(6 2 7 8 9))
  53.  
  54.   (set! BASE-VAL (get-value (get-top-card 2)))
  55.  
  56.   (add-to-score! 1)
  57.  
  58.   (give-status-message)
  59.  
  60.   (list 7 4))
  61.  
  62. (define (give-status-message)
  63.   (set-statusbar-message (string-append (get-stock-no-string)
  64.                     "   "
  65.                     (get-reserve-no-string)
  66.                     "   "
  67.                     (get-base-string))))
  68.  
  69. (define (get-stock-no-string)
  70.   (string-append (_"Stock left:") " " 
  71.          (number->string (length (get-cards 0)))))
  72.  
  73. (define (get-reserve-no-string)
  74.   (string-append (_"Reserve left:") " " 
  75.          (number->string (length (get-cards 6)))))
  76.  
  77. (define (get-base-string)
  78.   (cond ((and (> BASE-VAL 1)
  79.           (< BASE-VAL 11))
  80.      (string-append (_"Base Card: ") (number->string BASE-VAL)))
  81.     ((= BASE-VAL 1)
  82.      (_"Base Card: Ace"))
  83.     ((= BASE-VAL 11)
  84.      (_"Base Card: Jack"))
  85.     ((= BASE-VAL 12)
  86.      (_"Base Card: Queen"))
  87.     ((= BASE-VAL 13)
  88.      (_"Base Card: King"))
  89.     (#t "")))
  90.  
  91. (define (button-pressed slot-id card-list)
  92.   (and (not (= (length card-list) 0))
  93.        (is-visible? (car card-list))
  94.        (or (= slot-id 1)
  95.        (> slot-id 5))))
  96.  
  97. (define (droppable? start-slot card-list end-slot)
  98.   (cond ((= start-slot end-slot) #f)
  99.         ((and (> end-slot 1)
  100.           (< end-slot 6)
  101.           (= (length card-list) 1))
  102.      (and (or (and (empty-slot? end-slot)
  103.                (= BASE-VAL (get-value (car card-list))))
  104.           (and (not (empty-slot? end-slot))
  105.                (eq? (get-suit (get-top-card end-slot))
  106.                 (get-suit (car card-list)))
  107.                (or (and (= (get-value (get-top-card end-slot)) 
  108.                    king)
  109.                 (= (get-value (car card-list)) ace))
  110.                (= (+ 1 (get-value (get-top-card end-slot)))
  111.                   (get-value (car card-list))))))))
  112.     ((and (> end-slot 6)
  113.           (empty-slot? end-slot)
  114.           (= start-slot 1))
  115.      #t)
  116.     ((and (> end-slot 6)
  117.           (not (empty-slot? end-slot)))
  118.      (and (or (and (= (get-value (get-top-card end-slot)) ace)
  119.                (= (get-value (car (reverse card-list))) king))
  120.           (= (get-value (get-top-card end-slot))
  121.              (+ 1 (get-value (car (reverse card-list))))))))
  122.     (#t #f)))
  123.  
  124. (define (button-released start-slot card-list end-slot)
  125.   (and (droppable? start-slot card-list end-slot)
  126.        (or (< end-slot 2)
  127.            (> end-slot 5)
  128.            (add-to-score! 1))
  129.        (move-n-cards! start-slot end-slot card-list)
  130.        (or (= start-slot 1)
  131.        (empty-slot? 6)
  132.        (and (= start-slot 6)
  133.         (make-visible-top-card 6))
  134.        (not (empty-slot? start-slot))
  135.        (and (deal-cards 6 (list start-slot))
  136.         (or (empty-slot? 6)
  137.             (make-visible-top-card 6))
  138.         (give-status-message)))))
  139.                
  140. (define (button-clicked slot-id)
  141.   (and (= slot-id 0)
  142.        (flip-stock 0 1 0)
  143.        (give-status-message)))
  144.  
  145. (define (place-base slot-id foundation-slot)
  146.   (cond ((empty-slot? foundation-slot)
  147.      (and (move-n-cards! slot-id 
  148.                  foundation-slot
  149.                  (list (get-top-card slot-id)))
  150.           (remove-card slot-id)
  151.           (add-to-score! 1)
  152.           (or (= slot-id 1)
  153.           (empty-slot? 6)
  154.           (and (= slot-id 6)
  155.                (make-visible-top-card 6))
  156.           (not (empty-slot? slot-id))
  157.           (and (deal-cards 6 (list slot-id))
  158.                (or (empty-slot? 6)
  159.                (make-visible-top-card 6))))
  160.           (give-status-message)))
  161.     (#t
  162.      (place-base slot-id (+ 1 foundation-slot)))))
  163.  
  164. (define (place-card slot-id foundation-slot)
  165.   (cond ((> foundation-slot 5)
  166.      #f)
  167.     ((and (not (empty-slot? foundation-slot))
  168.           (eq? (get-suit (get-top-card slot-id))
  169.            (get-suit (get-top-card foundation-slot)))
  170.           (or (and (= (get-value (get-top-card slot-id)) ace)
  171.                (= (get-value (get-top-card foundation-slot)) king))
  172.           (= (get-value (get-top-card slot-id))
  173.              (+ 1 (get-value (get-top-card foundation-slot))))))
  174.      (and (move-n-cards! slot-id 
  175.                  foundation-slot 
  176.                  (list (get-top-card slot-id)))
  177.           (add-to-score! 1)
  178.           (remove-card slot-id)
  179.           (or (= slot-id 1)
  180.           (empty-slot? 6)
  181.           (and (= slot-id 6)
  182.                (make-visible-top-card 6))
  183.           (not (empty-slot? slot-id))
  184.           (and (deal-cards 6 (list slot-id))
  185.                (or (empty-slot? 6)
  186.                (make-visible-top-card 6))))
  187.           (give-status-message)))
  188.     (#t
  189.      (place-card slot-id (+ 1 foundation-slot)))))
  190.  
  191. (define (button-double-clicked slot-id)
  192.   (if (and (or (> slot-id 5) 
  193.            (eq? slot-id 1))
  194.        (not (empty-slot? slot-id)))
  195.       (cond ((= (get-value (get-top-card slot-id)) BASE-VAL)
  196.          (place-base slot-id 2))
  197.         (#t
  198.          (place-card slot-id 2)))
  199.       #f))
  200.  
  201. (define (game-continuable)
  202.   (and (not (game-won))
  203.        (get-hint)))
  204.  
  205. (define (game-won)
  206.   (and (= (length (get-cards 2)) 13)
  207.        (= (length (get-cards 3)) 13)
  208.        (= (length (get-cards 4)) 13)
  209.        (= (length (get-cards 5)) 13)))
  210.  
  211. (define (dealable?)
  212.   (and (not (empty-slot? 0))
  213.        (list 0 (_"Deal another card"))))
  214.  
  215. (define (check-a-foundation card foundation-slot)
  216.   (cond ((> foundation-slot 5)
  217.      #f)
  218.     ((and (not (empty-slot? foundation-slot))
  219.           (eq? (get-suit card)
  220.            (get-suit (get-top-card foundation-slot)))
  221.           (or (and (= (get-value card) ace)
  222.                (= (get-value (get-top-card foundation-slot)) king))
  223.           (= (get-value card)
  224.              (+ 1 (get-value (get-top-card foundation-slot))))))
  225.      #t)
  226.     (#t
  227.      (check-a-foundation card (+ 1 foundation-slot)))))
  228.  
  229. (define (check-to-foundations slot-id)
  230.   (cond ((> slot-id 9)
  231.      #f)
  232.     ((= slot-id 2)
  233.      (check-to-foundations 6))
  234.     ((empty-slot? slot-id)
  235.      (check-to-foundations (+ 1 slot-id)))
  236.     ((= (get-value (get-top-card slot-id)) BASE-VAL)
  237.      (list 2 (get-name (get-top-card slot-id)) (_"an empty foundation")))
  238.     ((check-a-foundation (get-top-card slot-id) 2)
  239.      (list 1 
  240.            (get-name (get-top-card slot-id))
  241.            (get-name (make-card (if (= (get-value (get-top-card slot-id))
  242.                        ace)
  243.                     king
  244.                     (- (get-value (get-top-card slot-id))
  245.                        1))
  246.                     (get-suit (get-top-card slot-id))))))
  247.     (#t
  248.      (check-to-foundations (+ 1 slot-id)))))
  249.  
  250. (define (check-a-tableau-list card card-list)
  251.   (cond ((= (length card-list) 0)
  252.      #f)
  253.     ((or (= (get-value card)
  254.         (+ 1 (get-value (car card-list))))
  255.          (and (= (get-value card) ace)
  256.           (= (get-value (car card-list)) king)))
  257.      (and (or (check-a-foundation (cadr card-list) 2)
  258.           (eq? (get-suit card)
  259.                (get-suit (car card-list))))
  260.           (list 1 (get-name (car card-list)) (get-name card))))
  261.     (#t
  262.      (check-a-tableau-list card (cdr card-list)))))
  263.  
  264. (define (check-a-tableau slot1 slot2)
  265.   (cond ((> slot2 9)
  266.      #f)
  267.     ((= slot2 2)
  268.      (check-a-tableau slot1 6))
  269.     ((or (= slot2 1)
  270.          (= slot2 6))
  271.      (or (and (not (empty-slot? slot2))
  272.           (or
  273.            (= (get-value (get-top-card slot1))
  274.               (+ 1 (get-value (get-top-card slot2))))
  275.            (and (= (get-value (get-top-card slot1)) ace)
  276.             (= (get-value (get-top-card slot2)) king)))
  277.           (list 1 
  278.             (get-name (get-top-card slot2))
  279.             (get-name (get-top-card slot1))))
  280.          (check-a-tableau slot1 (+ 1 slot2))))
  281.     ((and (not (empty-slot? slot2))
  282.           (or (and (= (get-value (get-top-card slot1)) ace)
  283.                (= (get-value (car (reverse (get-cards slot2)))) king))
  284.           (= (get-value (get-top-card slot1))
  285.              (+ 1 (get-value (car (reverse (get-cards slot2))))))))
  286.      (list 1 
  287.            (get-name (car (reverse (get-cards slot2))))
  288.            (get-name (get-top-card slot1))))
  289.     ((and (not (empty-slot? slot2))
  290.           (or (> (get-value (get-top-card slot1))
  291.              (get-value (get-top-card slot2)))
  292.           (and (>= (get-value (get-top-card slot1)) ace)
  293.                (< (get-value (get-top-card slot1)) BASE-VAL)
  294.                (<= (get-value (get-top-card slot2)) king)
  295.                (> (get-value (get-top-card slot2)) BASE-VAL)))
  296.           (or (<= (get-value (get-top-card slot1))
  297.               (get-value (car (reverse (get-cards slot2)))))
  298.           (and (<= (get-value (get-top-card slot1)) king)
  299.                (> (get-value (get-top-card slot1)) BASE-VAL)
  300.                (>= (get-value (car (reverse (get-cards slot2)))) ace)
  301.                (< (get-value (car (reverse (get-cards slot2)))) BASE-VAL)))
  302.           (check-a-tableau-list (get-top-card slot1)
  303.                     (get-cards slot2)))
  304.      (check-a-tableau-list (get-top-card slot1)
  305.                    (get-cards slot2)))
  306.     (#t
  307.      (check-a-tableau slot1 (+ 1 slot2)))))
  308.  
  309. (define (check-tableau slot-id)
  310.   (cond ((> slot-id 9)
  311.      #f)
  312.     ((and (not (empty-slot? slot-id))
  313.           (check-a-tableau slot-id 1))
  314.      (check-a-tableau slot-id 1))
  315.     (#t
  316.      (check-tableau (+ 1 slot-id)))))
  317.  
  318. (define (empty-tableau?)
  319.   (and (not (empty-slot? 1))
  320.        (or (empty-slot? 7)
  321.        (empty-slot? 8)
  322.        (empty-slot? 9))
  323.        (list 2 (get-name (get-top-card 1)) (_"an empty tableau slot"))))
  324.  
  325. (define (get-hint)
  326.   (or (check-to-foundations 1)
  327.       (check-tableau 7)
  328.       (empty-tableau?)
  329.       (dealable?)))
  330.  
  331. (define (get-options) 
  332.   #f)
  333.  
  334. (define (apply-options options) 
  335.   #f)
  336.  
  337. (define (timeout) 
  338.   #f)
  339.  
  340. (set-features droppable-feature)
  341.  
  342. (set-lambda new-game button-pressed button-released button-clicked
  343. button-double-clicked game-continuable game-won get-hint get-options
  344. apply-options timeout droppable?)
  345.