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

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