Compuzzlehttps://compuzzle.wordpress.com
@Proffreda: I'm a ramblin' computer science guySat, 12 May 2018 20:54:43 +0000enhourly1http://wordpress.com/https://secure.gravatar.com/blavatar/accf0128930e424abd23d177714542e0?s=96&d=https%3A%2F%2Fs0.wp.com%2Fi%2Fbuttonw-com.pngCompuzzlehttps://compuzzle.wordpress.com
Ranking Computing Buzzwordshttps://compuzzle.wordpress.com/2017/05/28/ranking-computing-buzzwords/
https://compuzzle.wordpress.com/2017/05/28/ranking-computing-buzzwords/#respondSun, 28 May 2017 21:35:13 +0000http://compuzzle.wordpress.com/?p=2217Continue reading →]]>The rapid growth and diversification of computing technologies has resulted in a significant number of terms that some consider “computing buzzwords”. And this growing collection of buzzwords signifies a paradox. On the one hand, identifying a key term as a buzzword implies that there is a popular opinion regarding the lack of value in its usage. On the other hand, each buzzword has a substantial frequency of usage within a least one community, and thus signals that a group of people regularly use the term to communicate about an important issue. What, if anything, can computing buzzwords tell us about the current problems faced by software developers? Can examining buzzwords open possibilities of finding better, common language to communicate about the underlying challenges of the software industry?

In this article we will rank the set of common computing buzzwords. The ranking measure we apply is one associated with measuring how important the term is in context of computing education. Our hypothesis is that a buzzword of value should be one that is relevant to computing educators. For this study we chose our initial list of buzzwords sourced from the Wikipedia article on topic of “list of buzzwords” (see, https://en.wikipedia.org/wiki/List_of_buzzwords). From this article we filtered all terms associated with the topics of modern computing practices and software development.

To determine the relevance of each of these terms to educational aims, we considered a document that was produced by a large number of computing professionals in the field of Computer Science Education. We used this document as a proxy to measure the value of these buzzwords for educational purpose. The document we analyzed is the influential report developed by the Joint ACM/IEEE Task Force on Computing Curricula entitled “Computer Science Curricula 2013: Curriculum Guidelines for Undergraduate Degree Programs in Computer Science” (CS2013). This report outlines the knowledge units recognized by leading university educators as the essential concepts and taxonomy needed by software development professionals. The CS2013 curriculum report is 518 pages and articulates 308 core hours of knowledge units representing the state-of-the-art computing curriculum. Of these 308 hours it could be argued at least 200 hours (65%) directly or indirectly address software engineering concepts, practices, and methodologies supporting the software development process.

We have analyzed the CS2013 report and determined the word frequency of each of the Wikipedia computing buzzwords within the document. The following listing is the resulting word frequency data:

As we can see from the listing above, over 60% of these buzzwords appear with frequency 0, and thus do not appear in the report. Using the frequency as a ranking measure we have the following top 20 terms:

Algorithm

Machine Learning

Mobile

Scalability

Agile

Virtualization

Data Mining

Cloud

Frameworks (software)

Test-driven Development

Modularity

SaaS

Design Patterns

Digital Rights Management

Digital Divide

Workflow

Cross-platform

Plan-Driven Development

Content Management

Big data

Buzzwords in Software Development IndustryOf these top terms listed above, there are only a few that represent concepts associated with modern trends in software development industry, including, ‘Agile’, ‘Cloud’, ‘SaaS’, ’Scalability’, and ’Virtualization’. This is a somewhat surprising result, since the list is very small, and except for the term ‘Agile’ these terms refer to core business concerns in software licensing and delivery models, and administering, provisioning and deploying IT infrastructure.

Granted that the CS2013 document is now four years old, it is still remarkable that so few prominent buzzwords in popular media covering computing are recognized as important by leading CS Educators. Today, there is a lot of media attention going to IT topical areas such as Internet of Things, microservices, containers, continuous delivery, DevOps, Paas, web services, and so forth. Yet, computing educators and university curriculum apparently rarely use these terms in discourse on software development. More importantly, these terms are not a significant part of the discourse practiced by junior software development professionals.

One possible reason for this state of language divergence is that universities are free from the demands and constraints of marketing and customer demands in the computing industries. However, the successes and pain points of software development in academics may overlap significantly with business concerns in certain contexts. For example, in the university setting we see software development practice with very short production cycles, since in many course schedules students are expected to deliver working software on a weekly basis. And in many project-based courses, students are expected to work in teams, use test-driven development, use version control (usually git/github), and deliver well-tested substantial and complex software solutions.

Within the university there can be tension between teaching new technologies versus focusing on fundamental principles. Faculties have time constraints, which make it difficult to acquire new ideas, new approaches, and technologies and bring them effectively into courses and curricula. Much of the software industry focuses on platform-based development opportunities, such as Web, Mobile, Cloud, and Gaming platforms. The past several years have seen a growing diversity in the set of programmable devices that are employed in university programming courses. For example, some introductory courses have chosen to engage in web development or mobile device programming. Some courses have applied the use of specialty platforms, such as game consoles or robots. Some educators believe that modern platforms can generate interest and enthusiasm for Computer Science among freshman students. Yet, we find that the topic of Platform-Based Development (PBD) represents a new knowledge unit in the CS2013 report, and these newly introduced units are listed only as electives, which have no core hours indicated in the CS2013 report.

Buzzwords in Software Engineering CurriculumOne prominent academic course has brought widespread recognition to issues associated with industry-focussed software development buzzwords such a Saas, Cloud, Virtualization, and Agile development. The course CS169: Software Engineering, is led by University of California, Berkeley faculty members Armando Fox and David Patterson, see, https://sites.google.com/site/ucbsaas/. This course is the basis of two very popular massive open online courses (MOOCs) covering SaaS, software lifecycles, Agile, software project planning and management, requirements elicitation, behavior driven design and test driven development, and design patterns. The success of CS169 may represent the beginning of a new set of breakthrough opportunities for building a common language for discourse between computing professionals in academia and industry.

]]>https://compuzzle.wordpress.com/2017/02/15/cs-career-links/feed/1proffredaTest Driven Development in Pythonhttps://compuzzle.wordpress.com/2016/07/15/test-driven-development-in-python/
https://compuzzle.wordpress.com/2016/07/15/test-driven-development-in-python/#respondFri, 15 Jul 2016 03:04:19 +0000http://compuzzle.wordpress.com/?p=2158Continue reading →]]>Test-driven development (TDD) is a software development process that has been documented considerably over recent years. At its heart is the practice of baking tests right into your everyday coding, as opposed to an afterthought.

