![]() |
![]() |
![]() |
![]() |
![]() |
Redefining the Properties of a Process Type
What You Will Learn
- To have a process type inherit properties from another process type
- To redefine transitions in a process type
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.
- Create the diagram above and save it on a new file (new_jackpotgame.spt for instance). Then close the diagram in the SDL Editor (Close Diagram from the File menu).
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.
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:
- 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.
- 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:
Simulating the JackpotGame
To understand the resulting system, you may want to spend a few minutes simulating it.
- 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.
- 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.)
- 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)
- Then, set the trace for the system to 1, meaning that only signals to/from the environment are traced. If required, turn all graphical traces off, in order to speed up the execution: -
set-gr-trace 0; stop-msc-log- Send the signal NewJackpotGame and run the simulator:
output-to NewJackpotGame Main; go- Click repeatedly the Probe button and watch the trace. You should win 10 points every now and then.
http://www.ibm.com/rational |
![]() |
![]() |
![]() |
![]() |