OTWO-1213 Works around lost encoding in Ruby/C binding layer
[ohcount] / test / expected_dir / lsp1.lsp
1 lisp    comment ;;; CrapsSim.lsp
2 lisp    blank   
3 lisp    comment """
4 lisp    comment The main purpose of this program was to implement a Craps game, using a language that we have just
5 lisp    comment learned.  Also, it was written in a functional style with almost no reliance on the assignment
6 lisp    comment operation.  Only one local variable called THROW was used.
7 lisp    comment """
8 lisp    blank   
9 lisp    blank   
10 lisp    comment ;;; ====================================================================================================== ;;;
11 lisp    comment ;;; ======================================= CRAPS SIMULATION ============================================= ;;;
12 lisp    comment ;;; ====================================================================================================== ;;;
13 lisp    blank   
14 lisp    blank   
15 lisp    comment ;;; ** This function takes no parameters as input and returns a random number between 1 and 6. **
16 lisp    blank   
17 lisp    code    (DEFUN THROW-DIE ()
18 lisp    code                             (+ (RANDOM 6) 1)          ;;; get a random number between 0 and 5 and then add 1
19 lisp    code                             )
20 lisp    blank   
21 lisp    comment ;;; ====================================================================================================== ;;;
22 lisp    blank   
23 lisp    comment ;;; ** This function takes no parameters as input and returns a LIST with two numbers between 1 and 6. **
24 lisp    blank   
25 lisp    blank   
26 lisp    code    (DEFUN THROW-DICE ()       
27 lisp    blank   
28 lisp    code                             (LIST (THROW-DIE) (THROW-DIE))              ;;; create a list with two random numbers
29 lisp    blank   
30 lisp    code                             )
31 lisp    blank   
32 lisp    comment ;;; ====================================================================================================== ;;;
33 lisp    blank   
34 lisp    comment ;;; ** This function takes two numbers as parameters for input and returns T or Nil.  T is returned if both
35 lisp    comment ;;;    numbers are equal to 6.  Nil is returned otherwise. **
36 lisp    blank   
37 lisp    code    (DEFUN BOXCARS-P (A B)
38 lisp    code                             (AND (EQUAL '6 A)                      
39 lisp    code                                                    (EQUAL '6 B)
40 lisp    code                                                    )
41 lisp    blank   
42 lisp    code                             )
43 lisp    blank   
44 lisp    comment ;;; ====================================================================================================== ;;;
45 lisp    blank   
46 lisp    comment ;;; ** This function takes two numbers as parameters for input and returns T or Nil.  T is returned if both
47 lisp    comment ;;;    numbers are equal to 1.  Nil is returned otherwise. **
48 lisp    blank   
49 lisp    code    (DEFUN SNAKE-EYES-P (A B)
50 lisp    code                             (AND (EQUAL '1 A)                       
51 lisp    code                                                    (EQUAL '1 B)
52 lisp    code                                                    )
53 lisp    blank   
54 lisp    code                             )
55 lisp    blank   
56 lisp    comment ;;; ====================================================================================================== ;;;
57 lisp    blank   
58 lisp    comment ;;; ** This function takes two numbers as parameters for input and returns T or Nil.  T is returned if the 
59 lisp    comment ;;;    sum of both numbers is equal to a 7 or 11.  Nil is returned otherwise. **
60 lisp    blank   
61 lisp    code    (DEFUN INSTANT-WIN-P (A B)
62 lisp    code                             (OR (EQUAL '7 (+ A B))                  
63 lisp    code                                             (EQUAL '11 (+ A B))
64 lisp    code                                             )
65 lisp    blank   
66 lisp    code                             )
67 lisp    blank   
68 lisp    comment ;;; ====================================================================================================== ;;;
69 lisp    blank   
70 lisp    comment ;;; ** This function takes two numbers as parameters for input and returns T or Nil.  T is returned if the 
71 lisp    comment ;;;    sum of both numbers is equal to a 2, 3 or 12.  Nil is returned otherwise. **
72 lisp    blank   
73 lisp    code    (DEFUN INSTANT-LOSS-P (A B)
74 lisp    code                             (OR (EQUAL '2 (+ A B))
75 lisp    code                                             (EQUAL '3 (+ A B))
76 lisp    code                                             (EQUAL '12 (+ A B))
77 lisp    code                                             )
78 lisp    blank   
79 lisp    code                             )
80 lisp    blank   
81 lisp    comment ;;; ====================================================================================================== ;;;
82 lisp    blank   
83 lisp    comment ;;; ** This function takes two numbers as parameters for input and returns a string.  If function BOXCARS_P
84 lisp    comment ;;;    returns T, then the returned string equals BOXCARS.  If function SNAKE_EYES_P returns T, then the 
85 lisp    comment ;;;    returned string equals SNAKE_EYES.  The string contains Nil otherwise. **
86 lisp    blank   
87 lisp    code    (DEFUN SAY-THROW (A B)
88 lisp    code                             (COND ((BOXCARS-P A B) 'BOXCARS)                 ;;; make use of function BOXCARS_P
89 lisp    code                                                     ((SNAKE-EYES-P A B) 'SNAKE-EYES)           ;;; make use of function SNAKE_EYES_P
90 lisp    blank   
91 lisp    code                                                     )
92 lisp    code                             )
93 lisp    blank   
94 lisp    comment ;;; ====================================================================================================== ;;;
95 lisp    blank   
96 lisp    comment ;;; ** This is the main function used to simulate the game of craps.  Variable THROW contains a LIST of two
97 lisp    comment ;;;    numbers between 1 and 6.  The numbers located in THROW, are used as parameters for the other functions.
98 lisp    comment ;;;    The several pieces used for output are listed together and then the LIST is returned from this 
99 lisp    comment ;;;    function.
100 lisp    blank   
101 lisp    blank   
102 lisp    code    (DEFUN CRAPS ()
103 lisp    code                             (LET THROW (THROW-DICE))                        ;;; get initial roll of the dice
104 lisp    blank   
105 lisp    comment                          ;;; if roll is a win, then LIST the appropriate output
106 lisp    blank   
107 lisp    code                             (COND ((INSTANT-WIN-P (FIRST THROW) (SECOND THROW)) 
108 lisp    code                                                            (LIST 'THROW (FIRST THROW) 'AND (SECOND THROW) '-- (+ (FIRST THROW) (SECOND THROW)) '-- 'YOU 'WIN))
109 lisp    blank   
110 lisp    comment                                                  ;;; if roll is a loss, then check for BOXCARS or SNAKE-EYES
111 lisp    blank   
112 lisp    code                                                     ((INSTANT-LOSS-P (FIRST THROW) (SECOND THROW))
113 lisp    blank   
114 lisp    code                                                            (IF (EQUAL 'NIL (SAY-THROW (FIRST THROW) (SECOND THROW)))   ;;; if Nil then LIST appropriate output
115 lisp    blank   
116 lisp    code                                                                            (LIST 'THROW (FIRST THROW) 'AND (SECOND THROW) '-- (+ (FIRST THROW) (SECOND THROW)) '-- 'YOU 'LOSE)
117 lisp    blank   
118 lisp    comment                                                                         ;;; else include the BOXCARS or SNAKE-EYES string in the output
119 lisp    blank   
120 lisp    code                                                                            (LIST 'THROW (FIRST THROW) 'AND (SECOND THROW) '-- (SAY-THROW (FIRST THROW) (SECOND THROW)) 
121 lisp    code                                                                                                    '-- 'YOU 'LOSE)))
122 lisp    blank   
123 lisp    comment                                                  ;;; if roll is not instant win or loss then output sum of dice
124 lisp    blank   
125 lisp    code                                                     (T (LIST 'THROW (FIRST THROW) 'AND (SECOND THROW) '-- 'YOUR 'POINT 'IS (+ (FIRST THROW) 
126 lisp    code                                                                                                                                                                                                                                                                                                                                                             (SECOND THROW))))
127 lisp    code                                                     )        ;;; end COND
128 lisp    blank   
129 lisp    code                             )           ;;; end LET
130 lisp    blank   
131 lisp    blank   
132 lisp    code    )
133 lisp    blank   
134 lisp    blank   
135 lisp    comment ;;; ======================================== END OF PROGRAM CRAPS ======================================== ;;;