代写代考 CS 88 Fall 2022

Project 2: Ants Vs. SomeBees | CS 88 Fall 2022

12/7/22, 10:55 PMProject 2: Ants Vs. SomeBees | CS 88 Fall 2022

Copyright By PowCoder代写 加微信 powcoder

Page 1 of 26https://c88c.org/fa22/proj/ants/

The bees are coming!
Create a better soldier

With inherit-ants.

Introduction

Grading Updates
Parts 1, 2 and 3, are the only required parts. Submitting Parts 1, 2, and 3 will be worth 60 points.
There will be no EC early submission points. There will be no composition grading, nor
checkpoint, but a submission by the deadline will earn you 4 pts for the checkpoint, and 2 points
for composition. (6 points total). You must complete phase 1 and phase to get the 8 points.
Phases 1, 2, and 3 will be scaled to 54 points. Phase 4 will be EC for everyone, up to 73 points
total. (Basically, ants_score = min(73, raw_score*(54/41)) .)

Project 2: Ants Vs.

ants.zip (ants.zip)

https://c88c.org/fa22/proj/ants/ants.zip

12/7/22, 10:55 PMProject 2: Ants Vs. SomeBees | CS 88 Fall 2022

Page 2 of 26https://c88c.org/fa22/proj/ants/

Important submission note: For full credit,
Submit with Phase 1 and 2 complete by Sunday, November 20 (worth 4 pts).
Submit with all phases complete by Thursday, December 1. You can get 2 EC points by
submitting the entire project by Tuesday, November 29.

Try to attempt the problems in order, as some later problems will depend on earlier problems in
their implementation and therefore also when running ok tests.

