you're reading...

Ants versus Somebees: CS1 OOP Project

Screenshot of Ants Versus Somebees

Screen Shot 2016-03-23 at 7.30.42 AM

Core Concepts

A game of Ants Vs. SomeBees consists of a series of turns. In each turn, new bees may enter the ant colony. Gamers select new ants and place them in the colony. Finally, all insects (ants, then bees) take individual actions: bees sting ants, and ants throw leaves at bees. The game ends either when a bee reaches the ant queen (you lose), or the entire bee flotilla has been vanquished (you win).

The Colony. The colony consists of several places that are chained together. The exit of each Place leads to anotherPlace.

Placing Ants. There are two constraints that limit ant production. Placing an ant uses up some amount of the colony’s food, a different amount for each type of ant. Also, only one ant can occupy each Place.

Bees. When it is time to act, a bee either moves to the exit of its current Place if no ant blocks its path, or stings an ant that blocks its path.

Ants. Each type of ant takes a different action and requires a different amount of 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.

The Code

Most concepts in the game have a corresponding class that encapsulates the logic for that concept. For instance, a Place in the colony holds insects and connects to other places. A Bee stings ants and advances through exits.

Here is a listing of specification and prototypes for the main classes: Place, Insect, and Colony classes and the associated subclasses:

The game can be run in three modes: as a text-based game, a low-resolution graphical user interface, and an advanced Web-based GUI. The game logic is the same in all cases, but the GUIs enforce a turn time limit that makes playing the game more exciting. The text-based interface is provided for debugging and development.

The full module and problem sets can be found at this link http://cs61a.org/proj/ants/

Unzip the ants.zip archive by downloading http://cs61a.org/proj/ants/ants.zip . The main program file is ants.py,  which knows nothing of graphics or turn time limits, as those aspects can be considered hidden information.

To start a text-based game, go to a shell and change directories to ants, then run

python3 ants.py

To start a tkinter-based graphical game, run

python3 ants_gui.py

To start a web-based graphical game, run

python3 gui.py

A Class Diagram for Ants versus Somebees


Screen Shot 2016-03-23 at 11.24.07 AM




No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: