;;; ======================================================= ;;; CMPU-101, Spring 2013 ;;; Assignment 5 ;;; ======================================================= (display "\n CS101 Assignment 5, Spring 2013") (display "\n Please type your name here\n\n") ;; IMPORTANT! MAKE SURE YOUR LINES OF CODE DO NOT WRAP WHEN YOUR ;; WINDOW IS ABOUT 80 COLUMNS ACROSS (SEE A COACH OR YOUR PROF IF YOU ;; ARE UNSURE HOW TO DO THIS). ;; Use the design recipe when writing the functions for this homework ;; assignment. No pre-function tests will be possible for this set of ;; interactive functions, so you should test each function as it is ;; written by calling it in the interactions window. DO NOT PROCEED TO ;; THE NEXT PROBLEM UNTIL YOU ARE SURE THE PROBLEMS YOU'VE ALREADY ;; WRITTEN WORK PROPERLY. ; ; In this assignment, you will implement a set of functions to play the ; casino game craps. Each problem implements part of the game, and when ; you are done with problem 5, you should have implemented the entire ; game. ; ; AN EXAMPLE EXECUTION OF THIS PROGRAM IS GIVEN IN THE BOTTOM-MOST ; COMMENT BOX. LOOK AT THIS EXAMPLE BEFORE YOU START AND WHILE YOU ; ARE CODING! ; (display "\n\n----------------------------\n") (display "Problem 1: roll-2-dice") (display "\n----------------------------\n") ; ; Write a function roll-2-dice that takes no input and returns the ; result of rolling two 6-sided dice. The output of this function ; should be a random number between 1 and 12. ; ; Do not use literal values in this function. ; (newline) (newline) (display "\n\n----------------------------\n") (display "Problem 2: give-instructions") (display "\n----------------------------\n") ; ; Write a zero-parameter function called give-instructions that ; prints the instructions to play the casino game craps. The ; instructions should be printed using a sequence of printf ; statements and should look like the example below: ; ; ; ; ; Hello and welcome to the Lucky Craps Game!! ; ; ; ; The game is easy, just roll a pair of dice. ; ; ; ; Here are the rules: ; ; 1. If you roll a 7 or 11, that's a natural and you win. ; ; 2. If you roll a 2, 3 or 12, that's craps and you lose. ; ; 3. If you roll a 4, 5, 6, 8, 9, or 10, keep rolling until: ; ; 4. you roll the same number as in step 3 and win, or ; ; 5. you roll a 7 and lose. ; ; ; ; ; ; Ready to play? (y or n) ; ; ; ; ; You can use literal values in your printf statements in this ; function. ; ; After you have written all the printf statements to generate the ; instructions, the give-instructions function should read the user ; response to the question "Ready to play (y or n)?" and either have ; the give-instructions function call itself if the answer is y ; (this will be changed as you develop the game) or print a goodbye ; message if the answer is n. ; ; The give-instructions function should produce only void output. ; (newline) (newline) (display "\n\n----------------------------\n") (display "Problem 3: ask-to-play-again") (display "\n----------------------------\n") ; ; Write a zero-parameter function called ask-to-play-again that ; returns a void output. The function should print the question ; ; "Do you want to play again (y or n)?" ; ; and read the response. ; ; If the user types y, ask-to-play-again should call itself (this will ; be changed later as you develop the game) or, if the user types n, ; it should print "So long!!" (or your preferred ending message) and ; stop. ; (newline) (newline) (display "\n\n----------------------------\n") (display "Problem 4: roll-for-point") (display "\n----------------------------\n") ; ; Write a one-parameter function called roll-for-point that consumes ; a number and returns a void output. Assume the input parameter is ; called point. ; ; The function should implement the following algorithm: ; ; 1. Define a local constant MATCH to contain the result of calling ; roll-2-dice (the result of rolling two 6-sided dice). ; ; 2. Print "You rolled " MATCH (the result of the roll). ; ; 3. If MATCH = 7: ; a. tell the user they lost and ; b. call the ask-to-play-again function. ; ; 4. Else If MATCH = point: ; a. tell the user they matched their point and won and ; b. call the ask-to-play-again function. ; ; 5. Else MATCH is not equal to 7 or point: ; a. call function roll-for-point, passing in point as an argu- ; ment. ; (newline) (newline) (display "\n\n----------------------------\n") (display "Problem 5: start-game") (display "\n----------------------------\n") ; ; The final function in the game is called start-game. This is a ; a zero-parameter function that returns a void output. The function ; should implement the following algorithm: ; ; 1. Define a local constant ROLL to contain the result of calling ; roll-2-dice (the result of rolling two 6-sided dice). ; ; 2. If ROLL = 7 or 11 : ; a. print "You rolled " ROLL, ; b. tell the user they win, and ; c. call the ask-to-play-again function. ; ; 3. Else If ROLL = 2, 3, or 12 : ; a. print "You rolled " ROLL, ; b. tell the user they lose, and ; c. call the ask-to-play-again function. ; ; 4. Else (ROLL = 4 5 6 8 9 or 10) : ; a. print "You rolled " ROLL, ; b. ask the user if they want to roll for a match, and ; i) If the user types y, call function roll-for-point ; ii) Else If the user types n, call the ask-to-play-again ; function. ; ; After you have implemented this function, go back to problems ; 2 and 3 and change them so that, instead of calling themselves ; recursively when the user types y, they call start-game. ; (newline) (newline) ;; IMPORTANT: LOOK AT EXAMPLE BELOW BEFORE STARTING TO CODE!! ; ; When you are finished, you should be able to start the game by ; typing (give-instructions) in the interactions window. ; ; The following box shows an example of playing this game in the ; interactions window: ; ; ; > (give-instructions) ; ; ; ; Hello and welcome to the Lucky Craps Game!! ; ; ; ; ; ; The game is easy, just roll a pair of dice. ; ; ; ; Here are the rules: ; ; 1. If you roll a 7 or 11, that's a natural and you win. ; ; 2. If you roll a 2, 3 or 12, that's craps and you lose. ; ; 3. If you roll a 4, 5, 6, 8, 9, or 10, keep rolling until: ; ; 4. you roll the same number as in step 3 and win, or ; ; 5. you roll a 7 and lose. ; ; ; ; ; ; Ready to play? (y or n) ; ; y ; ; ; ; ; ; You rolled 2 and you lose. ; ; ; ; ; ; Do you want to play again (y or n)? ; ; y ; ; ; ; ; ; You rolled 11 and you win! ; ; ; ; ; ; Do you want to play again (y or n)? ; ; y ; ; ; ; ; ; You rolled 9. ; ; ; ; Do you want to try to match this (y or n)? ; ; y ; ; ; ; You rolled 12. ; ; ; ; ; ; You rolled 5. ; ; ; ; ; ; You rolled 9. ; ; You made your point. You win! ; ; ; ; ; ; ; ; Do you want to play again (y or n)? ; ; n ; ; ; ; So long!! ; ; > ; ; ;