How to model parallel interaction in a gaming scenario?
1 次查看(过去 30 天)
显示 更早的评论
I wish to model parallel interactions for two players of a game in MATLAB on a single-machine (no client-server). Can someone help me started with the following simple example?
Alice and Bob each generate a random integer from 1 to 10, let's call these numbers A, B
Then they compute the function,
f(A,B) = A+B, and receive the summation f.
However, I do not assume that the two players receive the summation f at the same time. I model this asychrony with the following assumption: if A or B is odd, then the person experience a 1 second delay, if it is even, then 2 seconds delay. The delay is only affecting the person who generates the even or odd number.
Then this experiment repeats
An example is as follows:
Suppose A = 1, B = 2. Then I pause 1 second for A, and I pause 2 seconds for B. This means I wait 1 second for A to receive f = 1+2, Alice then generates another random integer, say A = 2. This means when the timer for B is up,, B receives f = 2 + 2, then B generates another number.
In summary, at t = 1, Alice receives f = 1+2 = 3, A then generates 2, at t = 2, Bob receives f = 2+2 = 4...
It could happen that both players receive the number at the same time, or that one player receives two numbers (say Alice gets odd and odd again) while the other play only receives 1 during the same time frame.
A pseudocode is as follows:
generate random number for A, and B
check whether A is even or odd
check whether B is even or odd
set time delay for A to be 1 second (if odd), 2 seconds (if even)
set time delay for B to be 1 second (if odd), 2 seconds (if even)
call f(A,B)
A receives f when the time delay is over
B receives f when the time delay is over.
Repeat
How do I model this parallelism?
4 个评论
TADA
2019-4-7
Also do you need to manage critical sections? Like if Bob started to calculate his f(A,B), does it need to stop Alice from raffling another number till the time f(A,B) is finished?
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!