The doctest Module

There is a standard python module called “doctest” that is useful for setting up and easy to use TDD testing framework. The doctest module searches for pieces of text that look like interactive Python sessions inside of the documentation parts of a module, and then executes (or reexecutes) the commands of those sessions to verify that they work exactly as shown, i.e. that the same results can be achieved. In other words: The help text of the module is parsed for example python sessions. These examples are run and the results are compared against the expected value.

Usage of doctest:
To use “doctest” it has to be imported. The part of an interactive Python sessions with the examples and the output has to be copied inside of the docstring the the corresponding function.

We demonstrate this way of proceeding with the following simple example. We have slimmed down the previous module, so that only the function fib is left:

We copy the complete session of the interactive shell into the docstring of our function. To start the module doctest we have to call the method testmod(), but only if the module is called standalone. The complete module looks like this now:

import doctest

def fib(n):
“””
Calculates the n-th Fibonacci number iteratively

>>> fib(0)
0
>>> fib(1)
1
>>> fib(10)
55
>>> fib(15)
610
>>>
“””

a, b = 0, 1
for i in range(n):
a, b = b, a + b
return a

if __name__ == “__main__”:
doctest.testmod()

If we start our module directly like this

$ python3 fibonacci_doctest.py
we get no output, because everything is okay.

To see how doctest works, if something is wrong, we place an error in our code:
We change again

The output depicts all the calls, which return faulty results. We can see the call with the arguments in the line following “Failed example:”. We can see the expected value for the argument in the line following “Expected:”. The output shows us the newly calculated value as well. We can find this value behind “Got:”
Test-driven Development (TDD)

