Stanford University Computer Science 244b: Spring 2013 Assignment 1 - Mazewar: A Multiplayer Computer Game |
Introduction | Game Description | Doing the Assignment | Submitting the Assignment | Programming Framework
You are to design and implement cs244b Mazewar, a distributed, multiplayer game that is described below. So that you do not have to deal with user interface and other framework issues, you have been provided with a single-player Mazewar game.
cs244b Mazewar is a distributed, multiplayer game that allows each player to control a rat in a maze. A player receives points for tagging other rats with a projectile and loses points for being tagged.
The game is based on the X Window System version of Mazewar, which is in turn based on the classic game of Mazewar that ran on the Xerox Alto in the 1970s. It is also based on Amaze, a multi-player game with a distributed implementation on top of the V kernel. Amaze is described in [E.Berglund and D.R.Cheriton. Amaze: a multiplayer computer game. IEEE Software. 2(3):30-39, May 1985].
| Input of Rat | Gesture or Action |
| A | About face (180 deg turn) |
| S | Left turn (270 deg turn) |
| D | Forward |
| F | Right turn (90 deg turn) |
| Space | Back one space |
| Mouse Left | Peek left |
| Mouse Right | Peek right |
| Mouse Middle | Throw projectile |
These commands are already implemented in the framework.
Students should try to form teams consisting of at least two people but not more than three people (Team Registration). You will then be provided with a unique UDP port number. If you're having trouble forming a group, post a note to the Piazzza discussion forum.
The teams are for the purpose of designing and specifying a protocol for the game, not for jointly writing code. You may not share code; you may not use code from the X version of Mazewar, nor may you use code from the V kernel version of Amaze. The members of a team should not work together to answer the questions in part three; we are interested in your individual answers.
You are each required to write a complete implementation of cs244b Mazewar and demonstrate that your program interacts correctly with those of the other members of your team.
We suggest that you stick to the rules provided in the Mazewar game description, but you are free to make any additions that you think improve the game, as long as
What to Submit:
Your team is to jointly design the specification of the protocol used by the game. The specification must be complete enough so that all members of the team can independently implement a mazewar program to the specification and have it interoperate with each of the other programs. Programs running on different architectures (e.g. Sun Ultra or HP PA-RISC) need to be able to correctly interact with each other.
The protocol design should specify a distributed game. A single centralized server that treats the nodes as terminals is not acceptable. Using a distinguished node tends to create a centralized single point of failure, so this approach should be avoided if possible, or at least handled (and justified) carefully. You are also not allowed to use broadcast to disseminate state. Sample code for joining a multicast group is provided in the netInit() function.
The description of your specification should have the information that you would expect to find in an RFC for Mazewar. One example you can work off of is the Gnutella Specification, it should give you some idea of what we are looking for. Be concrete and specific in the protocol. The protocol should describe how it meets the requirements and provides sufficient consistency, but don't convolute the specification with justifications; that is the focus of the third part of the assignment.
The protocol specification should include:
The team design and specification of the communication protocol will be graded for the group as a whole (i.e., a single grade will be given to all members of the group), based on the following criteria:
A team may revise its specification between the time it is submitted and the final due date as long as the revisions are documented and justified. If you revise your specification, resubmit one copy of it for your team at the time that individuals submit parts two and three of the assignment. Along with the updated specification include a ChangeLog file describing the changes and the reason for the changes. In addition, each individual submission of part two/three should state that the specification has been revised.
Implement Mazewar using the framework provided, conforming to the game description. The protocol used to communicate between the nodes in the game and the behavior of the nodes must obey the specification created by your team in part one.
The implementation will be graded on a demo of the running program as well as the submitted source code. Each group will sign up for a demo in the myth computing cluster during the week of the final due date (signups to be announced later). At demo time, each member of your group should be prepared to run his/her program with those of the rest of the group, and also be prepared to rebuild the program from source code if so requested.
We don't expect you to have to make many changes outside of toplevel.cpp and mazewar.h. However, there are a couple of implementation choices that you might consider that do require such changes:
Your implementation must also support setting the rat name, x pos, y pos, and direction (one of {n, s, e, w}) via the command line, in that order, separated by spaces. One-word names are sufficient. If none of these 4 values is provided, you program should start as usual, and ask for a user name and generate a random rat position and orientation. You do not need to do input validation and a single-word name is acceptable.
Answer each of the following questions in the answers.pdf file sent with your code.
Submit your group information using this form: Team Registration
Name your protocol design document as follows:
"<team-name>_<sunet-id-1>_<sunet-id-2>_pdd.pdf"
(e.g. ratpack_aljunied_liuj11_pdd.pdf).
Email your protocol design document to: "cs244b-ta at cs".
Please repeat your group information (group name, members, and email addresses) in the email.
The game framework is in /afs/ir.stanford.edu/class/cs244b/mazewar. Copy and unzip MazewarSpring2013.tar.gz to your directory. You can make mazewar and run it (the executable is mazewar). The provided code is for a single player - it executes entirely locally, and the throwing of projectiles is not implemented. You can play with a robotic rat by running mazewar -robot (use -time_interval << msec >> to control the speed of the robot).
We assume that all students are familiar with C and Unix and have some programming experience. We expect that you have the ability to write code that sends and receives packets over the network.
The programming assignment will be tested on myth machines, so please make sure they work there.
Some routines that are provided to you are described briefly below. Also, sample code for opening a multicast socket and joining a group is provided in the function netInit() in toplevel.cpp.
NewPosition(MazewarInstance::Ptr m) sets x, y, and dir to a random point in the maze, guaranteed to not be inside a wall, and not facing a wall. You will need to modify this in order to guarantee that a randomly placed rat is not placed on top of another rat. (toplevel.cpp)
MazeInit(int argc, char **argv) is called to initialize the maze, the window system etc. Pass in argc and argv as passed to the toplevel program. (init.cpp)
The following routines are used to control the display manager. They are not meant to control the state of the game.
SetRatPosition(RatId ratId, Loc xpos, Loc ypos, Direction dir) informs the display manager that the position of rat # ratId is (xpos,ypos), facing in direction dir. (display.cpp)
ClearRatPosition(RatId ratId) informs the display manager that rat # ratId is no longer to be displayed. (display.cpp)
ShowView(Loc x, Loc y, Direction dir) shows the perspective view from position (x,y) in direction dir. Other rats are displayed as set by previous calls to SetRatPosition(). (display.cpp)
ShowPosition(Loc xloc, Loc yloc, Direction tdir) shows the local rat's position as an arrow in the top-down view. (display.cpp)
DrawString(const char* msg, uint32_t length, uint32_t x, uint32_t y) draws a string on the specified location of the screen. You should call this function and display message at the center of the perspective screen when your rat tags other rats or is tagged by others. (winsys.cpp)
The following routines are used to interact with the user. They all take an argument, prompt, which is a string used to prompt a user, and they all return their values in the locations pointed to by the other arguments, and all of the returned values are allocated out of the heap by malloc. You can manage the memory accordingly.
getName(char *prompt, char **ratName) returns a user name, if none is given the username (login ID) is determined from the environment. When getName ("Enter foo", &r) returns, r points at the name of the rat. (init.cpp)
getString(char *prompt, char **string) prompts for an arbitrary string. CR alone returns NULL. The string is returned in string. (init.cpp)
NextEvent(MWEvent *event, int socket) returns the next X event, or an arrival of a network packet on socket. If your implementation requires you to listen on more than one socket at a time, you must modify the function NextEvent. (winsys.cpp)