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
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?
Bolin
Bolin 2019-4-7
编辑:Bolin 2019-4-7
Hey thanks for the reply. I think I understand what you mean by asychronously with timers.
To your other questions:
Alice can immediately start another round once the timer is fired, does not need to wait for Bob.
For example, the sequence would look like:
A(odd), A(odd),...
B(even),...
This means that Alice would have received two summations f at the end of the time interval t = [1,2], whereas B would only receive one.
The values of A,B are assumed to be held constant between firing.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Card games 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by