Group tournament simulation with matlab

10 views (last 30 days)
I am trying to develop a script for world cup alike tournament simulation. I've already finished script for play-off stage and now I have problems finding a solution how to write script for a group stage.
There are 4 teams (A,B,C,D) in a group. Each team will play one time against another (6 matches in total). The score of the team is generated randomly by using this code: A = [32:44]; a1 = numel(A); A1=A(ceil(rand*a1));
B = [30:47];
b1 = numel(B);
B1=B(ceil(rand*b1));
and so on. winner is decided:
if A1>=B1; (for the rest games: A2>=C1, A3>=D3, B2>=C2, B3>=D2, C3>=D3)
AW1=1;
BW1=0;
else
AW1=0;
BW1=1;
end
Finally, I will get number of victories for each team: AW=AW1+AW2+AW3; BW=BW1+BW2+BW3; CW=CW1+... and so on.
After all games are simulated, any ideas how can I arrange them into a standings ? There can be 4 possible outcomes of the Wins and Losses: [3 2 1 0], [3 1 1 1], [2 2 1 1] and [2 2 2 0]. Tie breaker is important (if there are 3 teams with a same number of victories, they can not be arranged in the final standings randomly). The point difference is defined as a variable. For example:
W L differance
1. A 3 0 20
2. B 1 2 5
3. C 1 2 -2
4. D 1 2 -10
Any ideas how to do it ? I am stuck on it for days. I think this is possible to do by manipulating if statements, but so far it looks that would be a very long script !

Answers (0)

Categories

Find more on Just for fun 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!