In the previous chapters, we tested functions, which we had already been finished. What about testing code you haven’t yet written? You think that this is not possible? It is not only possible, it is the un­der­ly­ing idea of test-dri­ven de­vel­opment. In the extreme case, you define tests be­fore you start coding the actual source code. The program developer writes an automated test case which defines the desired “behaviour” of a function. This test case will – that’s the idea behind the approach – initially fail, because the code has still to be written.

The major problem or diffi­culty of this approach is the task of writ­ing suitable tests. Naturally, the per­fect test would check all pos­si­ble in­puts and val­i­date the out­put. Of course, this is generally not always feasible.

We have set the return value of the fib function to 0 in the following example:

import doctest

def fib(n):
“””
Calculates the n-th Fibonacci number iteratively

>>> fib(0)
0
>>> fib(1)
1
>>> fib(10)
55
>>> fib(15)
610
>>>

“””

return 0

if __name__ == “__main__”:
doctest.testmod()

It hardly needs mentioning that the function returns except for fib(0) only wrong return values:

6. Modules

If you quit from the Python interpreter and enter it again, the definitions you
have made (functions and variables) are lost. Therefore, if you want to write a
somewhat longer program, you are better off using a text editor to prepare the
input for the interpreter and running it with that file as input instead. This
is known as creating a script. As your program gets longer, you may want to
split it into several files for easier maintenance. You may also want to use a
handy function that you’ve written in several programs without copying its
definition into each program.

To support this, Python has a way to put definitions in a file and use them in a
script or in an interactive instance of the interpreter. Such a file is called amodule; definitions from a module can be imported into other modules or into
the main module (the collection of variables that you have access to in a
script executed at the top level and in calculator mode).

A module is a file containing Python definitions and statements. The file name
is the module name with the suffix .py appended. Within a module, the
module’s name (as a string) is available as the value of the global variable__name__. For instance, use your favorite text editor to create a file
called fibo.py in the current directory with the following contents:

# Fibonacci numbers moduledeffib(n):# write Fibonacci series up to na,b=0,1whileb<n:print(b,end=' ')a,b=b,a+bprint()deffib2(n):# return Fibonacci series up to nresult=[]a,b=0,1whileb<n:result.append(b)a,b=b,a+breturnresult

Now enter the Python interpreter and import this module with the following
command:

>>> importfibo

This does not enter the names of the functions defined in fibo directly in
the current symbol table; it only enters the module name fibo there. Using
the module name you can access the functions:

If you intend to use a function often you can assign it to a local name:

>>> fib=fibo.fib>>> fib(500)1 1 2 3 5 8 13 21 34 55 89 144 233 377

6.1. More on Modules

A module can contain executable statements as well as function definitions.
These statements are intended to initialize the module. They are executed only
the first time the module is imported somewhere. [1]

Each module has its own private symbol table, which is used as the global symbol
table by all functions defined in the module. Thus, the author of a module can
use global variables in the module without worrying about accidental clashes
with a user’s global variables. On the other hand, if you know what you are
doing you can touch a module’s global variables with the same notation used to
refer to its functions, modname.itemname.

Modules can import other modules. It is customary but not required to place allimport statements at the beginning of a module (or script, for that
matter). The imported module names are placed in the importing module’s global
symbol table.

There is a variant of the import statement that imports names from a
module directly into the importing module’s symbol table. For example:

This does not introduce the module name from which the imports are taken in the
local symbol table (so in the example, fibo is not defined).

There is even a variant to import all names that a module defines:

>>> fromfiboimport*>>> fib(500)1 1 2 3 5 8 13 21 34 55 89 144 233 377

This imports all names except those beginning with an underscore (_).
In most cases Python programmers do not use this facility since it introduces
an unknown set of names into the interpreter, possibly hiding some things
you have already defined.

Note that in general the practice of importing * from a module or package is
frowned upon, since it often causes poorly readable code. However, it is okay to
use it to save typing in interactive sessions.

Note

For efficiency reasons, each module is only imported once per interpreter
session. Therefore, if you change your modules, you must restart the
interpreter – or, if it’s just one module you want to test interactively,
use imp.reload(), e.g. importimp;imp.reload(modulename).

