필터 지우기
필터 지우기

How to model parallel interaction in a gaming scenario?

조회 수: 1 (최근 30일)
Bolin
Bolin 2019년 4월 7일
편집: Bolin 2019년 4월 7일
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