MACRo 2015- 5th International Conference on Recent Achievements in Mechatronics, Automation, Computer Science and Robotics Random Process Simulation Using Petri Nets László SZILÁGYI 1, 2, 3 1 Department of Control Engineering and Information Technology Budapest University of Technology and Economics, Hungary, e-mail: [email protected] 2 Department of Electrical Engineering, Faculty of Technical and Human Sciences, Sapientia University, Tg. Mureş, e-mail: [email protected] 3 Hand in Scan Ltd., Budapest, Hungary, e-mail: [email protected] Manuscript received January 12, 2015, revised February 9, 2015. Abstract: This paper introduces a Petri net designed for the simulation of the ancient game called Rock-Paper-Scissors or Roshambo. The network enables us to simulate the behavior of machine players and allows us to design and evaluate strategies against weighted random machine opponents. The paper also presents a theoretical calculus on winning chances. Simulations carried out using the software package Pipe (version 4.3.0) fully confirm the theoretical considerations. Keywords: Petri nets, Roshambo, random processes, strategy. 1. Introduction The notion of Petri network was introduced over half a century ago, but its theory and its application spectra are still evolving quickly [1]. Although it was primarily designed to model automata, nowadays its applications cover the modeling of communication protocols [2], manufacturing systems [3], road traffic [4], cyber-intrusion [5], farm processes [6], and games [7, 8, 9], and controlling of discrete event systems [10], track-driven traffic [11], robot movements [12]. Recently, Petri nets are also used as bricks at building machine learning systems [13]. In this paper we employ a discrete hybrid Petri net, containing both immediate firing and timed transitions, to implement a simulation framework of the roshambo or Rock-Papers-Scissors (RPS) game. This game has an ancient Asian origin [14], and currently is very popular worldwide. It is frequently used as a decider, for example, who should execute a free kick on the soccer field? The two players count up to three or recite the names of the game Rock-PaperScissors, and at the third they suddenly bring their hidden hands in front, showing one of the three allowed gestures that correspond to rock, paper and 177 10.1515/macro-2015-0017 Unauthenticated Download Date | 7/29/17 12:04 AM 178 L. Szilágyi scissors. If the two gestures are the same, then the game is a draw. Otherwise there is a winner: rock destroys the sharpness of the scissors, scissors cut the paper, while paper covers the rock. Our main goal is to study the basic strategies that can be simply implemented into random generator driven machine players. Figure 1: Petri network model of the RPS game 2. Methods The basic RPS model is presented in Fig. 1. It is a Petri net consisted of 13 places, and 17 transitions. Ten transitions are immediately firing transitions, while seven are timed ones. In the initial state there is only one token in place P0, indicating that there is no game in progress. When the transition T ST fires, the game begins and places PST1 and PST2 get a token each, meaning that both players can come up with their bet. The token in PST1 enables three timed transitions, TR1, TP1, TS1, corresponding to the three choices: rock, paper, and scissors, respectively. When one of these three transitions fires, the corresponding place out of PR1, PP1, and PS1 will receive one token, showing the choice of the first player. Simultaneously PDN1 also receives a token, showing that the first player is done with their choice. The same process happens in Unauthenticated Download Date | 7/29/17 12:04 AM Random process simulation using Petri nets 179 parallel on the right side, modeling the choice of the second player. When both players are done with their choice, the result of the game is evaluated. This is performed by nine immediately firing transitions, out of which one and only one is enabled. One of the transitions TRR, TPP, and TSS will fire in case of a draw, when both players had the same choice. In any such case, two tokens disappear and no place receives any token. Transitions denoted by TRS, TPR, and TSP fire in the cases when the first player is the winner, and thus the place PW1 receives a token, indicating that player one got one point. On the other hand, transitions denoted by TSR, TRP, and TPS fire in the cases when the second player is the winner, and thus the place PW2 receives a token, indicating that player two got one point. At this moment, the next transition to fire is surely T FI, action corresponding to the final of the game. The network regains its initial state, with the possible difference of an extra token in either PW1 or PW2. In each cycle, exactly five firings take place, and the number of tokens in PW1 and PW2 indicate the current score in any moment. If we execute a random firing sequence of length 5n, it is equivalent with a sequence of n games. The first emerging tricky question is: who will win more games? The fastest and mistaken answer is that a draw is very likely. The truth is, it depends on the firing rates of the random choice transitions T R1, TP1, TS1, TR2, TP2, and TS2, denoted by rR1, rP1, rS1, rR2, rP2, and rS2, respectively. If we denote by pRk, pPk, and pSk the probabilities of Rock, Paper, and Scissors at player k (k is 1 or 2), then we will have: p Rk rRk / k p Pk rPk / k p r / Sk k Sk (1) where k rRk rPk rSk . This way, the probability of winning for the first player is: p w1 p R1 p S 2 p P1 p R 2 p S1 p P 2 (2) while the second player wins with the probability: p w2 p R 2 p S1 p P 2 p R1 p S 2 p P1 . (3) There is also a probability of a draw, defined as: pdraw pR1 pR 2 pP1 pP 2 pS1 pS 2 . (4) Having this accepted, it is likely to expect a score that is proportional with pw1 vs. pw2. The score is expected equal for example when all transfer rates are equal. On the other hand, when rR1=3, rS2=2, and rP1=rS1=rR2=rP2=1, then pw1=0.4 and pw2=0.3, hence the score is expected to be proportional to 4:3. Unauthenticated Download Date | 7/29/17 12:04 AM 180 L. Szilágyi Now let us suppose that both players are fully random machines, making random choices with all possible outcomes having equal probability. In this case all three transition rates are equal for both players. For the sake of simplicity, without loss of generalization, let us suppose rR1=rP1=rS1=1 and rR2=rP2=rS2=1. In this case, there are equal chances for the outcome of any game: pw1=pw2=pdraw=1/3. But let us further suppose that the first player wants to win the game by attacking, and the second player wants to win by defense. In this order, the first player intensifies the frequency of rock for example, throwing more rocks towards the second player via setting rR1=1+x, where we suppose x is a positive number. The second player on their turn identifies the situation and comes up with more papers to cover the rocks of the opponent (rP2=1+y, with y>0) and with less scissors to avoid unnecessary losses (rS2=1+z, with z<0). This way we get: σ1=3+x, σ2=3+y+z, and so pR1 pP1 p S1 1 x pR 2 3 x 1 pP 2 3 x pS 2 1 3 x 1 3 y z 1 y , 3 y z 1 z 3 y z (5) leading to 3 x y z xz p w1 (3 x)(3 y z ) 3 x y z xy p w2 . p (3 x)(3 y z ) draw 3 x y z (3 x)(3 y z ) (6) From the above formula it can be obviously deduced that the second player is winning more frequently if xz<xy. If really x and y are positive, and z negative, the inequality will always hold, meaning that attacking on one arbitrarily selected choice is never a good strategy. The best score achieved by the first player will be when x=0. On the other hand, if x is chosen negative, the second player can easily compensate by setting a positive z, and a negative y. These strategies will be numerically evaluated in the next section. The implementation and simulations were carried out using the Pipe software package [15], version 4.3.0. Unauthenticated Download Date | 7/29/17 12:04 AM Random process simulation using Petri nets 181 3. Results and Discussion The RPS game model was initialized with various parameter sets (x,y,z). For each setting, a sequence of five thousand firings was performed, equaling one thousand games. The expected scores were computed using Eq. (6), while the simulated score was given by the Petri network. Results are summarized in Table 1. The second test (second data row of the table) reveals that the best way of avoiding the loss of the game series is to keep on generating real random choices. But if we are able to detect the strategy of the opponent, we are able to compensate and win games more frequently. See details in the bottom nine rows of Table 1. Table 1: Tested cases. x 0 1 1 1 1 1 1 1 -0.5 -0.5 -0.5 Rate shifts y z 0 0 0 0 0.5 0 1 0 2 0 0 -0.5 1 -0.5 2 -0.5 -0.5 0 -0.5 1 -0.5 2 pdraw 1/3 1/3 9/28 5/16 3/10 7/20 9/28 11/36 8/25 12/35 16/45 Probabilities pw1 1/3 1/3 9/28 5/16 3/10 6/20 8/28 10/36 8/25 10/35 12/45 pw2 1/3 1/3 10/28 6/16 4/10 7/20 11/28 15/36 9/25 13/35 17/45 Theoretical score 333:333 333:333 321:357 313:375 300:400 300:350 286:393 278:417 320:360 286:371 267:378 Simulated score 313:356 310:387 277:403 297:360 272:405 277:415 320:363 287:381 250:388 If the attack comes on another track, namely the first player attacks with more frequent scissors or papers, the applicable defense strategy equally exists, due to the symmetry of the game. 4. Conclusion Petri networks are indeed excellent tools in modeling random processes. Using the built model, we were able to confirm the validity of analytically computed strategies. By employing the developed strategies, we were able to beat a weighted random machine player. Further work could be invested in implementing the strategy into the Petri net, making it able to identify the parameters of the random machine opponent. Unauthenticated Download Date | 7/29/17 12:04 AM 182 L. Szilágyi Acknowledgements This work was funded by Hungarian National Research Funds (OTKA), under grant number PD 103921. References [1] Silva, M., “Half a century after Carl Adam Petri’s Ph.D. thesis: A perspective on the field”, Ann. Rev. Contr., vol. 37, no. 2, pp. 191-219, 2013. [2] Fossati, L., and Varacca, D., “A Petri net model of handshake protocols”, Electr. Notes Theor. Comput. Sci., vol. 229, no. 3, pp. 59-76, 2009. [3] Lv, Y. Q., Lee, C. K. M., Wu, Z., Chan, H. K., and Ip, W. H., “Priority-based distributed manufacturing process modeling via hierarchical timed color Petri net”, IEEE Trans. Industr. Inform., vol. 9, no. 4, pp. 1836-1846, 2013. [4] Fanti, M. P., Iacobellis, G., Mangini, A. M., and Ukovich, W., “Freeway traffic modeling and control in a first-order hybrid Petri framework”, IEEE Trans. Autom. Sci. Eng., vol. 11, no. 1, pp. 90-102, 2014. [5] Chen, T. M., Sanchez-Aarnoutse, J. C., and Buford, J., “Petri nets modeling of cyberphysical attacks on smart grid”, IEEE Trans. Smart Grid., vol. 2, no. 4, pp. 741-749, 2011. [6] Guan, S. L., Nakamura, M., Shikanai, T., and Okazaki, T., “Hybrid Petri nets modeling for farm work flow”, Comput. Electron. Agricult., vol. 62, no. 2, pp. 149-158, 2008. [7] Araújo, M., and Roque, L., “Modeling games with Petri nets”, in Proc. Digital Games Research Association, 2009, pp. 1-9. [8] Syufagi, M.A., Hariadi, M, and Purnomo, M. H., “Petri net model for serious games based on motivation behavior classification”, Int. J. Comp. Games Technol., vol. 2013, Article ID 851287, pp. 1-12, 2013. [9] Kuo, C. H., Kuo, Y. C., Chen, T. S., Shen, Y. P, and Cheng, C. C., “Petri-net-based implementations for FIRA weightlifting and sprint games with a humanoid robot”, Robotics Autonom. Syst., vol. 62, no. 3, pp. 282-293, 2014. [10] Basile, F., Carbone, C., and Chiacchio, P., “Simulation and analysis of discrete-event control systems based on Petri nets using PNetLab”, Contr. Eng. Pract., vol. 15, no. 2, pp. 241-259, 2007. [11] Ahmad, F., Fakhir, I., Khan, S. A., and Khan, Y. D., “Petri net-based modeling and control of the multi-elevator systems”, Neural Comput. Appl., vol. 24, no. 7-8, pp. 1601-1612, 2014. [12] Fukuda, O., Kim, J. H., Nakai, I., and Ichikawa, Y., “EMG control of a pneumatic 5fingered hand using a Petri net”, Artif. Life Robot., vol. 16, no. 1, pp. 90-93, 2011. [13] Su, C., and Li, H. G., “An affective learning agent with Petri-net-based implementation”, Appl. Intell., vol. 37, no. 4, pp. 569-585, 2012. [14] Sosnoski, D., Introduction to Japanese culture. Rutland: Tuttle. 2001 [15] Bloom, J., Clark, C., Clifford, C., Duncan, A., Khan, H., and Papantoniou, M., “Platform independent Petri net editor, final report”, 2003, available at: http://pipe2.sourceforge.net/documents/PIPE-report.pdf. Unauthenticated Download Date | 7/29/17 12:04 AM
© Copyright 2026 Paperzz