-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtroopPlaceBalanced.m
81 lines (67 loc) · 2.3 KB
/
troopPlaceBalanced.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function RiskGame = troopPlaceBalanced(troopNum, player, RiskGame)
myTerritories = 0;
% Iterates through the entire structure and collects which territories are owned by the inputted player
for count = 1:length(RiskGame)
if RiskGame(count).player == player
myTerritories = myTerritories + 1;
end
end
enemy1 = 0;
enemy2 = 0;
enemy3 = 0;
% Depending on which player was inputted, these if statements will collect the troops owned by the other players
if player == 1
for icount = 1:length(RiskGame)
if RiskGame(count).player == 2
enemy1 = enemy1 + 1;
elseif RiskGame(count).player == 3
enemy2 = enemy2 + 1;
elseif RiskGame(count).player == 4
enemy3 = enemy3 + 1;
end
end
elseif player == 2
for icount = 1:length(RiskGame)
if RiskGame(count).player == 1
enemy1 = enemy1 + 1;
elseif RiskGame(count).player == 3
enemy2 = enemy2 + 1;
elseif RiskGame(count).player == 4
enemy3 = enemy3 + 1;
end
end
elseif player == 3
for icount = 1:length(RiskGame)
if RiskGame(count).player == 2
enemy1 = enemy1 + 1;
elseif RiskGame(count).player == 1
enemy2 = enemy2 + 1;
elseif RiskGame(count).player == 4
enemy3 = enemy3 + 1;
end
end
elseif player == 4
for icount = 1:length(RiskGame)
if RiskGame(count).player == 2
enemy1 = enemy1 + 1;
elseif RiskGame(count).player == 3
enemy2 = enemy2 + 1;
elseif RiskGame(count).player == 1
enemy3 = enemy3 + 1;
end
end
end
% These ratios are created to see who is winning
ratio1 = enemy1/36;
ratio2 = enemy2/36;
ratio3 = enemy3/36;
myRatio = myTerritories/36;
TheArray = [ratio1, ratio2, ratio3, myRatio];
sort(TheArray, 'ascend');
% If the player's position in the ratio is first or second, they are losing, and will thus implement an aggressive troop placement strategy
if TheArray(1) == myRatio || TheArray(2) == myRatio
RiskGame = troopPlaceAggressive(troopNum, player, RiskGame);
% Otherwise, they are winning or in second place, so they will place their troops in a more defensive way to guard their territories
else
RiskGame = troopPlaceDefensive(troopNum, player, RiskGame);
end