Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

HW1 for CIS151

Instructions:

Complete the coding project described in the following pages and submit your implementation on Blackboard as the single completed file helpers .py. You can leave out the other .py files included with this assignment, because they will be replaced with the instructor’s copies anyway.

Note: You are expected to complete this homework on your own. Do not copy answers from your classmates. At first glance, your instructions may look similar to your classmates’, but there are differences in the details that will impact your solution. If you submit answers that solve another student’s instructions instead of your own, you will be reported to the

academic integrity office.

Introduction:

In this exercise you will implement a single-player text-based farming game.  The following three sections provide an overview  of the game, an explanation of the included  .py files and how they

are organized, and the specific tasks you need to complete.

Overview:

In this game you raise chickens, buy supplies, sell products, and pay rent each day. Rent gradually increases.  The objective is to keep a positive balance in your bank account as long as possible. Each turn of the game represents another day on the farm, and repeats the following steps in order:

1. The current day, rent payment, account balance, chicken inventory, egg inventory, and grub inventory are displayed to the player.

2. The player decides how many new grubs to buy. Grub is food for the chickens. The amount you can buy is limited by your current account balance, as well as available supply at the grub store.

3. The player decides how many eggs to sell.  The amount you can sell is limited by current egg inventory, as well as current demand at the egg market. Different days of the week have different demand, and some days the market is closed so no eggs can be sold.

4. The chickens are fed grubs.  Each chicken requires a daily serving size to survive, and you feed the daily serving size to as many chickens as possible. If there is not enough grub to feed all the chickens, the unfed chickens are slaughtered and sold.

5. The remaining chickens lay new eggs, increasing egg inventory. Different chickens lay different numbers of eggs.

6. Some eggs are hatched, decreasing egg inventory and increasing chicken inventory.

7. The current rent payment is made, and then the daily rent payment is increased.  If the account balance is below zero, the game ends.

Code organization:

This project involves three Python files:

• helpers .py: This file contains several “helper”functions that implement various parts of the game. For example, one function calculates the number of eggs that hatch on any given day.

You need to complete the implementations of these functions and submit this completed file on blackboard.

• farming .py: This is the script you run to play the game. It contains a main game loop that repeats the daily game activities until the player’s account balance runs out. This script uses the helper functions in the previous file and will not work properly until they are completed. You should not edit this file, or else the game may not work properly. You do not need to submit this file.

• farm tests .py: This is the script you run to check your work. It tests the helper functions you are implementing, tells you which ones are working, and calculates your current grade. You should run this script many times while working on your homework to check your progress. You do not need to submit this file, and it will be replaced by the instructor’s copy for grading anyway. You should not edit this file, or else the score it shows you may be inaccurate.  The score that you see when you run this script will be your grade on the homework.  For each test, you get 0 points if your function crashes, 1 point if it returns an incorrect output, and 2 points (full credit) if it returns the correct output.

Specific tasks:

These are the specific tasks you need to complete. It is recommended you complete them in order, and rerun farm tests .py every time you complete another task to check your grade. You can find additional details in the TODO comments and type annotations in helpers .py.

• Implement the next day function in helpers .py.  This function accepts one parameter for the current day of the week, and returns the next day of the week.

• Implement the max grubs function in helpers .py. This function accepts one parameter for the current account balance, and returns the maximum number of grubs that can be bought. Each grub costs 0.05$, and you cannot buy more grubs than you can afford with your current balance. You also cannot buy more than 800 grubs, which is the maximum amount of grubs in stock at the store each day.

• Implement the max dozens function in helpers .py. This function accepts two parameters for the current egg inventory and day of the week, and returns the maximum number of dozens that can be sold.  One dozen” is 12 eggs, and you can only sell a whole number of dozens. You can not sell more eggs than you have in inventory, and can not sell more than customers want.  Eggs are most popular on Wednesday and Thursday, when you can sell at most 9 dozens. On the other days, you can sell at most 6 dozens. No eggs are sold on weekends when the market is closed.

• Implement the measure feed function in helpers .py. This function accepts two parameters for the current grub and chicken inventory levels, and returns the total amount of grub that will be used for feeding today.  Each chicken must be fed either 8 or 0 grubs, and you must feed 8 grubs each to as many chickens in inventory as possible. Any remaining chickens will eat nothing. You can not use more grub than you have in inventory.

• Implement the slaughter chickens function in helpers .py.   This function accepts two parameters for the current grub and chicken inventory levels, and returns the number of chickens that were not fed today.  As stated for the previous method, this is the number of unfed chickens remaining, after feeding exactly 8 grubs to as many chickens as possible. This number of unfed chickens will be non-zero whenever there is not enough grub inventory to feed every chicken 8 grubs. Sadly, these unfed chickens will be slaughtered and sold.

• Implement the lay eggs function in helpers .py.  This function accepts one parameter for the current number of chickens in inventory, and returns the total number of eggs laid today. If there are zero chickens, then zero eggs are laid.  If there is one chicken, then 11 eggs are laid.   Otherwise, different chickens produce different numbers of eggs.   Suppose you have N > 1 chickens and number them 1, 2, ...,N, from least to most productive. The 1st  chicken produces zero eggs per day, and the Nth  chicken produces 11 eggs per day.  In general, for 1 ≤ k ≤ N, the number of eggs produced by the kth  chicken is:

where「x⌋ is the largest integer less than or equal to x. So, the total number of eggs laid is:

As a concrete example, if you have N = 3 chickens, the total eggs laid is:

• Implement the hatch function in helpers .py.  This function accepts one parameter for the current number of eggs in inventory, and returns the number of eggs that hatch new baby chicks today. 20% of the eggs (rounded to the nearest integer) hatch each day.