the code in the module will be executed, just as if you imported it, but with
the __name__ set to "__main__". That means that by adding this code at
the end of your module:

if__name__=="__main__":importsysfib(int(sys.argv[1]))

you can make the file usable as a script as well as an importable module,
because the code that parses the command line only runs if the module is
executed as the “main” file:

$ python fibo.py 50
1 1 2 3 5 8 13 21 34

If the module is imported, the code is not run:

>>> importfibo>>>

This is often used either to provide a convenient user interface to a module, or
for testing purposes (running the module as a script executes a test suite).

6.1.2. The Module Search Path

When a module named spam is imported, the interpreter searches for a file
named spam.py in the current directory, and then in the list of
directories specified by the environment variable PYTHONPATH. This
has the same syntax as the shell variable PATH, that is, a list of
directory names. When PYTHONPATH is not set, or when the file is not
found there, the search continues in an installation-dependent default path; on
Unix, this is usually .:/usr/local/lib/python.

Actually, modules are searched in the list of directories given by the variablesys.path which is initialized from the directory containing the input script
(or the current directory), PYTHONPATH and the installation- dependent
default. This allows Python programs that know what they’re doing to modify or
replace the module search path. Note that because the directory containing the
script being run is on the search path, it is important that the script not have
the same name as a standard module, or Python will attempt to load the script as
a module when that module is imported. This will generally be an error. See
section Standard Modules for more information.

6.1.3. “Compiled” Python files

As an important speed-up of the start-up time for short programs that use a lot
of standard modules, if a file called spam.pyc exists in the directory
where spam.py is found, this is assumed to contain an
already-“byte-compiled” version of the module spam. The modification time
of the version of spam.py used to create spam.pyc is recorded inspam.pyc, and the .pyc file is ignored if these don’t match.

Normally, you don’t need to do anything to create the spam.pyc file.
Whenever spam.py is successfully compiled, an attempt is made to write
the compiled version to spam.pyc. It is not an error if this attempt
fails; if for any reason the file is not written completely, the resultingspam.pyc file will be recognized as invalid and thus ignored later. The
contents of the spam.pyc file are platform independent, so a Python
module directory can be shared by machines of different architectures.

Some tips for experts:

When the Python interpreter is invoked with the -O flag, optimized
code is generated and stored in .pyo files. The optimizer currently
doesn’t help much; it only removes assert statements. When-O is used, allbytecode is optimized; .pyc files are
ignored and .py files are compiled to optimized bytecode.

Passing two -O flags to the Python interpreter (-OO) will
cause the bytecode compiler to perform optimizations that could in some rare
cases result in malfunctioning programs. Currently only __doc__ strings are
removed from the bytecode, resulting in more compact .pyo files. Since
some programs may rely on having these available, you should only use this
option if you know what you’re doing.

A program doesn’t run any faster when it is read from a .pyc or.pyo file than when it is read from a .py file; the only thing
that’s faster about .pyc or .pyo files is the speed with which
they are loaded.

When a script is run by giving its name on the command line, the bytecode for
the script is never written to a .pyc or .pyo file. Thus, the
startup time of a script may be reduced by moving most of its code to a module
and having a small bootstrap script that imports that module. It is also
possible to name a .pyc or .pyo file directly on the command
line.

It is possible to have a file called spam.pyc (or spam.pyo
when -O is used) without a file spam.py for the same module.
This can be used to distribute a library of Python code in a form that is
moderately hard to reverse engineer.

The module compileall can create .pyc files (or .pyo
files when -O is used) for all modules in a directory.

6.2. Standard Modules

Some modules are built into the interpreter; these provide access to operations that
are not part of the core of the language but are nevertheless built in, either
for efficiency or to provide access to operating system primitives such as
system calls. The set of such modules is a configuration option which also
depends on the underlying platform For example, the winreg module is only
provided on Windows systems. One particular module deserves some attention:sys, which is built into every Python interpreter. The variablessys.ps1 and sys.ps2 define the strings used as primary and secondary
prompts:

These two variables are only defined if the interpreter is in interactive mode.

The variable sys.path is a list of strings that determines the interpreter’s
search path for modules. It is initialized to a default path taken from the
environment variable PYTHONPATH, or from a built-in default ifPYTHONPATH is not set. You can modify it using standard list
operations:

