This assignment invovles programming a virtual bot's game-playing strategy.
In the game, virtual bots from different students interact in a common world.
The goal of the game is to be the bot with the highest energy level at the
end of the game. Energy is acquired by consuming food items or stealing
energy from another bot.
Background and Prerequisites
This assignment is taken from Paul Kube's
"Snack Time" game assignment. It is used as the final assignment in
CSE 11, which is a first
course in the CSE major, but one intended for accelerated students
(students with prior programming experience). CSE 11 is a programming
course taught in Java, that is also supposed to introduce students to basic
data structures and algorithms (such as sorting). Therefore, learning
objectives for original version include Java class inheritance, and fast
What Students Need to Do
Like the CSE 11 version, the students' responsibility for the assignment
is to implement a "move()" function. The function takes as its only argument
the current state of the virutal world, in the form of an array of tuples,
each representing an object in the world. Objects in the world are either
food items or other players. Each tuple is three integers: (x,y,energy),
where x and y are the coordinates of the object's current location, and
energy is its energy level. The move() function returns an (x,y) tuple
representing the location of the next move for its bot.
The next move can be no further (in Euclidean distance) from the bot's
current location than a specified limit (a function of the bot's current
energy level). Otherwise the behavior of the bot is at the student
programmer's discretion. For more information on game rules and strategies,
see the CSE 11 assignment description.
Programming Environment Requirements
The game, as used in CSE 11, includes a robust and quite attractive GUI.
The server and client (including client GUI) are all written in Java.
We will retain the entire framework, including Java-based server and Java-
based client GUI and network interface. But instead of asking students to
also write their move() function in a Java class, our students will
implement the move() function in python.
Why? Java is needed on the client machine to run the client GUI.
Why? The jython system allows python code to be called from
Java, which is exactly what we need, to allow the Java client to call the
students' move() function.
How? Students write their move function inside a python class "Action," as shown in the attached code. Then they run the jythonc compiler which rewrites their python source code into Java source code, which is then compiled to a Java bytecode (*.class) file, using a regular Java compiler. This results in a Java class called Action, with a public static move() function, just as the existing CSE 11 framework expects.
Where can I get jython? Jython is available here. After downloading the file provided,
run "java -cp . jython_21" to install (or "jview /cp:. jython_21" on Windows). After that, you can type "jython" to get a python interpreter prompt, or, as we will do in this assignment, type "jythonc myfile.py" to compile python source code files to Java.
Client Software: Download the SnackTime Java client here. To run it, type "java -jar SnackTime.jar". A login
window will appear, where students should enter an assigned login and
password. (A list of approved logins and passwords is kept at the server.)
The code here is an example of what the students
would generate and turn in. The example just demonstrates how to
properly format the python source code so that the jythonc can make a Java
class called Action.