IBM
Contents Index Previous Next



Redefining the Properties of a Process Type


What You Will Learn

The Process Type JackpotGame

So far, you have redesigned the original functionality of the system -DemonGame, using a slightly different design. Next step will be to add a feature that allows you to win the "jackpot", with a probability of 10%. The jackpot is arbitrarily set to increase the score by 10. A simple implementation of this could be to create a pseudo random number generator that returns a sequence of numbers from 0 to 9, and to check the random number upon the reception of the signal Probe.

It should also be possible to specify what kind of game to start at run-time, meaning that we need an additional input signal from the environment, NewJackpotGame, that will start the JackpotGame; that new signal requires additions to the process Main and the system diagram.

The JackpotGame is implemented as a process type that inherits the properties of the process type Game, and adds the random number feature by redefining the transitions that handle the signal Bump. The pseudo random generator is activated upon each reception of the signal Bump. See below.

Figure 156 : The process type JackpotGame

Changes to the Block GameBlock

To make the process type JackpotGame available from the parent block, you simply add a process reference symbol and a process instantiation symbol, as you did before with the process type Game. You also add a signal NewJackpotGame to the signal list to the process Main.

Figure 157 : The block GameBlock

Changes to Process Main and System DemonGame

The process Main and the system DemonGame need to be extended with the declaration of the signal NewJackpotGame and the code to receive the signal and create an instance of the game JackpotGame:

Figure 158 : The extensions to process Main and system DemonGame

  1. Update the diagrams Main and DemonGame according to the figure above and save them on file. You may want to save the diagrams on new files, e.g. new_demongame.ssy and new_main.spr.
    • This version of the Main diagram is also available as the file main2.spr, if you wish use it instead of editing the diagram. In the Organizer, connect the diagram to the new file (from the Edit menu).
    • The DemonGame diagram has to be edited manually - do not re-connect it to an existing file.
  2. In the Organizer, make sure that the process type diagram JackpotGame is connected to the file new_jackpotgame.spt that you created earlier. (If not, use Connect in the Edit menu and the option To an existing file.)

The resulting Organizer list should now look like this:

Figure 159 : JackpotGame added to Organizer list

Simulating the JackpotGame

To understand the resulting system, you may want to spend a few minutes simulating it.

  1. First analyze the system and generate a simulator, as you learned from the tutorial on the simulator. Then open the generated simulator in the Simulator UI.
  2. We suggest that you check the following features:
    • It should be possible to start one instance of Game or of -JackpotGame at run-time using the NewGame/NewJackpotGame signals, but not to have two games running at the same time. (Use the command output-via to send the signals NewJackpotGame, Newgame and EndGame via C1, in order to start and stop the game).
    • Even if we do not have any game started, the signal Bump no longer causes any dynamic error, since there is always a receiver (Main).
    • Turn the graphical MSC trace on, to visualize how the signalling is done. Also turn the graphical SDL trace on. Verify that the execution takes place in the graphs for both the process types Game and JackpotGame, even if you have started a JackpotGame! (You may have to execute at symbol level to catch this.)
  3. Play the game in a realistic way.
    • First, create a button in the Simulator UI with the name Probe, that sends the signals Probe and then Result, then resumes the execution with the command Go. Each time you click this button, the Score is returned. (The button definition should contain output-to Probe Main; output-to Result Main; go)

Figure 160 : Defining the button Probe

  1. Stop the execution with the Break button.

http://www.ibm.com/rational
Contents Index Previous Next