CSc 59866: Applied Cryptography & Information Security

Lab 2: Rock-Paper-Scissors MIDLet (User vs. User)

Instructor: Nelly Fazio

Back to class webpage


[ Introduction | Design Guidelines | Collaboration Policy | Hand-in Procedure]


Introduction

In this lab, you will build a simple MIDLet application which will allow two users to play the Rock-Paper-Scissors game against each other using two (emulated) SunSPOTs. This lab builds on the MIDLet application written for Lab 1, where the user plays the same game against an (emulated) SunSPOT device. By doing the lab, you will gain familiarity with some additional components of the SunSPOT devices (e.g., the radio antenna) and learn how to deploy an application which pairs two SPOTs.

Design Guidelines

As already discussed in Lab 1, each SPOT is equipped with eight tricolor LEDs, L0, L1, L2, L3, L4, L5, L6 and L7:
LEDs
and two switches, SW1 (to the left) and SW2 (to the right).
Virtual SPOT

The UnicastCount MIDlet that is bundled in the EmulatorDemo shows how two SPOTs can be paired using the radio antenna and their SPOTs addresses. Once the connection has been established, the two switches are programmed to light up the LEDs in a binary pattern and/or change their color.

In this lab, you will work with two SPOTs: SPOT1 and SPOT2. On each of these devices, you will program the right switch SW2 to cycle through the three possible selections (Rock, Paper, or Scissors) of the device itself, and the left switch SW1 to confirm the selection and reveal the other SPOT's move. More specifically, on device SPOT1, the three rightmost LEDs (L5, L6 and L7) shall display the SPOT1's selection, while the three leftmost LEDs (L0, L1 and L2) shall display the SPOT2's selection. The two central LEDs (L3 and L4) will be used to display the winner. Similarly, on device SPOT2, the three rightmost LEDs (L5, L6 and L7) shall display SPOT2's selection, while the three leftmost LEDs (L0, L1 and L2) shall display SPOT1's selection. Again, the two central LEDs (L3 and L4) will be used to display the winner.

On each device, we will use different colors to display the SPOT's own selection and the other SPOT's choice. More precisely, on SPOT1, we use green for SPOT1's selection and red for SPOT2's selection. Similarly, on SPOT2, we use green for SPOT2's selection and red for SPOT1's selection.

The two central LEDs shall be solid blue while the SPOTs make their selections, and turn to flushing green, red, or blue depending on whether SPOT1 won, lost, or tied the game. The initial LEDs configuration is as in Lab 1 and is depicted below:

Initial LEDs configuration

Let's now discuss in more details the functionalities of the two switches. We will take the point of view of SPOT1, but the discussion is analogous on SPOT2.

SPOT1 uses switch SW2 to make its choice: one click for Rock, two clicks for Paper, and three clicks for Scissors. Further clicks shall cycle back through Rock, Paper, etc. When SPOT1 confirms its selection by pressing the SW1 switch, it sends its selection to SPOT2. At this point we need to distinguish two cases, depending on whether SPOT2 has already made its selection or not:

When the two SPOTs have both made their selections, the Rock-Paper-Scissors rules are applied to declare the winner. Here is a pictorial representation of the rules of the game:

rock_paper_scissors rules
(From Wikipedia's rock-paper-scissor entry.)

The two middle switches (L3 and L4) of the two SPOTs will then blink for five times. On each device, we use the color green if this device won; we use the color red if the other device won, and we use color blue if there is no winner (SPOT1 and SPOT2 made the same selection). After blinking five times, the LEDs on the two SPOTs return to their initial configuration, ready for a new game.

Collaboration Policy

You must write all the code you hand in for the programming assignments, except for code that is part of the EmulatorDemo. You are not allowed to look at anyone else's solution. You may discuss the assignments with other students, but you may not look at or copy each others' code.

Hand-In Procedure

To turn in your lab, e-mail your Rock-Paper-Scissors MIDLet application as a .zip file (your.name-lab2.zip) at "fazio AT cs DOT ccny DOT cuny DOT edu" by 11:59pm, October 26, 2009.


Copyright © Nelly Fazio