The entire project can be completed with a partner. Consider using Visual Studio Code Live Share
(https://code.visualstudio.com/learn/collaboration/live-share) to synchronously work on code with
your partner. <<<<<<< HEAD ~~You can get 2 EC points by submitting the entire project by~~ ~~Tuesday, November 29.~~ The entire project is now due Monday, December 5. See Grading Updates below for more details. >>>>>> afeafbad4293a0954930a672c655275ec7feadd1

In this project, you will create a tower defense
(https://secure.wikimedia.org/wikipedia/en/wiki/Tower_defense) game called Ants Vs. SomeBees. As the
ant queen, you populate your colony with the bravest ants you can muster. Your ants must protect their
queen from the evil bees that invade your territory. Irritate the bees enough by throwing leaves at them,
and they will be vanquished. Fail to pester the airborne intruders adequately, and your queen will
succumb to the bees’ wrath. This game is inspired by PopCap Games’ Plants Vs. Zombies
(https://www.ea.com/studios/popcap/plants-vs-zombies).

This project uses an object-oriented programming paradigm, focusing on material from Chapter 2.5
(http://composingprograms.com/pages/25-object-oriented-programming.html) of Composing
Programs. The project also involves understanding, extending, and testing a large program.

Download starter files
The ants.zip (ants.zip) archive contains several files, but all of your changes will be made to ants.py .

ants.py : The game logic of Ants Vs. SomeBees
ants_gui.py : The original GUI for Ants Vs. SomeBees
gui.py: A new GUI for Ants Vs. SomeBees.
graphics.py : Utilities for displaying simple two-dimensional animations
utils.py : Some functions to facilitate the game interface
ucb.py : Utility functions for CS 88
state.py : Abstraction for gamestate for gui.py
assets : A directory of images and files used by gui.py
img : A directory of images used by ants_gui.py
ok : The autograder
proj3.ok : The ok configuration file
tests : A directory of tests used by ok

You can obtain all the files needed for this project by downloading this zip archive (ants.zip).

This is a project. You may work with one other partner. You should not share your code with students
who are not your partner or copy from anyone else’s solutions.

In the end, you will submit one project for both partners. The project is worth 60 points.

https://code.visualstudio.com/learn/collaboration/live-share
https://secure.wikimedia.org/wikipedia/en/wiki/Tower_defense
https://www.ea.com/studios/popcap/plants-vs-zombies
http://composingprograms.com/pages/25-object-oriented-programming.html
https://c88c.org/fa22/proj/ants/ants.zip
https://c88c.org/fa22/proj/ants/ants.zip

12/7/22, 10:55 PMProject 2: Ants Vs. SomeBees | CS 88 Fall 2022

Page 3 of 26https://c88c.org/fa22/proj/ants/

The project is worth 60 points. 54 points are assigned for correctness, 2 points for composition, 4
points for submitting Phase 1 and 2 by the checkpoint date

~~Additionally, there are some extra credit point opportunities.~~ ~~You can get 2 EC point for
submitting the entire project by~~ ~~Tuesday, November 29, and~~ ~~2 EC points for submitting the
extra credit problem.~~

~~Important:~~ ~~In order to receive all of the extra credit points for Ants,~~ ~~your
implementation of the entire project,~~ ~~including the EC problem,~~ ~~must be submitted by
the early submission deadline.~~

Grading Updates
Parts 1, 2 and 3, are the only required parts. Submitting Parts 1, 2, and 3 will be worth 60 points.
There will be no EC early submission points. There will be no composition grading, nor
checkpoint, but a submission by the deadline (Monday, December 5) will earn you 4 pts for the
checkpoint, and 2 points for composition. (6 points total). You must complete phase 1 and phase
to get the 8 points. Phases 1, 2, and 3 will be scaled to 54 points. Phase 4 will be EC for
everyone, up to 70 points total. (Basically, ants_score = min(70, raw_score*(54/41)) ).

You will turn in the following files:

You do not need to modify or turn in any other files to complete the project. To submit the project, run
the following command:

python3 ok –submit

You will be able to view your submissions on the Ok dashboard (https://okpy.org/).

For the functions that we ask you to complete, there may be some initial code that we provide. If you
would rather not use that code, feel free to delete it and start from scratch. You may also add new
function definitions as you see fit.

However, please do not modify any other functions. Doing so may result in your code failing our
autograder tests. Also, please do not change any function signatures (names, argument order, or
number of arguments).

Throughout this project, you should be testing the correctness of your code. It is good practice to test
often, so that it is easy to isolate any problems.

We have provided an autograder called ok to help you with testing your code and tracking your

The primary purpose of ok is to test your implementations, but there is a catch. At first, the test cases
are locked. To unlock tests, run the following command from your terminal.

python3 ok -u

https://okpy.org/

12/7/22, 10:55 PMProject 2: Ants Vs. SomeBees | CS 88 Fall 2022

Page 4 of 26https://c88c.org/fa22/proj/ants/

Run the specific version of this command as detailed in each problem. This command will start an
interactive prompt that looks like:

=====================================================================
Assignment: Ants Vs. SomeBees
OK, version …
=====================================================================

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unlocking tests

At each “? “, type what you would expect the output to be.
Type exit() to quit

———————————————————————
Question 0 > Suite 1 > Case 1
(cases remaining: 1)

>>> Code here

At the ? , you can type what you expect the output to be. If you are correct, then this test case will be
available the next time you run the autograder.

The idea is to understand conceptually what your program should do first, before you start writing any

Once you have unlocked some tests and written some code, you can check the correctness of your
program using the tests that you have unlocked:

python3 ok

Most of the time, you will want to focus on a particular question. Use the -q option as directed in the
problems below.

The tests folder is used to store autograder tests, so make sure not to modify it. You may lose all
your unlocking progress if you do. If you need to get a fresh copy, you can download the zip archive
(ants.zip) and copy it over, but you will need to start unlocking from scratch.

If you are ever stuck on a problem, you should add print statements to your code to help debug. Use
print(“DEBUG:”, variable) to see the value of variable and still have your tests pass.

A game of Ants Vs. SomeBees consists of a series of turns. In each turn, new bees may enter the ant
colony. Then, new ants are placed to defend their colony. Finally, all insects (ants, then bees) take
individual actions. Bees either try to move toward the end of the tunnel or sting ants in their way. Ants
perform a different action depending on their type, such as collecting more food or throwing leaves at
the bees. The game ends either when a bee reaches the end of the tunnel (you lose), the bees destroy
the QueenAnt if it exists (you lose), or the entire bee fleet has been vanquished (you win).

https://c88c.org/fa22/proj/ants/ants.zip

12/7/22, 10:55 PMProject 2: Ants Vs. SomeBees | CS 88 Fall 2022

Page 5 of 26https://c88c.org/fa22/proj/ants/

Core concepts
The Colony. This is where the game takes place. The colony consists of several Place s that are
chained together to form a tunnel where bees can travel through. The colony also has some quantity of
food which can be expended in order to place an ant in a tunnel.

Places. A place links to another place to form a tunnel. The player can put a single ant into each place.
However, there can be many bees in a single place.

The Hive. This is the place where bees originate. Bees exit the beehive to enter the ant colony.

Ants. Players place an ant into the colony by selecting from the available ant types at the top of the
screen. Each type of ant takes a different action and requires a different amount of colony food to place.
The two most basic ant types are the HarvesterAnt , which adds one food to the colony during each
turn, and the ThrowerAnt , which throws a leaf at a bee each turn. You will be implementing many

Bees. In this game, bees are the antagonistic forces that the player must defend the ant colony from.
Each turn, a bee either advances to the next place in the tunnel if no ant is in its way, or it stings the ant
in its way. Bees win when at least one bee reaches the end of a tunnel.

Core classes
The concepts described above each have a corresponding class that encapsulates the logic for that
concept. Here is a summary of the main classes involved in this game:

GameState : Represents the colony and some state information about the game, including how
much food is available, how much time has elapsed, where the AntHomeBase is, and all the
Place s in the game.
Place : Represents a single place that holds insects. At most one Ant can be in a single place,
but there can be many Bee s in a single place. Place objects have an exit to the left and an
entrance to the right, which are also places. Bees travel through a tunnel by moving to a
Place ‘s exit .
Hive : Represents the place where Bee s start out (on the right of the tunnel).
AntHomeBase : Represents the place Ant s are defending (on the left of the tunnel). If Bees get
here, they win 🙁
Insect : A superclass for Ant and Bee . All insects have health attribute, representing their

*ExitGUI Food:2 Time:

Harvester Short Long Hungry Slow Bodyguard

Pickatypeof

Don’tletthe
beesreachthe

Placeantsin

Attackingbees
movefromright

12/7/22, 10:55 PMProject 2: Ants Vs. SomeBees | CS 88 Fall 2022

Page 6 of 26https://c88c.org/fa22/proj/ants/

remaining health, and a place attribute, representing the Place where they are currently
located. Each turn, every active Insect in the game performs its action .
Ant : Represents ants. Each Ant subclass has special attributes or a special action that
distinguish it from other Ant types. For example, a HarvesterAnt gets food for the colony and
a ThrowerAnt attacks Bee s. Each ant type also has a food_cost attribute that indicates how
much it costs to deploy one unit of that type of ant.
Bee : Represents bees. Each turn, a bee either moves to the exit of its current Place if the
Place is not blocked by an ant, or stings the ant occupying its same Place .

Game Layout
Below is a visualization of a GameState. As you work through the unlocking tests and problems, we
recommend drawing out similar diagrams to help your understanding.

Object map
To help visualize how all the classes fit together, we’ve also created an object map for you to reference
as you work, which you can find here (assets/ants_diagram.pdf):

https://c88c.org/fa22/proj/ants/assets/ants_diagram.pdf

12/7/22, 10:55 PMProject 2: Ants Vs. SomeBees | CS 88 Fall 2022

Page 7 of 26https://c88c.org/fa22/proj/ants/

Playing the game
The game can be run in two modes: as a text-based game or using a graphical user interface (GUI). The
game logic is the same in either case, but the GUI enforces a turn time limit that makes playing the
game more exciting. The text-based interface is provided for debugging and development.

The files are separated according to these two modes. ants.py knows nothing of graphics or turn
time limits.

To start a text-based game, run

python3 ants_text.py

To start a graphical game, run

python3 gui.py

When you start the graphical version, a new browser window should appear. In the starter
implementation, you have unlimited food and your ants can only throw leaves at bees in their current
Place . Before you complete Problem 2, the GUI may crash since it doesn’t have a full conception of
what a Place is yet! Try playing the game anyway! You’ll need to place a lot of ThrowerAnt s (the
second type) in order to keep the bees from reaching your queen.

The game has several options that you will use throughout the project, which you can view with
python3 ants_text.py –help .

usage: ants_text.py [-h] [-d DIFFICULTY] [-w] [–food FOOD]

Play Ants vs. SomeBees

optional arguments:
-h, –help show this help message and exit
-d DIFFICULTY sets difficulty of game (test/easy/normal/hard/extra-hard)
-w, –water loads a full layout with water
–food FOOD number of food to start with when testing

Getting Started Videos
These videos may provide some helpful direction for tackling the coding problems on the project. Note
that these videos start providing help at Q4 and that the Q12 video does not apply to this version of the
project. You can watch the videos provided here (https://www.youtube.com/watch?
v=QrWrKAuxSy8&list=PLx38hZJ5RLZdWOZuRdQp7pcbswC4DT3pA&index=1).

To see these videos, you should be logged into your berkeley.edu email.

Phase 1: Basic gameplay
Important submission note: For full credit, submit with Phase 1 and 2 complete by Thursday,
November 17 (worth 4 pts).

In the first phase you will complete the implementation that will allow for basic gameplay with the two
basic Ant s: the HarvesterAnt and the ThrowerAnt .

https://www.youtube.com/watch?v=QrWrKAuxSy8&list=PLx38hZJ5RLZdWOZuRdQp7pcbswC4DT3pA&index=1

12/7/22, 10:55 PMProject 2: Ants Vs. SomeBees | CS 88 Fall 2022

Page 8 of 26https://c88c.org/fa22/proj/ants/

Problem 0 (0 pt)
Answer the following questions with your partner after you have read the entire ants.py file.

To submit your answers, run:

python3 ok -q 00 -u

If you get stuck while answering these questions, you can try reading through ants.py again, consult
the core concepts/classes sections above, or ask a question in the Question 0 thread on Piazza.

1. What is the significance of an Insect’s health attribute? Does this value change? If so, how?
2. Which of the following is a class attribute of the Insect class?
3. Is the health attribute of the Ant class an instance attribute or a class attribute? Why?
4. Is the damage attribute of an Ant subclass (such as ThrowerAnt ) an instance attribute or class

attribute? Why?
5. Which class do both Ant and Bee inherit from?
6. What do instances of Ant and instances of Bee have in common?
7. How many insects can be in a single Place at any given time (before Problem 8)?
8. What does a Bee do during one of its turns?
9. When is the game lost?

Remember to run:

python3 ok -q 00 -u

Problem 1 (3 pt)
Before writing any code, read the instructions and test your understanding of the problem:

python3 ok -q 01 -u

Part A: Currently, there is no cost for placing any type of Ant , and so there is no challenge to the
game. The base class Ant has a food_cost of zero. Override this class attribute for HarvesterAnt
and ThrowerAnt according to the “Food Cost” column in the table below.

Class Food Cost Initial Health

HarvesterAnt

12/7/22, 10:55 PMProject 2: Ants Vs. SomeBees | CS 88 Fall 2022

Page 9 of 26https://c88c.org/fa22/proj/ants/

ThrowerAnt

Part B: Now that placing an Ant costs food, we need to be able to gather more food! To fix this issue,
implement the HarvesterAnt class. A HarvesterAnt is a type of Ant that adds one food to the
gamestate.food total as its action .

After writing code, test your implementation:

python3 ok -q 01

Try playing the game by running python3 gui.py . Once you have placed a HarvesterAnt , you
should accumulate food each turn. You can also place ThrowerAnt s, but you’ll see that they can only
attack bees that are in their Place , making it a little difficult to win.

Problem 2 (3 pt)
Before writing any code, read the instructions and test your understanding of the problem:

python3 ok -q 02 -u

In this problem, you’ll complete Place.__init__ by adding code that tracks entrances. Right now, a
Place keeps track only of its exit . We would like a Place to keep track of its entrance as well. A
Place needs to track only one entrance . Tracking entrances will be useful when an Ant needs to
see what Bee s are in front of it in the tunnel.

However, simply passing an entrance to a Place constructor will be problematic; we would need to
have both the exit and the entrance before creating a Place ! (It’s a chicken or the egg
(https://en.wikipedia.org/wiki/Chicken_or_the_egg) problem.) To get around this problem, we will keep
track of entrances in the following way instead. Place.__init__ should use this logic:

A newly created Place always starts with its entrance as None .
If the Place has an exit , then the exit ‘s entrance is set to that Place .

Hint: Remember that when the __init__ method is called, the first parameter, self , is bound
to the newly created object

Hint: Try drawing out two Place s next to each other if things get confusing. In the GUI, a place’s
entrance is to its right while the exit is to its left.

https://en.wikipedia.org/wiki/Chicken_or_the_egg

12/7/22, 10:55 PMProject 2: Ants Vs. SomeBees | CS 88 Fall 2022

Page 10 of 26https://c88c.org/fa22/proj/ants/

Hint: Remember that Places are not stored in a list, so you can’t index into anything to access
them. This means that you can’t do something like colony[index + 1] to access an adjacent
Place . How can you move from one place to another?

After writing code, test your implementation:

python3 ok -q 02

Problem 3 (3 pt)
Before writing any code, read the instructions and test your understanding of the problem:

python3 ok -q 03 -u

In order for a ThrowerAnt to throw a leaf, it must know which bee to hit. The provided implementation
of the nearest_bee method in the ThrowerAnt class only allows them to hit bees in the same
Place . Your job is to fix it so that a ThrowerAnt will throw_at the nearest bee in front of it that is
not still in the Hive . This includes bees that are in the same Place as a ThrowerAnt

Hint: All Place s have an is_hive attribute which is True when that place is the Hive .

Change nearest_bee so that it returns a random Bee from the nearest place that contains bees. Your
implementation should follow this logic:

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com