home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / gnome-games / aisleriot / games / whitehead.scm < prev    next >
Encoding:
Text File  |  2009-04-14  |  7.9 KB  |  265 lines

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