#include "maisie.h" #define N 500 /* N is the number of rounds */ #define B 50 /* B is the message size, in bytes */ /* This is a ping-pong program. */ /* It sends a message back and forth "N" times between two entities. */ /* Adapted for Maisie v. 3.0 on 2-25-97 */ message other_player {ename name;}; message ball {char size[B];}; entity driver {} { ename Jack, Jill; char gameball[B]; Jack = new player {1} at 1; Jill = new player {0} at 2; /* Send opponent's name to each entity */ invoke Jack with other_player {Jill}; invoke Jill with other_player {Jack}; /* Start the ping-pong game */ invoke Jack with ball {gameball}; } entity player {int first_player} { int trips; char gameball[B]; ename opponent; /* Wait to receive opponent's name */ wait until mtype (other_player) opponent = msg.other_player.name; /* Wait for the message then send it back to the opponent */ for (trips=1; trips < N; ++trips) wait until mtype (ball) invoke opponent with ball {gameball}; /* Game over -- don't return the message */ if (first_player) { printf ("Game over after %d rounds and %d byte ball size!\n",N,B); wait until mtype(ball) terminate(); } }