home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / gnome-games / aisleriot / games / agnes.scm < prev    next >
Encoding:
Text File  |  2009-04-14  |  8.4 KB  |  290 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.   (dealable-set-sensitive (dealable?))
  59.   
  60.   (list 7 4))
  61.  
  62. (define (give-status-message)
  63.   (set-statusbar-message (string-append (get-stock-no-string)
  64.                     "   "
  65.                     (get-base-string))))
  66.  
  67. (define (get-base-string)
  68.   (cond ((and (> BASE-VAL 1)
  69.           (< BASE-VAL 11))
  70.      (format (_"Base Card: ~a") (number->string BASE-VAL)))
  71.     ((= BASE-VAL 1)
  72.      (_"Base Card: Ace"))
  73.     ((= BASE-VAL 11)
  74.      (_"Base Card: Jack"))
  75.     ((= BASE-VAL 12)
  76.      (_"Base Card: Queen"))
  77.     ((= BASE-VAL 13)
  78.      (_"Base Card: King"))
  79.     (#t "")))
  80.  
  81. (define (get-stock-no-string)
  82.   (if (> (length (get-cards 0)) 1)
  83.       (string-append (_"Stock left:") " "
  84.              (number->string (length (get-cards 0))))
  85.       (string-append (_"Stock left: 0")))) 
  86.  
  87. (define (check-straight-descending-list card-list)
  88.   (or (< (length card-list) 2)
  89.       (and (= (get-value (car card-list)) king)
  90.        (= (get-value (cadr card-list)) ace)
  91.        (not (= BASE-VAL ace))
  92.        (check-straight-descending-list (cdr card-list)))
  93.       (and (= (get-value (car card-list)) (- (get-value (cadr card-list)) 1))
  94.        (not (= BASE-VAL (get-value (cadr card-list))))
  95.        (check-straight-descending-list (cdr card-list)))))
  96.  
  97. (define (button-pressed slot-id card-list)
  98.   (and (not (empty-slot? slot-id))
  99.        (is-visible? (car (reverse card-list)))
  100.        (check-same-color-list card-list)
  101.        (check-straight-descending-list card-list)))
  102.  
  103. (define (droppable? start-slot card-list end-slot)
  104.   (cond ((= start-slot end-slot)
  105.      #f)
  106.     ((and (> end-slot 0)
  107.           (< end-slot 5))
  108.      (and (= (length card-list) 1)
  109.           (or (and (empty-slot? end-slot)
  110.                (= (get-value (car card-list))
  111.               BASE-VAL))
  112.           (and (not (empty-slot? end-slot))
  113.                (= (get-suit (car card-list))
  114.               (get-suit (get-top-card end-slot)))
  115.                (or (= (get-value (car card-list))
  116.                   (+ 1 (get-value (get-top-card end-slot))))
  117.                (and (= (get-value (car card-list)) ace)
  118.                 (= (get-value (get-top-card end-slot)) king)))))))
  119.     ((> end-slot 4)
  120.      (and (not (empty-slot? end-slot))
  121.           (eq? (is-red? (car card-list))
  122.            (is-red? (get-top-card end-slot)))
  123.           (or (= (get-value (car (reverse card-list)))
  124.              (- (get-value (get-top-card end-slot)) 1))
  125.           (and (= (get-value (car (reverse card-list))) king)
  126.                (= (get-value (get-top-card end-slot)) ace)))))
  127.     (#t #f)))
  128.  
  129. (define (button-released start-slot card-list end-slot)
  130.   (and (droppable? start-slot card-list end-slot)
  131.        (move-n-cards! start-slot end-slot card-list)
  132.        (or (> start-slot 4)
  133.            (add-to-score! -1))
  134.        (or (> end-slot 4)
  135.            (add-to-score! 1))
  136.        (or (empty-slot? start-slot)
  137.        (make-visible-top-card start-slot))))
  138.  
  139. (define (check-slot-and-deal slot)
  140.   (if (and (not (empty-slot? 0))
  141.        (< slot 12))
  142.       (and (deal-cards-face-up 0 (list slot))
  143.        (check-slot-and-deal (+ 1 slot)))))
  144.  
  145. (define (do-deal-next-cards)
  146.   (and (dealable?)
  147.        (check-slot-and-deal 5)))
  148.  
  149. (define (button-clicked slot-id)
  150.   (and (= slot-id 0)
  151.        (do-deal-next-cards)))
  152.  
  153. (define (dealable?)
  154.   (not (empty-slot? 0)))
  155.  
  156. (define (check-dc slot f-slot just-checking?)
  157.   (cond ((= f-slot 5)
  158.      #f)
  159.     ((and (not (empty-slot? f-slot))
  160.           (= (get-suit (get-top-card slot))
  161.          (get-suit (get-top-card f-slot)))
  162.           (or (= (get-value (get-top-card slot))
  163.              (+ 1 (get-value (get-top-card f-slot))))
  164.           (and (= (get-value (get-top-card slot)) ace)
  165.                (= (get-value (get-top-card f-slot)) king)))
  166.           (or (and just-checking?
  167.                f-slot)
  168.           (and (deal-cards slot (list f-slot))
  169.                (add-to-score! 1)
  170.                (or (empty-slot? slot)
  171.                (make-visible-top-card slot))))))
  172.     (#t
  173.      (check-dc slot (+ 1 f-slot) just-checking?))))
  174.  
  175. (define (autoplay-foundations)
  176.   (define (autoplay-foundations-tail)
  177.     (if (or-map button-double-clicked '(5 6 7 8 9 10 11))
  178.         (delayed-call autoplay-foundations-tail)
  179.         #t))
  180.   (if (or-map button-double-clicked '(5 6 7 8 9 10 11))
  181.       (autoplay-foundations-tail)
  182.       #f))
  183.  
  184. (define (button-double-clicked slot-id)
  185.   (cond ((or (and (empty-slot? slot-id)
  186.                   (> slot-id 4))
  187.          (= slot-id 0))
  188.      #f)
  189.     ((< slot-id 5)
  190.      (autoplay-foundations))
  191.     ((= (get-value (get-top-card slot-id)) BASE-VAL)
  192.      (and (or (and (empty-slot? 1)
  193.                (deal-cards slot-id '(1)))
  194.           (and (empty-slot? 2)
  195.                (deal-cards slot-id '(2)))
  196.           (and (empty-slot? 3)
  197.                (deal-cards slot-id '(3)))
  198.           (deal-cards slot-id '(4)))
  199.           (add-to-score! 1)
  200.           (or (empty-slot? slot-id)
  201.           (make-visible-top-card slot-id))))
  202.     (#t
  203.      (check-dc slot-id 1 #f))))
  204.  
  205. (define (game-continuable)
  206.   (give-status-message)
  207.   (dealable-set-sensitive (dealable?))
  208.   (not (game-won)))
  209.  
  210. (define (game-won)
  211.   (and (= 13 (length (get-cards 1)))
  212.        (= 13 (length (get-cards 2)))
  213.        (= 13 (length (get-cards 3)))
  214.        (= 13 (length (get-cards 4)))))
  215.  
  216. (define (check-to-foundation? slot)
  217.   (cond ((= slot 12)
  218.      #f)
  219.     ((and (not (empty-slot? slot))
  220.           (= (get-value (get-top-card slot))
  221.          BASE-VAL))
  222.      (list 2
  223.            (get-name (get-top-card slot))
  224.            (_"an empty foundation pile")))
  225.     ((and (not (empty-slot? slot))
  226.           (check-dc slot 1 #t))
  227.      (list 1
  228.            (get-name (get-top-card slot))
  229.            (get-name (get-top-card (check-dc slot 1 #t)))))
  230.     (#t (check-to-foundation? (+ 1 slot)))))
  231.  
  232. (define (check-a-tableau card slot)
  233.   (and (not (empty-slot? slot))
  234.        (eq? (is-red? card) (is-red? (get-top-card slot)))
  235.        (not (= (get-value (get-top-card slot)) BASE-VAL))
  236.        (or (and (= (get-value card) king)
  237.         (= (get-value (get-top-card slot)) ace))
  238.        (= (+ (get-value card) 1)
  239.           (get-value (get-top-card slot))))))
  240.  
  241. (define (strip card-list)
  242.   (cond ((< (length card-list) 2)
  243.      (car card-list))
  244.     ((or (not (is-visible? (car (reverse card-list))))
  245. ;         (eq? (is-red? (car (reverse card-list)))
  246. ;          (is-black? (car card-list)))
  247.          (not (check-same-color-list card-list))
  248.          (not (check-straight-descending-list card-list)))
  249.      (strip (reverse (cdr (reverse card-list)))))
  250.     (#t (car (reverse card-list)))))
  251.  
  252. (define (check-to-tableau? slot1 slot2)
  253.   (cond ((= slot1 12)
  254.      #f)
  255.     ((or (= slot2 12)
  256.          (empty-slot? slot1))
  257.      (check-to-tableau? (+ 1 slot1) 5))
  258.     ((and (not (= slot1 slot2))
  259.           (check-a-tableau (strip (get-cards slot1)) slot2))
  260.      (list 1 
  261.            (get-name (strip (get-cards slot1)))
  262.            (get-name (get-top-card slot2))))
  263.     (#t (check-to-tableau? slot1 (+ 1 slot2)))))
  264.  
  265.  
  266. (define (check-deal?)
  267.   (and (dealable?)
  268.        (list 0 (_"Deal more cards"))))
  269.  
  270. (define (get-hint)
  271.   (or (check-to-foundation? 5)
  272.       (check-to-tableau? 5 6)
  273.       (check-deal?)
  274.       (list 0 (_"Try rearranging the cards"))))
  275.  
  276. (define (get-options) 
  277.   #f)
  278.  
  279. (define (apply-options options) 
  280.   #f)
  281.  
  282. (define (timeout) 
  283.   #f)
  284.  
  285. (set-features droppable-feature dealable-feature)
  286.  
  287. (set-lambda new-game button-pressed button-released button-clicked
  288. button-double-clicked game-continuable game-won get-hint get-options
  289. apply-options timeout droppable? dealable?)
  290.