home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / sol-games / whitehead.scm < prev    next >
Encoding:
Text File  |  2006-08-22  |  7.8 KB  |  262 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 (button-clicked slot-id)
  102.   (and (= slot-id 0)
  103.        (flip-stock 0 1 0)))
  104.  
  105. (define (check-to-foundation card f-slot)
  106.   (cond ((= f-slot 6)
  107.      #f)
  108.     ((and (empty-slot? f-slot)
  109.           (= (get-value card) ace))
  110.      f-slot)
  111.     ((and (not (empty-slot? f-slot))
  112.           (= (get-suit (get-top-card f-slot))
  113.          (get-suit card)))
  114.      (and (= (get-value card)
  115.          (+ 1 (get-value (get-top-card f-slot))))
  116.           f-slot))
  117.     (#t (check-to-foundation card (+ 1 f-slot)))))
  118.  
  119. (define (button-double-clicked slot-id)
  120.   (and (not (empty-slot? slot-id))
  121.        (or (= slot-id 1)
  122.        (> slot-id 5))
  123.        (check-to-foundation (get-top-card slot-id) 2)
  124.        (deal-cards slot-id (list (check-to-foundation (get-top-card slot-id) 2)))
  125.        (add-to-score! 1)))
  126.  
  127. (define (game-continuable)
  128.   (give-status-message)
  129.   (and (not (game-won))
  130.        (get-hint)))
  131.  
  132. (define (game-won)
  133.   (and (empty-slot? 0)
  134.        (empty-slot? 1)
  135.        (empty-slot? 6)
  136.        (empty-slot? 7)
  137.        (empty-slot? 8)
  138.        (empty-slot? 9)
  139.        (empty-slot? 10)
  140.        (empty-slot? 11)
  141.        (empty-slot? 12)))
  142.  
  143. (define (check-foundations slot)
  144.   (cond ((= slot 13)
  145.      #f)
  146.     ((= slot 2)
  147.      (check-foundations 6))
  148.     ((and (not (empty-slot? slot))
  149.           (check-to-foundation (get-top-card slot) 2))
  150.      (if (= (get-value (get-top-card slot)) ace)
  151.          (list 2 (get-name (get-top-card slot)) (_"an empty foundation"))
  152.          (list 1
  153.            (get-name (get-top-card slot))
  154.            (get-name (get-top-card (check-to-foundation (get-top-card slot) 2))))))
  155.     (#t (check-foundations (+ 1 slot)))))
  156.  
  157. (define (check-a-tab-slot card slot2 same-suit?)
  158.   (and (or (and (not same-suit?)
  159.         (eq? (is-red? card)
  160.              (is-red? (get-top-card slot2))))
  161.        (= (get-suit card)
  162.           (get-suit (get-top-card slot2))))
  163.        (= (+ 1 (get-value card))
  164.       (get-value (get-top-card slot2)))))
  165.  
  166. (define (stripped card-list slot)
  167.   (if (or (= slot 1)
  168.       (= (length card-list) 1))
  169.       (car card-list)
  170.       (if (and (check-straight-descending-list card-list)
  171.            (check-same-suit-list card-list))
  172.       (car (reverse card-list))
  173.       (stripped (reverse (cdr (reverse card-list))) slot))))
  174.   
  175.  
  176. (define (check-same-suit-builds slot1 slot2)
  177.   (cond ((= slot1 13)
  178.      #f)
  179.     ((= slot1 2)
  180.      (check-same-suit-builds 6 7))
  181.     ((or (empty-slot? slot1)
  182.          (= slot2 13))
  183.      (check-same-suit-builds (+ 1 slot1) 6))
  184.     ((and (not (= slot1 slot2))
  185.           (not (empty-slot? slot2))
  186.           (check-a-tab-slot (stripped (get-cards slot1) slot1) slot2 #t))
  187.      (list 1 
  188.            (get-name (stripped (get-cards slot1) slot1)) 
  189.            (get-name (get-top-card slot2))))
  190.     (#t (check-same-suit-builds slot1 (+ 1 slot2)))))
  191.  
  192. (define (check-same-color-builds slot1 slot2)
  193.   (cond ((= slot1 13)
  194.      #f)
  195.     ((= slot1 2)
  196.      (check-same-color-builds 6 7))
  197.     ((or (empty-slot? slot1)
  198.          (= slot2 13))
  199.      (check-same-color-builds (+ 1 slot1) 6))
  200.     ((and (not (= slot1 slot2))
  201.           (not (empty-slot? slot2))
  202.           (check-a-tab-slot (stripped (get-cards slot1) slot1) slot2 #f))
  203.      (list 1 
  204.            (get-name (stripped (get-cards slot1) slot1)) 
  205.            (get-name (get-top-card slot2))))
  206.     (#t (check-same-color-builds slot1 (+ 1 slot2)))))
  207.  
  208. (define (empty-tab? slot)
  209.   (cond ((= slot 13)
  210.      #f)
  211.     ((empty-slot? slot)
  212.      (and (or (not (empty-slot? 1))
  213.           (and (not (empty-slot? 6))
  214.                (or (not (check-same-suit-list (get-cards 6)))
  215.                (not (check-straight-descending-list (get-cards 6)))))
  216.           (and (not (empty-slot? 7))
  217.                (or (not (check-same-suit-list (get-cards 7)))
  218.                (not (check-straight-descending-list (get-cards 7)))))
  219.           (and (not (empty-slot? 8))
  220.                (or (not (check-same-suit-list (get-cards 8)))
  221.                (not (check-straight-descending-list (get-cards 8)))))
  222.           (and (not (empty-slot? 9))
  223.                (or (not (check-same-suit-list (get-cards 9)))
  224.                (not (check-straight-descending-list (get-cards 9)))))
  225.           (and (not (empty-slot? 10))
  226.                (or (not (check-same-suit-list (get-cards 10)))
  227.                (not (check-straight-descending-list (get-cards 10)))))
  228.           (and (not (empty-slot? 11))
  229.                (or (not (check-same-suit-list (get-cards 11)))
  230.                (not (check-straight-descending-list (get-cards 11)))))
  231.           (and (not (empty-slot? 12))
  232.                (or (not (check-same-suit-list (get-cards 12)))
  233.                (not (check-straight-descending-list (get-cards 12))))))
  234.           (list 0 (_"Move a build of cards on to the empty Tableau slot"))))
  235.     (#t (empty-tab? (+ 1 slot)))))
  236.  
  237. (define (dealable?)
  238.   (and (not (empty-slot? 0))
  239.        (list 0 (_"Deal another card"))))
  240.  
  241. (define (get-hint)
  242.   (or (check-foundations 1)
  243.       (check-same-suit-builds 1 6)
  244.       (check-same-color-builds 1 6)
  245.       (empty-tab? 6)
  246.       (dealable?)))
  247.  
  248. (define (get-options) 
  249.   #f)
  250.  
  251. (define (apply-options options) 
  252.   #f)
  253.  
  254. (define (timeout) 
  255.   #f)
  256.  
  257. (set-features droppable-feature)
  258.  
  259. (set-lambda new-game button-pressed button-released button-clicked
  260. button-double-clicked game-continuable game-won get-hint get-options
  261. apply-options timeout droppable?)
  262.