Homework 2
Distributed Simulation Game: Annihilation
Due: Monday, October 10

Game Description

You are to implement a distributed simulation game using the FDK (Federated Simulations Development Kit) software package. There are two players in the game, the red team and the blue team that share a playing area that is organized as a grid, as illustrated in Figure 1. Each team consists of 16 mobile units (MUs).

At each time step of the game, each MU randomly moves in one direction (N/NE/E/SE/S/SW/W/NW) to an adjacent grid cell, or remains in the same cell. An MU cannot move beyond the edge of the playing area. For example, a MU in the northernmost row cannot move north. Each MU is equally likely to choose among its options for moving or remaining in the same cell. FDK includes a random number generator that you can use to implement this function. Multiple MUs can reside in the same grid cell at the same time.

The red team's base is at the grid cell with coordinates (0,0), and blue team's base is located at (7,7). At the start of the game, all MUs should start from their team's home base.

When red and blue MUs meet in the same grid cell, each red MU annihilates exactly one blue MU. For example, if three Red MUs and one Blue MU meet in the same cell, one Red and one Blue MU are destroyed and removed from the game, leaving two Red MUs in the cell. The remaining MUs then advance to the next time step, and resume their movement operations. The game ends when the simulation executes 40 time steps.

 

 

0

1

2

3

4

5

6

7

0

Red base

 

 

 

 

 

 

 

1

 

 

RR

 

 

B

 

 

2

 

R

 

B

 

 

BB

 

3

 

 

RB

B

 

B

 

 

4

RB

 

 

 

 

 

 

 

5

 

 

 

 

B

 

 

 

6

 

R

 

 

 

 

 

 

7

 

 

 

B

 

 

 

Blue base

 

Figure 1: 8X8 play area.

 

 

Implementation Guidelines

You should implement a distributed simulation containing two federates, one to simulate the red team, and one to simulate the blue team. Each time step the red (blue) federate should (1) compute the new position of each red (blue) MU, (2) send messages indicating the new position of the red (blue) MUs, (3) receive messages indicating the position of the blue (red) MUs, (4) print out the position of all MUs (after they move, but before annihilation takes place) (5) annihilate MUs that are in the same grid cell, and (6) print a list of MUs that are annihilated.

Use the object management services (e.g., Update/Reflect Attribute Values) and the time management services (Time Advance Request and Time Advance Grant) of the FDK to generate updated MU positions and to advance the simulation time, respectively. It is recommended you use BRTI for this assignment since it is simpler to use than DRTI, and program each federate in C.

You should define two object classes to exchange position information: RedMU is an object class that includes attributes indicating the position of a single Red MU. Similarly, BlueMU is an object class with attributes indicating the position of a single Blue MU. The red (blue) federate should create an instance of a RedMU (BlueMU) object for each MU it owns, and update the position of RedMU (BlueMU) object instances each time step. The red (blue) federate subscribes to the blue (red) object class in order to receive position updates for Blue (Red) MUs.

Deliverables

You must submit both source code and an executable for the program. Use the tar command to make an archive of your files. You should also include a README file describing how to compile and run your program. Please name the tar file hw2_lastname.tar, for example, hw2_singh.tar and send it as an attachment to the TA.

FDK Installation

Below, % denotes the Unix prompt (i.e., type the command following the %). Use Linux machines for the assignment.

Download the FDK software to your working directory.

Decompress the file:

      % gunzip fdk-3.0b5.tar.gz
      % tar xvf fdk-3.0b5.tar

Before compilation, include the following directories at the begining of your path
      /usr/local/gnu/gcc-2.96/bin
      /usr/local/gnu/gcc-2.96/lib
      /usr/local/gnu/gcc-2.96/include

If you are using bash use
      export PATH=/usr/local/gnu/gcc-2.96/bin:/usr/local/gnu/gcc-2.96/lib:/usr/local/gnu/gcc-2.96/include:$PATH
If you are using csh use
      setenv PATH /usr/local/gnu/gcc-2.96/bin:/usr/local/gnu/gcc-2.96/lib:/usr/local/gnu/gcc-2.96/include:$PATH

If they are not at the begining of your path then you'll pick up the newer gcc and fdk won't compile properly. Older compilers are installed on the SYSTEMS machines.

Read the documents in the fdk-3.0b5/DOC directory. Try out the examples before you start writing your own application.

How to run a sample (tm_ping)

Replace the runon file at ./RTIS/BRTI/APP/PING by this runon.

Since the CoC machines don't support rsh now, you need to setup your Unix account to accept ssh without passwords. To do this, check the CNS webpage here.

Go to the sample program directory:

      % cd ./RTIS/BRTI/APP/PING

You can now run the tm_ping application program by typing:

      % ./runon abc abc

NOTE: Please don't use baobab for your testing. Use SYSTEMS machines instead. Also, don't run your programs for long (i.e. more than 15 minutes.)

Here is a list of machines you can use:
abc artemis barra belgian benbecula bernera canna cbs coll cromarty delos demeter dove drummond eigg eriskay etna ghostface hawaii-lnx hera
hispaniola ios isleroyale kahoolawe-lnx kauai-lnx lanai-lnx manitou margarita maui-lnx method molokai-lnx mwali-lnx nbc newguinea niihau-lnx
oahu-lnx odb paros poseidon raekwon thunderbay traverseisle virgin xwing1 xwing2 xwing3 xwing4

This will create two tm_ping processes that run on the two processors. Output is sent to stdout. Also, the output produced by each federate is dumped to a file created on /tmp (the file name includes your login name).

How to start the assignment

To get you started, we have provided you a variation on tm_ping that sets up publications and subscriptions, invokes the time management services for a time stepped execution, and sends and receives update messages. This program is in sampleProg.c and uses a modified fedfile which you need to place in the same directory. You will need to modify the makefile.aimk and runon files in the PING directory to replace tm_ping with sampleProg to compile and run this program. After making these modifications, just type make in the same directory to compile, and the same runon command as before to execute the distributed simulation.

The sample program is commented to describe what the program is doing, and how it interfaces to FDK. See the FDK User's Manual located in the DOC directory of the installation for more detailed information concerning FDK and the calls and declarations made in the sample program.