CS 61A Project 1: The Game of Hog

Posted accepteddoge

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.
    Example 1: The current player has a total score of 37 and the opponent has 92. The current player rolls two dice that total 9. The opponent‘s score (92) is exactly twice the player‘s new total score (46). These scores are swapped! The current player now has 92 points and the opponent has 46. The turn ends.
    Example 2: The current player has 91 and the opponent has 37. The current player rolls five dice that total 20. The current player has 111, which is 3 times 37, so the scores are swapped. The opponent ends the turn with 111 and wins the game.

技术分享图片

Phase 1: Simulator

In the first phase, you will develop a simulator for the game of Hog.

Problem 0 (0 pt)

The dice.py file represents dice using non-pure zero-argument functions. These functions are non-pure because they may have different return values each time they are called. The documentation of dice.py describes the two different types of dice used in the project:

  • Dice can be fair, meaning that they produce each possible outcome with equal probability. Example: six_sided.
  • For testing functions that use dice, deterministic test dice always cycle through a fixed sequence of values that are passed as arguments to the make_test_dice function.

Before we start writing any code, read over the dice.py file and check your understanding by unlocking the following tests.

以上是关于CS 61A Project 1: The Game of Hog的主要内容,如果未能解决你的问题,请参考以下文章

CS61A Fall 2020 Project 2 Autocorrected Typing Software 我的思路

CS61A 2022 fall HW 01: Functions, Control

CS61A学习笔记 lecture1 Computer science

CS61A 2022 fall lab01

CS61A 2022 fall lab0

[2021 Spring] CS61A 学习笔记 lecture 9 Function Examples