Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include "omnetpp.h"
- class Workstation : public cSimpleModule
- {
- virtual int calculateRandomRecipient();
- protected:
- virtual void handleMessage(cMessage *wiad);
- };
- Define_Module(Workstation);
- void Workstation::handleMessage(cMessage *msgin)
- {
- int num_sticks = msgin->getKind(); // extract message kind (an int)
- // this hold the number of sticks on the table
- delete msgin; // dispose of the message
- // call virtual function
- // to calculate the number of sticks to take.
- int recipient = calculateRandomRecipient();
- // send answer back to the Game module
- char msgname[32];
- sprintf(msgname," Recipient %d", recipient);
- cMessage *msgout = new cMessage(msgname); // create message
- msgout->setKind(recipient);
- send(msgout, "out"); // send the message to Game
- }
- int Workstation::calculateRandomRecipient()
- {
- int repicient = rand()%3;
- return repicient;
- // calculate move
- // int move = (num_sticks + 4) % 5;
- // if (move == 0) move = 1;
- // return move;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement