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

  1. ; AisleRiot - bakers_dozen.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. (define (new-game)
  20.   (initialize-playing-area)
  21.   (set-ace-low)
  22.   (make-standard-deck)
  23.   (shuffle-deck)
  24.  
  25.   (add-blank-slot)
  26.   (add-blank-slot)
  27.   (add-blank-slot)
  28.  
  29.   (add-normal-slot DECK)
  30.   (add-blank-slot)
  31.   (add-normal-slot '())
  32.   (add-blank-slot)
  33.   (add-normal-slot '())
  34.   (add-blank-slot)
  35.   (add-normal-slot '())
  36.  
  37.   (add-carriage-return-slot)
  38.  
  39.   (add-extended-slot '() down)
  40.   (add-extended-slot '() down)
  41.   (add-extended-slot '() down)
  42.   (add-extended-slot '() down)
  43.   (add-extended-slot '() down)
  44.   (add-extended-slot '() down)
  45.   (add-extended-slot '() down)
  46.   (add-extended-slot '() down)
  47.   (add-extended-slot '() down)
  48.   (add-extended-slot '() down)
  49.   (add-extended-slot '() down)
  50.   (add-extended-slot '() down)
  51.   (add-extended-slot '() down)
  52.  
  53.   (deal-cards-face-up 0 '(4 5 6 7 8 9 10 11 12 13 14 15 16 4 5 6 7 8 9
  54.                 10 11 12 13 14 15 16))
  55.   (move-kings-back 4)
  56.  
  57.   (deal-cards-face-up 0 '(4 5 6 7 8 9 10 11 12 13 14 15 16))
  58.   (move-kings-back 4)
  59.  
  60.   (deal-cards-face-up 0 '(4 5 6 7 8 9 10 11 12 13 14 15 16))
  61.   (move-kings-back 4)
  62.  
  63.   (list 13 5))
  64.  
  65. (define (move-kings-back slot-id)
  66.   (if (< slot-id 17)
  67.       (begin (and (= (get-value (get-top-card slot-id)) king)
  68.           (set-cards! slot-id (append (cdr (get-cards slot-id)) 
  69.                           (list (get-top-card slot-id)))))
  70.          (move-kings-back (+ 1 slot-id)))
  71.       #t))
  72.  
  73. (define (button-pressed slot-id card-list)
  74.   (and (not (empty-slot? slot-id))
  75.        (= (length card-list) 1)))
  76.  
  77. (define (droppable? start-slot card-list end-slot)
  78.   (cond ((= start-slot end-slot)
  79.      #f)
  80.     ((< end-slot 4)
  81.      (cond ((and (= (get-value (car card-list))
  82.             ace)
  83.              (empty-slot? end-slot))
  84.         #t)
  85.            ((and (not (empty-slot? end-slot))
  86.              (= (get-suit (get-top-card end-slot))
  87.             (get-suit (car card-list)))
  88.              (= (+ 1 (get-value (get-top-card end-slot)))
  89.             (get-value (car card-list))))
  90.         #t)
  91.            (#t #f)))
  92.     ((and (not (empty-slot? end-slot))
  93.           (= (get-value (get-top-card end-slot))
  94.          (+ 1 (get-value (car card-list)))))
  95.      #t)
  96.     (#t #f)))
  97.  
  98. (define (button-released start-slot card-list end-slot)
  99.   (and (droppable? start-slot card-list end-slot)
  100.        (move-n-cards! start-slot end-slot card-list)
  101.        (or (> start-slot 3)
  102.            (add-to-score! -1))
  103.        (or (> end-slot 3)
  104.            (add-to-score! 1))))
  105.  
  106. (define (button-clicked slot-id)
  107.   #f)
  108.  
  109. (define (find-empty-foundation a-slot f-slot)
  110.   (cond ((> f-slot 3)
  111.      #f)
  112.     ((empty-slot? f-slot)
  113.      (deal-cards a-slot (list f-slot)))
  114.     (#t (find-empty-foundation a-slot (+ 1 f-slot)))))
  115.  
  116. (define (find-foundation a-slot f-slot)
  117.   (cond ((> f-slot 3)
  118.      #f)
  119.     ((and (not (empty-slot? f-slot))
  120.           (= (get-suit (get-top-card a-slot))
  121.          (get-suit (get-top-card f-slot)))
  122.           (= (get-value (get-top-card a-slot))
  123.          (+ 1 (get-value (get-top-card f-slot)))))
  124.      (and (deal-cards a-slot (list f-slot))
  125.           (add-to-score! 1)))
  126.     (#t (find-foundation a-slot (+ 1 f-slot)))))
  127.  
  128.  
  129. (define (button-double-clicked slot-id)
  130.   (and (> slot-id 3)
  131.        (not (empty-slot? slot-id))
  132.        (or (and (= (get-value (get-top-card slot-id))
  133.            ace)
  134.         (find-empty-foundation slot-id 0)
  135.         (add-to-score! 1))
  136.        (find-foundation slot-id 0))))
  137.        
  138.  
  139. (define (game-continuable)
  140.   (and (not (game-won))
  141.        (get-hint)))
  142.  
  143. (define (game-won)
  144.   (and (= (length (get-cards 0)) 13)
  145.        (= (length (get-cards 1)) 13)
  146.        (= (length (get-cards 2)) 13)
  147.        (= (length (get-cards 3)) 13)))
  148.  
  149. (define (foundation-possible? t-slot f-slot)
  150.   (cond ((= t-slot 17)
  151.      #f)
  152.     ((or (= f-slot 4)
  153.          (empty-slot? t-slot))
  154.      (foundation-possible? (+ 1 t-slot) 0))
  155.     ((= (get-value (get-top-card t-slot)) ace)
  156.      (list 2 (get-name (get-top-card t-slot)) (_"an empty foundation")))
  157.     ((and (not (empty-slot? f-slot))
  158.           (= (get-suit (get-top-card t-slot))
  159.          (get-suit (get-top-card f-slot)))
  160.           (= (get-value (get-top-card t-slot))
  161.          (+ 1 (get-value (get-top-card f-slot)))))
  162.      (list 1 
  163.            (get-name (get-top-card t-slot)) 
  164.            (get-name (get-top-card f-slot))))
  165.     (#t (foundation-possible? t-slot (+ 1 f-slot)))))
  166.  
  167. (define (card-to-foundation-possible? card f-slot)
  168.   (cond ((= f-slot 4)
  169.      #f)
  170.     ((and (not (empty-slot? f-slot))
  171.           (= (get-suit card)
  172.          (get-suit (get-top-card f-slot))))
  173.      (= (get-value card)
  174.         (+ 1 (get-value (get-top-card f-slot)))))
  175.     (#t (card-to-foundation-possible? card (+ 1 f-slot)))))
  176.  
  177. (define (tableau-moves? slot1 slot2)
  178.   (cond ((= slot1 17)
  179.      #f)
  180.     ((or (= slot2 17)
  181.          (empty-slot? slot1))
  182.      (tableau-moves? (+ 1 slot1) 4))
  183.     ((and (not (= slot1 slot2))
  184.           (not (empty-slot? slot2))
  185.           (> (length (get-cards slot1)) 1)
  186.           (= (+ 1 (get-value (get-top-card slot1)))
  187.          (get-value (get-top-card slot2)))
  188.           (or (not (= (get-value (get-top-card slot2))
  189.               (get-value (cadr (get-cards slot1)))))
  190.           (card-to-foundation-possible? (cadr (get-cards slot1)) 0)))
  191.      (list 1 (get-name (get-top-card slot1)) (get-name (get-top-card slot2))))
  192.     (#t (tableau-moves? slot1 (+ 1 slot2)))))
  193.  
  194. (define (get-hint)
  195.   (or (foundation-possible? 4 0)
  196.       (tableau-moves? 4 5)
  197.       (list 0 (_"Try rearranging the cards"))))
  198.  
  199. (define (get-options) 
  200.   #f)
  201.  
  202. (define (apply-options options) 
  203.   #f)
  204.  
  205. (define (timeout) 
  206.   #f)
  207.  
  208. (set-features droppable-feature)
  209.  
  210. (set-lambda new-game button-pressed button-released button-clicked
  211. button-double-clicked game-continuable game-won get-hint get-options
  212. apply-options timeout droppable?)
  213.