How to model parallel interaction in a gaming scenario?

1 view (last 30 days)
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 Comments
TADA
TADA on 7 Apr 2019
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 on 7 Apr 2019
Edited: Bolin on 7 Apr 2019
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.

Sign in to comment.

Answers (0)

Categories

Find more on Card games in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!