Hands-On Example 2.3B Hands-On Example 2.3B Review an Algorithm A The algorithm to o play Rock-Paper-Scissors is writ tt en out in Figure 2-8. The algorithm should be tested and d reviewed. Find a person to be th he second player to evaluate the algorithm. 1 Choose what ob bj ect you will play: rock, paper, or r scissors. 2 Agree with second o player that it is time to play. 3 Count to three. 4 Immediately bo ot h players “throw.” 5 Evaluate the outcome: Player 1 Player 1 Player 2 Player 2 Outcome Outcome Result Result You throw rock. Second player throws rock. A tie. Play again. Second player throws paper. You lose. Game over. Second player throws scissors. You win. Game over. You throw paper. Second player throws paper. A tie. Play again. Second player throws rock. You win. Game over. Second player throws scissors. You lose. Game over. You throw scissors. Second player throws scissors. A tie. Play again. Second player throws rock. You lose. Game over. Second player throws paper. You win. Game over. 6 Together with your y partner, write a statement about how accurate the algorithm is for playing this game. m Suggest improvements. Try It! The object of the h License Plate Game is to be the h first one to find all letters of the alphabet. The challenge e is that the letters must come m from license plates you see while driving, and the lett te rs must be found in alphabetical c order. Write an algorithm to play this game. Carry Out the Plan Write out the rules for the game. Format them in a number list to make following the rules easy. Then, play the game a few times with a classmate. Follow the rules exactly as written. Review and Reflect The final step is to review and reflect on the plan. Did the steps above cover every situation? Were the outcomes correct? Identify any part of the plan that needs to be updated or corrected. Copyright Goodheart-Willcox Co., Inc. 36 Introduction to Computer Science: Coding
Previous Page Next Page