6.4. Packages

Packages are a way of structuring Python’s module namespace by using “dotted
module names”. For example, the module name A.B designates a submodule
named B in a package named A. Just like the use of modules saves the
authors of different modules from having to worry about each other’s global
variable names, the use of dotted module names saves the authors of multi-module
packages like NumPy or the Python Imaging Library from having to worry about
each other’s module names.

Suppose you want to design a collection of modules (a “package”) for the uniform
handling of sound files and sound data. There are many different sound file
formats (usually recognized by their extension, for example: .wav,.aiff, .au), so you may need to create and maintain a growing
collection of modules for the conversion between the various file formats.
There are also many different operations you might want to perform on sound data
(such as mixing, adding echo, applying an equalizer function, creating an
artificial stereo effect), so in addition you will be writing a never-ending
stream of modules to perform these operations. Here’s a possible structure for
your package (expressed in terms of a hierarchical filesystem):

When importing the package, Python searches through the directories onsys.path looking for the package subdirectory.

The __init__.py files are required to make Python treat the directories
as containing packages; this is done to prevent directories with a common name,
such as string, from unintentionally hiding valid modules that occur later
on the module search path. In the simplest case, __init__.py can just be
an empty file, but it can also execute initialization code for the package or
set the __all__ variable, described later.

Users of the package can import individual modules from the package, for
example:

importsound.effects.echo

This loads the submodule sound.effects.echo. It must be referenced with
its full name.

sound.effects.echo.echofilter(input,output,delay=0.7,atten=4)

An alternative way of importing the submodule is:

fromsound.effectsimportecho

This also loads the submodule echo, and makes it available without its
package prefix, so it can be used as follows:

echo.echofilter(input,output,delay=0.7,atten=4)

Yet another variation is to import the desired function or variable directly:

fromsound.effects.echoimportechofilter

Again, this loads the submodule echo, but this makes its functionechofilter() directly available:

echofilter(input,output,delay=0.7,atten=4)

Note that when using frompackageimportitem, the item can be either a
submodule (or subpackage) of the package, or some other name defined in the
package, like a function, class or variable. The import statement first
tests whether the item is defined in the package; if not, it assumes it is a
module and attempts to load it. If it fails to find it, an ImportError
exception is raised.

Contrarily, when using syntax like importitem.subitem.subsubitem, each item
except for the last must be a package; the last item can be a module or a
package but can’t be a class or function or variable defined in the previous
item.

6.4.1. Importing * From a Package

Now what happens when the user writes fromsound.effectsimport*? Ideally,
one would hope that this somehow goes out to the filesystem, finds which
submodules are present in the package, and imports them all. This could take a
long time and importing sub-modules might have unwanted side-effects that should
only happen when the sub-module is explicitly imported.

The only solution is for the package author to provide an explicit index of the
package. The import statement uses the following convention: if a package’s__init__.py code defines a list named __all__, it is taken to be the
list of module names that should be imported when frompackageimport* is
encountered. It is up to the package author to keep this list up-to-date when a
new version of the package is released. Package authors may also decide not to
support it, if they don’t see a use for importing * from their package. For
example, the file sounds/effects/__init__.py could contain the following
code:

__all__=["echo","surround","reverse"]

This would mean that fromsound.effectsimport* would import the three
named submodules of the sound package.

If __all__ is not defined, the statement fromsound.effectsimport*
does not import all submodules from the package sound.effects into the
current namespace; it only ensures that the package sound.effects has
been imported (possibly running any initialization code in __init__.py)
and then imports whatever names are defined in the package. This includes any
names defined (and submodules explicitly loaded) by __init__.py. It
also includes any submodules of the package that were explicitly loaded by
previous import statements. Consider this code:

In this example, the echo and surround modules are imported in the
current namespace because they are defined in the sound.effects package
when the from...import statement is executed. (This also works when__all__ is defined.)

Although certain modules are designed to export only names that follow certain
patterns when you use import*, it is still considered bad practise in
production code.

Remember, there is nothing wrong with using fromPackageimportspecific_submodule! In fact, this is the recommended notation unless the
importing module needs to use submodules with the same name from different
packages.

