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

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