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

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