6.4.2. Intra-package References

When packages are structured into subpackages (as with the sound package
in the example), you can use absolute imports to refer to submodules of siblings
packages. For example, if the module sound.filters.vocoder needs to use
the echo module in the sound.effects package, it can use fromsound.effectsimportecho.

You can also write relative imports, with the frommoduleimportname form
of import statement. These imports use leading dots to indicate the current and
parent packages involved in the relative import. From the surround
module for example, you might use:

from.importechofrom..importformatsfrom..filtersimportequalizer

Note that relative imports are based on the name of the current module. Since
the name of the main module is always "__main__", modules intended for use
as the main module of a Python application must always use absolute imports.

6.4.3. Packages in Multiple Directories

Packages support one more special attribute, __path__. This is
initialized to be a list containing the name of the directory holding the
package’s __init__.py before the code in that file is executed. This
variable can be modified; doing so affects future searches for modules and
subpackages contained in the package.

While this feature is not often needed, it can be used to extend the set of
modules found in a package.

As functions are called, their names are placed on the stack, and as they return, their names are removed. The Traceback presents us with the list of called functions (from the first called to the most recent called [most recent call last]), telling us the file where the call occurred, the line in that file, and the name of the function the call was made from if any (otherwise ‘?’). On the next line slightly indented it tells us the name of the function called.

From the above Traceback we see that execution started in the file test.py and proceeded to line 25, where the function ‘triangle’ was called. Within the function triangle, execution proceeded until line 12, where the function ‘inc_total_height’ was called. Within ‘inc_total_height’ and error occurred on line 8.

Simple Debugging Strategies

*****use print statements: useful for showing what’s happening with the state of variables and will not stop execution flow.

******assert statements: useful for raising an exception if some condition is not met and does nothing if everything works and assert statement evaluates to true.

Example: assert(len(rj.edges()) == 16)

Should use assert statements liberally! And Not just for debugging!

****input statements: useful for prompting users for input and can be used to stop execution.

Step 3. Some Deeper Issues: When import name is executed the interpreter searches for a file named name.py in several locations such as the

“Current Working Directory” given by os.getcwd(); the “System path” given by variable sys.path; sys.path will include a list of directories specified by environment variable called PYTHONPATH. To avoid conflicts modules being run should not have the same name as a python standard library. Finally, by using project directories and tool called virtualenv we can often avoid dealing with system path problems.

Textbook and Resources

Course Goals

In this course students will learn intermediate programming skills using the python programming language and python-related tools. Topics include use of interpreters, the runtime execution model, python IDEs, standard utility modules, program design using numbers, iterables and functions, event-driven programming, interactive systems programming using a model, a view, and a controller, regular expressions, graphics programming using static and interactive drawing methods, data methods including use of scipy and related modules, which apply probability and distributions, generators and game solvers, and an introduction to networking and concurrent programming.

Installation of Python

Download the latest version of Python 3. This will be the official software platform for the course.

Installation of Text Editor

Geany is a simple text editor that lets you run almost all of your programs directly from the editor. It also displays your output in a terminal window, which helps you get comfortable using terminals. Other text editors are popular, for example try out Sublime text.

Getting Help

Piazza is a platform for Q and A that we will use for this class. Each student should sign up for an account. Instead of email, all
student questions should be directed to Piazza, either publicly (for all students in the class to see), or privately (for only instructors to see.) Students are able and encouraged to help answer the questions of their peers.

Another popular online resource for programming help is
Stack Overflow , which will often appear in the first page of results on Python-related google searches. Members post questions when they’re stuck, and other members try to give helpful responses. Many basic Python questions have very clear answers on Stack Overflow.

(Optional) Version Control

Students are encouraged but not required to run version control. Version control software allows you to take snapshots of a project whenever it’s in a working state. When you make changes to a project—for example, when you implement a new feature—you have the option of reverting back to a previous working state if the project’s current state
isn’t functioning well. Appendix D in the textbook provides a guide to the git version control system.

Grading Policy

There will be 2 exams and 4-6 programming projects. Group efforts for projects are encouraged.

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:http://pastebin.com/8rdmbLs8

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.

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