Summary |
The common game of "rock-paper-scissors" is used as a basis for
creating a networked client-server game in a Unix systems programming
course.
|
Topics |
Client-server interactions, Unix servers and sockets, basic
algorithmic design.
|
Audience |
Sophomore level
systems-programming course, but could be easily adapted for a
CS1/CS2 environment. |
Difficulty |
Two weeks (with textbook
supplying examples of networking code). |
Strengths |
Provides a fun application
while working on client/server interactions. Can be customized
with different choices of gestures, to avoid problems of
plagiarism. Can be scaled down to a CS1 or CS2 context. Can be
offered in an open-ended context (e.g. determining the
protocol to be used). |
Weaknesses |
The game itself is relatively
simple; one might call it "simplistic". Networking code can be
notoriously difficult to debug, depending on the environment in use.
|
Dependencies |
Basic CS1 understanding of
algorithmic development, strings, game state, and so on;
networking knowledge (in whatever form). |
Variants |
Can be adopted to fewer (or
more) gestures, or fewer (or more) throws per game. Problem can
be simplified by supplying a functioning client (or server) and
requiring students to write the other. |
In the childhood game of "rock-paper-scissors" (also known by a variety of other names), two participants select one of three different gestures (or "throws"). The selected gestures are then compared using the following rule set:
Of course, with only three gestures to choose from, the possibility of a tie on any given throw is fairly high, and the possibility of repeated ties (while diminishing) is certainly non-trivial. When competing against an opponent whose tendencies may be known, the possibilities of ties may be even higher. In response, Sam Kass (with help from Karen Bryla) developed an extension of this game by adding two new gestures: "lizard" and "Spock". The full rule set may be expressed as follows:
Note that this rule set is a conservative extension of the classic rule set. The rule set still permits a fair game: every gesture defeats two other gestures and loses to two other gestures. And while the possibility of ties still exists, the probability of ties (and, in particular, repeated ties) is lower.
One can purchase T-shirts (from CafePress or ThinkGeek) with graphical depictions of the above rules. The game was also featured in an episode of CBS's The Big Bang Theory.
In Winter 2010, I used this assignment in a course in systems programming at Kettering University. The course is taken mostly by sophomores and juniors who have already taken two courses in object-oriented programming (using Java). The course begins with a "crash course" in C programming, and then spends most of the term learning to write programs that interact with the Unix operating system.
One of the last units of the course introduces students to TCP/IP networking and Unix streams. I was interested in providing a final assignment for the students to complete that would involve writing a genuinely networked application. Most of the assignments during the semester had been rather un-nifty (e.g. writing subsets of common Unix utilities); I was hoping to give an assignment that would be more interesting --- or at least more entertaining.
The assignment I gave to the students required students to implement a client-server application for playing Rock-Paper-Scissors-Lizard-Spock. Students were required to write a stand-along server application along with a companion client application. The server accepted requests from clients, pairing them up into two-player games, referee each game, and announce a winner. The server permitted multiple concurrent games. Students were given complete freedom in defining the network protocol used in exchanging information between server and clients, as well as the interface used by the clients to interact with the users.
The course textbook (Molay, Understanding Unix/Linux Programming contained extensive code examples for writing networked TCP/IP applications, which students were free to use in their assignments. This simplified matters greatly; many students simply constructed a library from the code provided by the textbook and accessed the library from their own code.
All students managed to complete the assignment. Many students went above and beyond the required scope of the assignment. One student used the Unix curses library to create an attractive ASCII-oriented client application. Others used innovative ideas for structuring both the client and server for future scalability.
Two student solutions are included for your perusal (with the full permission of the authors):