CS 61A Project 1: The Game of Hog

Introduction

In this project, you will develop a simulator and multiple strategies for the dice game Hog. You will need to use control statements and higher-order functions together, as described in Sections 1.2 through 1.6 of Composing Programs.

In Hog, two players alternate turns trying to be the first to end a turn with at least 100 total points. On each turn, the current player chooses some number of dice to roll, up to 10. That player's score for the turn is the sum of the dice outcomes.

To spice up the game, we will play with some special rules:

  • Pig Out. If any of the dice outcomes is a 1, the current player's score for the turn is 1.
  • Example 1: The current player rolls 7 dice, 5 of which are 1's. They score 1 point for the turn.
  • Example 1: The current player rolls 7 dice, 5 of which are 1's. They score 1 point for the turn.

  • Free Bacon. A player who chooses to roll zero dice scores 2 more than the absolute difference between the digits in the opponent's total score.
  • Example 1: If the opponent has 42 points, the current player gains 2 + abs(4 - 2) = 4 points by rolling zero dice.
  • Example 2: If the opponent has 42 points, the current player gains 2 + abs(4 - 2) = 4 points by rolling zero dice.
  • Example 2: If the opponent has 48 points, the current player gains 2 + abs(4 - 8) = 6 points by rolling zero dice.

  • Swine Swap. After points for the turn are added to the current player's score, if both scores are larger than 1 and either one of the scores is a positive integer multiple of the other, then the two scores are swapped.

猜你喜欢

转载自www.cnblogs.com/accepteddoge/p/8989439.html
61A