Making a world cup tournament simulator

4 visualizaciones (últimos 30 días)
Er Le
Er Le el 24 de Mayo de 2022
Editada: Omega el 11 de Jul. de 2024
I am making a world cup simulator
I am done with making the group stage simulator
How do I write a code for the tournament stage?
for example, the first place from group A is playing against the second place from group B. The second place from group A is playing against the first place from group B.
A={'Qatar';'Ecuador';'Senegal';'Netherlands'};
teamRank = randperm(4);
A_advance = A(teamRank(1:2))
B={'England';'IR Iran';'USA';'Euro Play-off'};
teamRank = randperm(4);
B_advance = B(teamRank(1:2))
C={'Argentina';'Saudi Arabia';'Mexico';'Poland'};
teamRank = randperm(4);
C_advance = C(teamRank(1:2))
D={'France';'IC Play-off 1';'Denmark';'Tuinisa'};
teamRank = randperm(4);
D_advance = D(teamRank(1:2))
E={'Spain';'IC Play-off 2';'Germany';'Japan'};
teamRank = randperm(4);
E_advance = E(teamRank(1:2))
F={'Belgium';'Canada';'Morocco';'Coratia'};
teamRank = randperm(4);
F_advance = F(teamRank(1:2))
G={'Brazil';'Serbia';'Switzerland';'Cameroon'};
teamRank = randperm(4);
G_advance = G(teamRank(1:2))
H={'Portugal';'Ghana';'Uruguay';'Korea Republic'};
teamRank = randperm(4);
H_advance = H(teamRank(1:2))
these are my codes for the group stage

Respuestas (1)

Omega
Omega el 11 de Jul. de 2024
Editada: Omega el 11 de Jul. de 2024
Hi Er Le,
I understand that you would like to create a World Cup tournament simulator. I see that you have already written the code for the group stage simulator. To simulate the tournament stage, you can first define the Round of 16 matchups based on the rules you have specified and then simulate the matches, assuming the results are random.
Here is an example code to do so:
A={'Qatar';'Ecuador';'Senegal';'Netherlands'};
teamRank = randperm(4);
A_advance = A(teamRank(1:2));
B={'England';'IR Iran';'USA';'Euro Play-off'};
teamRank = randperm(4);
B_advance = B(teamRank(1:2));
C={'Argentina';'Saudi Arabia';'Mexico';'Poland'};
teamRank = randperm(4);
C_advance = C(teamRank(1:2));
D={'France';'IC Play-off 1';'Denmark';'Tuinisa'};
teamRank = randperm(4);
D_advance = D(teamRank(1:2));
E={'Spain';'IC Play-off 2';'Germany';'Japan'};
teamRank = randperm(4);
E_advance = E(teamRank(1:2));
F={'Belgium';'Canada';'Morocco';'Coratia'};
teamRank = randperm(4);
F_advance = F(teamRank(1:2));
G={'Brazil';'Serbia';'Switzerland';'Cameroon'};
teamRank = randperm(4);
G_advance = G(teamRank(1:2));
H={'Portugal';'Ghana';'Uruguay';'Korea Republic'};
teamRank = randperm(4);
H_advance = H(teamRank(1:2));
% Define the Round of 16 matchups
roundOf16 = {
A_advance{1}, B_advance{2};
A_advance{2}, B_advance{1};
C_advance{1}, D_advance{2};
C_advance{2}, D_advance{1};
E_advance{1}, F_advance{2};
E_advance{2}, F_advance{1};
G_advance{1}, H_advance{2};
G_advance{2}, H_advance{1};
};
% Function to simulate a match
simulateMatch = @(team1, team2) team1{randi(2)};
% Simulate the Round of 16
quarterFinals = cell(8, 1);
for i = 1:8
quarterFinals{i} = simulateMatch(roundOf16(i, :));
end
% Define the Quarter Finals matchups
quarterFinalMatchups = reshape(quarterFinals, 2, 4)';
% Simulate the Quarter Finals
semiFinals = cell(4, 1);
for i = 1:4
semiFinals{i} = simulateMatch(quarterFinalMatchups(i, :));
end
% Define the Semi Finals matchups
semiFinalMatchups = reshape(semiFinals, 2, 2)';
% Simulate the Semi Finals
finals = cell(2, 1);
for i = 1:2
finals{i} = simulateMatch(semiFinalMatchups(i, :));
end
% Simulate the Final
champion = simulateMatch(finals);
% Display the results
disp('Champion:');
Champion:
disp(champion);
Ecuador

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by