Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. #include "omnetpp.h"
  5.  
  6. class Workstation : public cSimpleModule
  7. {
  8. virtual int calculateRandomRecipient();
  9. protected:
  10. virtual void handleMessage(cMessage *wiad);
  11. };
  12.  
  13. Define_Module(Workstation);
  14.  
  15. void Workstation::handleMessage(cMessage *msgin)
  16. {
  17. int num_sticks = msgin->getKind(); // extract message kind (an int)
  18. // this hold the number of sticks on the table
  19.  
  20. delete msgin; // dispose of the message
  21.  
  22. // call virtual function
  23. // to calculate the number of sticks to take.
  24. int recipient = calculateRandomRecipient();
  25.  
  26. // send answer back to the Game module
  27. char msgname[32];
  28. sprintf(msgname," Recipient %d", recipient);
  29. cMessage *msgout = new cMessage(msgname); // create message
  30. msgout->setKind(recipient);
  31.  
  32. send(msgout, "out"); // send the message to Game
  33. }
  34.  
  35. int Workstation::calculateRandomRecipient()
  36. {
  37. int repicient = rand()%3;
  38. return repicient;
  39. // calculate move
  40.  
  41. // int move = (num_sticks + 4) % 5;
  42. // if (move == 0) move = 1;
  43. // return move;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement