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

  1. ; AisleRiot - king_albert.scm
  2. ; Copyright (C) 2001 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-normal-slot DECK)
  27.   (add-blank-slot)
  28.   (add-normal-slot '())
  29.   (add-blank-slot)
  30.   (add-normal-slot '())
  31.   (add-blank-slot)
  32.   (add-normal-slot '())
  33.   (add-carriage-return-slot)
  34.  
  35.   (add-extended-slot '() down)
  36.   (add-extended-slot '() down)
  37.   (add-extended-slot '() down)
  38.   (add-extended-slot '() down)
  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.  
  45.   (set! HORIZPOS 0)
  46.   (set! VERTPOS 0)
  47.  
  48.   (add-carriage-return-slot)
  49.  
  50.   (set! VERTPOS (+ VERTPOS 0.5))
  51.   (set! HORIZPOS (+ HORIZPOS 9))
  52.   (add-normal-slot '())
  53.   (add-carriage-return-slot)
  54.   (set! HORIZPOS (+ HORIZPOS 9))
  55.   (add-normal-slot '())
  56.   (add-carriage-return-slot)
  57.   (set! HORIZPOS (+ HORIZPOS 9))
  58.   (add-normal-slot '())
  59.   (add-carriage-return-slot)
  60.   (set! HORIZPOS (+ HORIZPOS 9))
  61.  
  62.   (set! HORIZPOS 0)
  63.   (set! VERTPOS 0)
  64.  
  65.   (add-carriage-return-slot)
  66.  
  67.   (set! HORIZPOS (+ HORIZPOS 9))
  68.   (add-blank-slot)
  69.   (add-normal-slot '())
  70.   (add-carriage-return-slot)
  71.   (set! HORIZPOS (+ HORIZPOS 9))
  72.   (add-blank-slot)
  73.   (add-normal-slot '())
  74.   (add-carriage-return-slot)
  75.   (set! HORIZPOS (+ HORIZPOS 9))
  76.   (add-blank-slot)
  77.   (add-normal-slot '())
  78.   (add-carriage-return-slot)
  79.   (set! HORIZPOS (+ HORIZPOS 9))
  80.   (add-blank-slot)
  81.   (add-normal-slot '())
  82.  
  83.   (deal-cards 0 '(4 5 6 7 8 9 10 11 12 4 5 6 7 8 9 10 11 4 5 6 7 8 9
  84.             10 4 5 6 7 8 9 4 5 6 7 8 4 5 6 7 4 5 6 4 5 4 13 14
  85.             15 16 17 18 19))
  86.  
  87.   (map flip-top-card '(4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19))
  88.  
  89.   (list 11 5))
  90.  
  91. (define (button-pressed slot-id card-list)
  92.   (and (not (empty-slot? slot-id))
  93.        (is-visible? (car (reverse card-list)))))
  94.  
  95. (define (droppable? start-slot card-list end-slot)
  96.   (cond ((= start-slot end-slot)
  97.      #f)
  98.     ((< end-slot 4)
  99.      (and (= (length card-list) 1)
  100.           (or (and (= (get-value (car card-list)) ace)
  101.                (empty-slot? end-slot))
  102.           (and (not (empty-slot? end-slot))
  103.                (= (get-suit (get-top-card end-slot))
  104.               (get-suit (car card-list)))
  105.                (= (get-value (car card-list))
  106.               (+ 1 (get-value (get-top-card end-slot))))))))
  107.     ((< end-slot 13)
  108.      (and (or (empty-slot? end-slot)
  109.           (and (eq? (is-red? (car (reverse card-list)))
  110.                 (is-black? (get-top-card end-slot)))
  111.                (= (+ 1 (get-value (car (reverse card-list))))
  112.               (get-value (get-top-card end-slot)))))))
  113.     (#t #f)))
  114.  
  115. (define (button-released start-slot card-list end-slot)
  116.   (and (droppable? start-slot card-list end-slot)
  117.        (move-n-cards! start-slot end-slot card-list)
  118.        (or (> start-slot 3)
  119.            (add-to-score! -1))
  120.        (or (> end-slot 3)
  121.            (add-to-score! 1))
  122.        (or (empty-slot? start-slot)
  123.            (make-visible-top-card start-slot))))
  124.  
  125. (define (button-clicked slot-id)
  126.   #f)
  127.  
  128. (define (move-ace-to-foundation slot f-slot)
  129.   (if (empty-slot? f-slot)
  130.       f-slot
  131.       (move-ace-to-foundation slot (+ 1 f-slot))))
  132.  
  133. (define (move-card-to-foundation slot f-slot)
  134.   (cond ((= f-slot 4)
  135.      #f)
  136.     ((and (not (empty-slot? f-slot))
  137.           (= (get-suit (get-top-card slot))
  138.          (get-suit (get-top-card f-slot)))
  139.           (= (get-value (get-top-card slot))
  140.          (+ 1 (get-value (get-top-card f-slot)))))
  141.      f-slot)
  142.     (#t (move-card-to-foundation slot (+ 1 f-slot)))))
  143.     
  144.  
  145. (define (button-double-clicked slot-id)
  146.   (and (> slot-id 3)
  147.        (not (empty-slot? slot-id))
  148.        (or (and (= (get-value (get-top-card slot-id))
  149.            ace)
  150.         (deal-cards slot-id (list (move-ace-to-foundation slot-id 0))))
  151.        (and (move-card-to-foundation slot-id 0)
  152.         (deal-cards slot-id (list (move-card-to-foundation slot-id 0)))))
  153.        (add-to-score! 1)
  154.        (or (empty-slot? slot-id)
  155.        (make-visible-top-card slot-id))))
  156.  
  157. (define (game-continuable)
  158.   (not (game-won)))
  159.  
  160. (define (game-won)
  161.   (and (= (length (get-cards 0)) 13)
  162.        (= (length (get-cards 1)) 13)
  163.        (= (length (get-cards 2)) 13)
  164.        (= (length (get-cards 3)) 13)))
  165.  
  166. (define (strip card-list)
  167.   (if (or (= (length card-list) 1)
  168.       (not (is-visible? (cadr card-list))))
  169.       (car card-list)
  170.       (strip (cdr card-list))))
  171.  
  172. (define (check-plop card t-slot)
  173.   (cond ((= t-slot 13)
  174.      #f)
  175.     ((and (not (empty-slot? t-slot))
  176.           (eq? (is-red? card)
  177.            (is-black? (get-top-card t-slot)))
  178.           (= (+ 1 (get-value card))
  179.          (get-value (get-top-card t-slot))))
  180.      t-slot)
  181.     ((empty-slot? t-slot)
  182.      t-slot)
  183.     (#t (check-plop card (+ 1 t-slot)))))
  184.  
  185. (define (check-uncover t-slot)
  186.   (cond ((= t-slot 20)
  187.      #f)
  188.     ((and (not (empty-slot? t-slot))
  189.           (check-plop (strip (get-cards t-slot)) 4))
  190.      (if (empty-slot? (check-plop (strip (get-cards t-slot)) 4))
  191.          (list 2 
  192.            (get-name (strip (get-cards t-slot)))
  193.            (_"an empty tableau slot"))
  194.          (list 1 
  195.            (get-name (strip (get-cards t-slot)))
  196.            (get-name (get-top-card (check-plop (strip (get-cards t-slot)) 
  197.                                4))))))
  198.     ((and (not (empty-slot? t-slot))
  199.           (> (length (get-cards t-slot)) 1)
  200.           (not (is-visible? (cadr (get-cards t-slot))))
  201.           (check-a-slot-to-foundations t-slot 0))
  202.      (check-a-slot-to-foundations t-slot 0))
  203.     (#t (check-uncover (+ 1 t-slot)))))
  204.  
  205. (define (check-a-foundation-for-uncover card f-slot)
  206.   (cond ((= f-slot 4)
  207.      #f)
  208.     ((and (not (empty-slot? f-slot))
  209.           (eq? (is-red? card)
  210.            (is-black? (get-top-card f-slot)))
  211.           (= (+ 1 (get-value card))
  212.          (get-value (get-top-card f-slot)))
  213.           (check-plop (get-top-card f-slot) 4))
  214.      (list 1 
  215.            (get-name (get-top-card f-slot))
  216.            (get-name (get-top-card (check-plop (get-top-card f-slot) 4)))))
  217.     (#t (check-a-foundation-for-uncover card (+ 1 f-slot)))))
  218.  
  219. (define (check-foundation-for-uncover t-slot)
  220.   (cond ((= t-slot 13)
  221.      #f)
  222.     ((and (not (empty-slot? t-slot))
  223.           (not (is-visible? (car (reverse (get-cards t-slot)))))
  224.           (check-a-foundation-for-uncover (strip (get-cards t-slot)) 0))
  225.      (check-a-foundation-for-uncover (strip (get-cards t-slot)) 0))
  226.     (#t (check-foundation-for-uncover (+ 1 t-slot)))))
  227.  
  228. (define (check-empty-tslot t-slot)
  229.   (cond ((= t-slot 13)
  230.      #f)
  231.     ((and (not (empty-slot? t-slot))
  232.           (is-visible? (car (reverse (get-cards t-slot))))
  233.           (check-plop (car (reverse (get-cards t-slot))) 4))
  234.      (if (empty-slot? (check-plop (car (reverse (get-cards t-slot))) 4))
  235.          (check-empty-tslot (+ 1 t-slot))
  236.          (list 1
  237.            (get-name (car (reverse (get-cards t-slot))))
  238.            (get-name (get-top-card (check-plop (car (reverse (get-cards t-slot)))
  239.                                4))))))
  240.     (#t (check-empty-tslot (+ 1 t-slot)))))
  241.  
  242. (define (check-to-foundations slot f-slot)
  243.   (cond ((= slot 20)
  244.      #f)
  245.     ((empty-slot? slot)
  246.      (check-to-foundations (+ 1 slot) f-slot))
  247.     ((check-a-slot-to-foundations slot f-slot)
  248.      (check-a-slot-to-foundations slot f-slot))
  249.     (#t (check-to-foundations (+ 1 slot) f-slot))))
  250.  
  251. (define (check-a-slot-to-foundations slot f-slot)
  252.   (cond ((= f-slot 4)
  253.      #f)
  254.     ((= (get-value (get-top-card slot))
  255.         ace)
  256.      (list 2
  257.            (get-name (get-top-card slot))
  258.            (_"an empty foundation")))
  259.     ((and (not (empty-slot? f-slot))
  260.           (= (get-suit (get-top-card slot))
  261.          (get-suit (get-top-card f-slot)))
  262.           (= (get-value (get-top-card slot))
  263.          (+ 1 (get-value (get-top-card f-slot)))))
  264.      (list 1
  265.            (get-name (get-top-card slot))
  266.            (get-name (get-top-card f-slot))))
  267.     (#t (check-a-slot-to-foundations slot (+ 1 f-slot)))))
  268.     
  269. (define (check-simple-foundation slot happynum)
  270.   (cond ((= slot 20)
  271.      #f)
  272.     ((and (not (empty-slot? slot))
  273.           (<= (get-value (get-top-card slot)) happynum)
  274.           (check-a-slot-to-foundations slot 0))
  275.      (check-a-slot-to-foundations slot 0))
  276.     (#t (check-simple-foundation (+ 1 slot) happynum))))
  277.  
  278. (define (get-min-happy-foundation fslot value)
  279.   (cond ((= fslot 4)
  280.      value)
  281.     ((empty-slot? fslot)
  282.      2)
  283.     (#t (get-min-happy-foundation (+ 1 fslot) 
  284.                       (min value (+ 2 (get-value (get-top-card fslot))))))))
  285.  
  286. (define (get-hint)
  287.   (or (check-simple-foundation 4 (get-min-happy-foundation 2 king))
  288.       (check-uncover 4)
  289.       (check-empty-tslot 4)
  290.       (check-foundation-for-uncover 4)
  291.       (check-to-foundations 4 0)
  292.       (list 0 (_"Try rearranging the cards"))))
  293.  
  294. (define (get-options) 
  295.   #f)
  296.  
  297. (define (apply-options options) 
  298.   #f)
  299.  
  300. (define (timeout) 
  301.   #f)
  302.  
  303. (set-features droppable-feature)
  304.  
  305. (set-lambda new-game button-pressed button-released button-clicked
  306. button-double-clicked game-continuable game-won get-hint get-options
  307. apply-options timeout droppable?)
  308.