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

  1. ; AisleRiot - thirteen.scm
  2. ; Copyright (C) 1999, 2003 Rosanna Yuen <rwsy@mit.edu>
  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 magic-total 13)
  20.  
  21. (define waste-slot 1)
  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-extended-slot '() right)
  31.  
  32.   (add-carriage-return-slot)
  33.  
  34.   (add-blank-slot)
  35.   (add-blank-slot)
  36.   (add-blank-slot)
  37.   (add-normal-slot '())
  38.  
  39.   (add-carriage-return-slot)
  40.   (set! VERTPOS (- VERTPOS (/ 2 3)))
  41.   (set! HORIZPOS (+ HORIZPOS 0.5))
  42.   (add-blank-slot)
  43.   (add-blank-slot)
  44.   (add-normal-slot '())
  45.   (add-normal-slot '())
  46.  
  47.   (add-carriage-return-slot)
  48.   (set! VERTPOS (- VERTPOS (/ 2 3)))
  49.   (add-blank-slot)
  50.   (add-blank-slot)
  51.   (add-normal-slot '())
  52.   (add-normal-slot '())
  53.   (add-normal-slot '())
  54.  
  55.   (add-carriage-return-slot)
  56.   (set! VERTPOS (- VERTPOS (/ 2 3)))
  57.   (set! HORIZPOS (+ HORIZPOS 0.5))
  58.   (add-blank-slot)
  59.   (add-normal-slot '())
  60.   (add-normal-slot '())
  61.   (add-normal-slot '())
  62.   (add-normal-slot '())
  63.  
  64.   (add-carriage-return-slot)
  65.   (set! VERTPOS (- VERTPOS (/ 2 3)))
  66.   (add-blank-slot)
  67.   (add-normal-slot '())
  68.   (add-normal-slot '())
  69.   (add-normal-slot '())
  70.   (add-normal-slot '())
  71.   (add-normal-slot '())
  72.  
  73.   (add-carriage-return-slot)
  74.   (set! VERTPOS (- VERTPOS (/ 2 3)))
  75.   (set! HORIZPOS (+ HORIZPOS 0.5))
  76.   (add-normal-slot '())
  77.   (add-normal-slot '())
  78.   (add-normal-slot '())
  79.   (add-normal-slot '())
  80.   (add-normal-slot '())
  81.   (add-normal-slot '())
  82.  
  83.   (add-carriage-return-slot)
  84.   (set! VERTPOS (- VERTPOS (/ 2 3)))
  85.   (add-normal-slot '())
  86.   (add-normal-slot '())
  87.   (add-normal-slot '())
  88.   (add-normal-slot '())
  89.   (add-normal-slot '())
  90.   (add-normal-slot '())
  91.   (add-normal-slot '())
  92.  
  93.   (deal-cards 0 '(2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22))
  94.   (deal-cards-face-up 0 '(23 24 25 26 27 28 29))
  95.  
  96.   (give-status-message)
  97.  
  98.   (list 7 4)
  99. )
  100.  
  101. (define (give-status-message)
  102.   (set-statusbar-message (get-stock-no-string)))
  103.  
  104. (define (get-stock-no-string)
  105.   (string-append (_"Stock left:") " " 
  106.          (number->string (length (get-cards 0)))))
  107.  
  108. (define (button-pressed slot-id card-list)
  109.   (and (not (empty-slot? slot-id))
  110.        (is-visible? (car card-list))
  111.        (= (length card-list) 1)
  112.        (not (= (get-value (car card-list)) king))))
  113.  
  114. (define (check-for-flips slot-id)
  115.   (cond ((= slot-id 29)
  116.      (if (empty-slot? 28)
  117.          (flip-top-card 22)
  118.          ))
  119.     ((= slot-id 28)
  120.      (begin
  121.        (if (empty-slot? 29)
  122.            (flip-top-card 22)
  123.            )
  124.        (if (empty-slot? 27)
  125.            (flip-top-card 21)
  126.            )))
  127.     ((= slot-id 27)
  128.      (begin
  129.        (if (empty-slot? 28)
  130.            (flip-top-card 21)
  131.            )
  132.        (if (empty-slot? 26)
  133.            (flip-top-card 20)
  134.            )))
  135.     ((= slot-id 26)
  136.      (begin
  137.        (if (empty-slot? 27)
  138.            (flip-top-card 20)
  139.            )
  140.        (if (empty-slot? 25)
  141.            (flip-top-card 19)
  142.            )))
  143.     ((= slot-id 25)
  144.      (begin
  145.        (if (empty-slot? 26)
  146.            (flip-top-card 19)
  147.            )
  148.        (if (empty-slot? 24)
  149.            (flip-top-card 18)
  150.            )))
  151.     ((= slot-id 24)
  152.      (begin
  153.        (if (empty-slot? 25)
  154.            (flip-top-card 18)
  155.            )
  156.        (if (empty-slot? 23)
  157.            (flip-top-card 17)
  158.            )))
  159.     ((= slot-id 23)
  160.      (if (empty-slot? 24)
  161.          (flip-top-card 17)
  162.          ))
  163.     ((= slot-id 22)
  164.      (if (empty-slot? 21)
  165.          (flip-top-card 16)
  166.          ))
  167.     ((= slot-id 21)
  168.      (begin
  169.        (if (empty-slot? 22)
  170.            (flip-top-card 16)
  171.            )
  172.        (if (empty-slot? 20)
  173.            (flip-top-card 15)
  174.            )))
  175.     ((= slot-id 20)
  176.      (begin
  177.        (if (empty-slot? 21)
  178.            (flip-top-card 15)
  179.            )
  180.        (if (empty-slot? 19)
  181.            (flip-top-card 14)
  182.            )))
  183.     ((= slot-id 19)
  184.      (begin
  185.        (if (empty-slot? 20)
  186.            (flip-top-card 14)
  187.            )
  188.        (if (empty-slot? 18)
  189.            (flip-top-card 13)
  190.            )))
  191.     ((= slot-id 18)
  192.      (begin
  193.        (if (empty-slot? 19)
  194.            (flip-top-card 13)
  195.            )
  196.        (if (empty-slot? 17)
  197.            (flip-top-card 12)
  198.            )))
  199.     ((= slot-id 17)
  200.      (if (empty-slot? 18)
  201.          (flip-top-card 12)
  202.          ))
  203.     ((= slot-id 16)
  204.      (if (empty-slot? 15)
  205.          (flip-top-card 11)
  206.          ))
  207.     ((= slot-id 15)
  208.      (begin
  209.        (if (empty-slot? 16)
  210.            (flip-top-card 11)
  211.            )
  212.        (if (empty-slot? 14)
  213.            (flip-top-card 10)
  214.            )))
  215.     ((= slot-id 14)
  216.      (begin
  217.        (if (empty-slot? 15)
  218.            (flip-top-card 10)
  219.            )
  220.        (if (empty-slot? 13)
  221.            (flip-top-card 9)
  222.            )))
  223.     ((= slot-id 13)
  224.      (begin
  225.        (if (empty-slot? 14)
  226.            (flip-top-card 9)
  227.            )
  228.        (if (empty-slot? 12)
  229.            (flip-top-card 8)
  230.            )))
  231.     ((= slot-id 12)
  232.      (if (empty-slot? 13)
  233.          (flip-top-card 8)
  234.          ))
  235.     ((= slot-id 11)
  236.      (if (empty-slot? 10)
  237.          (flip-top-card 7)
  238.          ))
  239.     ((= slot-id 10)
  240.      (begin
  241.        (if (empty-slot? 11)
  242.            (flip-top-card 7)
  243.            )
  244.        (if (empty-slot? 9)
  245.            (flip-top-card 6)
  246.            )))
  247.     ((= slot-id 9)
  248.      (begin
  249.        (if (empty-slot? 10)
  250.            (flip-top-card 6)
  251.            )
  252.        (if (empty-slot? 8)
  253.            (flip-top-card 5)
  254.            )))
  255.     ((= slot-id 8)
  256.      (if (empty-slot? 9)
  257.          (flip-top-card 5)
  258.          ))
  259.     ((= slot-id 7)
  260.      (if (empty-slot? 6)
  261.          (flip-top-card 4)
  262.          ))
  263.     ((= slot-id 6)
  264.      (begin
  265.        (if (empty-slot? 7)
  266.            (flip-top-card 4)
  267.            )
  268.        (if (empty-slot? 5)
  269.            (flip-top-card 3)
  270.            )))
  271.     ((= slot-id 5)
  272.      (if (empty-slot? 6)
  273.          (flip-top-card 3)
  274.          ))
  275.     ((= slot-id 4)
  276.      (if (empty-slot? 3)
  277.          (flip-top-card 2)
  278.          ))
  279.     ((= slot-id 3)
  280.      (if (empty-slot? 4)
  281.          (flip-top-card 2)
  282.          ))
  283.     ))
  284.  
  285. (define (check-double-flips start-slot end-slot)
  286.   (if (= 1 (- (max start-slot end-slot) (min start-slot end-slot)))
  287.       (let ((smaller (min start-slot end-slot)))
  288.     (cond ((= smaller 28)
  289.            (flip-top-card 22))
  290.           ((= smaller 27)
  291.            (flip-top-card 21))
  292.           ((= smaller 26)
  293.            (flip-top-card 20))
  294.           ((= smaller 25)
  295.            (flip-top-card 19))
  296.           ((= smaller 24)
  297.            (flip-top-card 18))
  298.           ((= smaller 23)
  299.            (flip-top-card 17))
  300.           ((= smaller 21)
  301.            (flip-top-card 16))
  302.           ((= smaller 20)
  303.            (flip-top-card 15))
  304.           ((= smaller 19)
  305.            (flip-top-card 14))
  306.           ((= smaller 18)
  307.            (flip-top-card 13))
  308.           ((= smaller 17)
  309.            (flip-top-card 12))
  310.           ((= smaller 15)
  311.            (flip-top-card 11))
  312.           ((= smaller 14)
  313.            (flip-top-card 10))
  314.           ((= smaller 13)
  315.            (flip-top-card 9))
  316.           ((= smaller 12)
  317.            (flip-top-card 8))
  318.           ((= smaller 10)
  319.            (flip-top-card 7))
  320.           ((= smaller 9)
  321.            (flip-top-card 6))
  322.           ((= smaller 8)
  323.            (flip-top-card 5))
  324.           ((= smaller 6)
  325.            (flip-top-card 4))
  326.           ((= smaller 5)
  327.            (flip-top-card 3))
  328.           ((= smaller 3)
  329.            (flip-top-card 2))
  330.           (#t #t)))))
  331.  
  332. (define (droppable? start-slot card-list end-slot)
  333.   (and (not (empty-slot? end-slot))
  334.        (is-visible? (get-top-card end-slot))
  335.        (= magic-total (+ (get-value (car card-list))
  336.              (get-value (get-top-card end-slot))))))
  337.  
  338. (define (button-released start-slot card-list end-slot)
  339.   (if (droppable? start-slot card-list end-slot)
  340.       (begin
  341.     (remove-card end-slot)
  342.     (check-for-flips start-slot)
  343.     (check-for-flips end-slot)
  344.     (check-double-flips start-slot end-slot)
  345.     (add-to-score! 2))))
  346.  
  347. (define (button-clicked slot-id)
  348.   (if (= slot-id 0)
  349.       (if (not (empty-slot? 0))
  350.       (deal-cards-face-up 0 (list waste-slot))
  351.       #f)
  352.       (and (not (empty-slot? slot-id))
  353.        (is-visible? (get-top-card slot-id))
  354.        (= (get-value (get-top-card slot-id))
  355.           king)
  356.        (remove-card slot-id)
  357.        (check-for-flips slot-id)
  358.        (add-to-score! 1))))
  359.  
  360. (define (button-double-clicked slot-id)
  361.   #f)
  362.  
  363. (define (game-continuable)
  364.   (give-status-message)
  365.   (and (not (game-won))
  366.        (get-hint)))
  367.  
  368. (define (game-won)
  369.   (and (empty-slot? 3)
  370.        (empty-slot? waste-slot)
  371.        (empty-slot? 0)))
  372.  
  373. ; This doesn't check for a King on top, that is a generic move and
  374. ; check-move handles it. This only checks for the one special case
  375. ; of the top two cards matching.
  376. (define (check-waste-for-move)
  377.   (if (and (> (length (get-cards waste-slot)) 2)
  378.        (= (+ (get-value (get-nth-card waste-slot 1))
  379.          (get-value (get-nth-card waste-slot 2))) 
  380.           magic-total))
  381.       (list 0 (_"Match the top two cards of the waste."))
  382.       #f))
  383.  
  384. (define (check-move slot1 slot2)
  385.   (if (or (empty-slot? slot1)
  386.       (not (is-visible? (get-top-card slot1))))
  387.       (if (< slot1 28)
  388.       (check-move (+ 1 slot1) (+ 2 slot1))
  389.       #f)
  390.       (if (= king (get-value (get-top-card slot1)))
  391.       (list 2 (get-name (get-top-card slot1)) (_"itself"))
  392.       (if (or (empty-slot? slot2)
  393.           (not (is-visible? (get-top-card slot2)))
  394.           (not (= magic-total (+ (get-value (get-top-card slot1))
  395.                      (get-value (get-top-card slot2))))))
  396.           (if (< slot2 29)
  397.           (check-move slot1 (+ 1 slot2))
  398.           (if (< slot1 28)
  399.               (check-move (+ 1 slot1) (+ 2 slot1))
  400.               #f))
  401.           (list 1 
  402.             (get-name (get-top-card slot1)) 
  403.             (get-name (get-top-card slot2)))))))
  404.  
  405. (define (dealable?)
  406.   (if (not (empty-slot? 0))
  407.       (list 0 (_"Deal a card"))
  408.       #f))
  409.  
  410. (define (get-hint)
  411.   (or (check-waste-for-move) 
  412.       (check-move waste-slot 2)
  413.       (dealable?)))
  414.  
  415. (define (get-options) 
  416.   #f)
  417.  
  418. (define (apply-options options) 
  419.   #f)
  420.  
  421. (define (timeout) 
  422.   #f)
  423.  
  424. (set-features droppable-feature)
  425.  
  426. (set-lambda new-game button-pressed button-released button-clicked
  427. button-double-clicked game-continuable game-won get-hint get-options
  428. apply-options timeout droppable?)
  429.