-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
181 lines (143 loc) · 6.5 KB
/
Main.java
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Main {
private static final Scanner in = new Scanner(System.in);
private static final StringBuilder allLogs = new StringBuilder();
private enum GameType {
NORMAL,PVP
}
private static GameType stringToGameType(String gameType) {
switch (gameType.toLowerCase()) {
case "normal":
return GameType.NORMAL;
case "pvp":
return GameType.PVP;
default:
System.err.println("Usage: java Main [game-type]");
System.exit(1);
}
return GameType.NORMAL;
}
private static State nextState(int currentTurnNo) {
int noOfActiveAttackers = in.nextInt();
List<Attacker> attackers = new ArrayList<>();
for (int i = 0; i < noOfActiveAttackers; i++) {
attackers.add(
new Attacker(in.nextInt(), in.nextInt(), in.nextInt(), new Position(in.nextInt(), in.nextInt()), in.nextInt()));
}
int noOfActiveDefenders = in.nextInt();
List<Defender> defenders = new ArrayList<>();
for (int i = 0; i < noOfActiveDefenders; i++) {
defenders.add(
new Defender(in.nextInt(), in.nextInt(), in.nextInt(), new Position(in.nextInt(), in.nextInt())));
}
int coinsLeft = in.nextInt();
return new State(attackers, defenders, coinsLeft, currentTurnNo + 1);
}
private static PvPState nextPvPState(int currentTurnNo) {
int noOfActiveAttackers = in.nextInt();
List<Attacker> attackers = new ArrayList<>();
for (int i = 0; i < noOfActiveAttackers; i++) {
attackers.add(
new Attacker(in.nextInt(), in.nextInt(), in.nextInt(), new Position(in.nextInt(), in.nextInt()), in.nextInt()));
}
int noOfActiveOpponentAttackers = in.nextInt();
List<Attacker> opponentAttackers = new ArrayList<>();
for (int i = 0; i < noOfActiveOpponentAttackers; i++) {
opponentAttackers.add(
new Attacker(in.nextInt(), in.nextInt(), in.nextInt(), new Position(in.nextInt(), in.nextInt()),in.nextInt()));
}
return new PvPState(attackers, opponentAttackers, Constants.PVP_FIXED_COINS, currentTurnNo + 1);
}
private static GameMap getInitialMap() {
Constants.MAP_NO_OF_ROWS = in.nextInt();
Constants.MAP_NO_OF_COLS = in.nextInt();
int grid[][] = new int[Constants.MAP_NO_OF_ROWS][Constants.MAP_NO_OF_COLS];
for (int y = 0; y < Constants.MAP_NO_OF_ROWS; y++) {
for (int x = 0; x < Constants.MAP_NO_OF_COLS; x++) {
grid[x][y] = in.nextInt();
}
}
return new GameMap(grid);
}
private static void output(int turnNo, Game game) {
String log = game.getLog();
if (!log.isEmpty()) {
allLogs.append("TURN " + turnNo + "\n");
allLogs.append(log + "\n");
allLogs.append("ENDLOG\n");
}
List<SpawnDetail> spawnPositions = game.getSpawnPositions();
List<Integer> abilityActivations = game.getAbilityActivations();
System.out.println(spawnPositions.size());
for (SpawnDetail entry : spawnPositions) {
System.out.println(entry.getTypeId() + " " + entry.getPos().getX() + " " + entry.getPos().getY());
}
Map<Integer, Integer> playerSetTargets = game.getPlayerSetTargets();
System.out.println(playerSetTargets.size());
for (Map.Entry<Integer, Integer> entry : playerSetTargets.entrySet()) {
System.out.println(entry.getKey() + " " + entry.getValue());
}
System.out.println(abilityActivations.size());
for (Integer attacker_id : abilityActivations) {
System.out.println(attacker_id);
}
}
public static void main(String[] args) {
if(args.length < 1) {
System.err.println("Usage: java Main [game-type]");
System.exit(1);
}
GameType gameType = stringToGameType(args[0]);
Constants.NO_OF_TURNS = in.nextInt();
if(gameType == GameType.PVP) {
Constants.PVP_FIXED_COINS = in.nextInt();
}
else{
Constants.MAX_NO_OF_COINS = in.nextInt();
}
Constants.NO_OF_ATTACKER_TYPES = in.nextInt();
Constants.ATTACKER_TYPE_ATTRIBUTES = new HashMap<Integer, Attributes>();
for (int i = 1; i <= Constants.NO_OF_ATTACKER_TYPES; i++) {
Constants.ATTACKER_TYPE_ATTRIBUTES.put(i,
new Attributes(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt()));
}
Constants.NO_OF_DEFENDER_TYPES = in.nextInt();
Constants.DEFENDER_TYPE_ATTRIBUTES = new HashMap<Integer, Attributes>();
for (int i = 1; i <= Constants.NO_OF_DEFENDER_TYPES; i++) {
Constants.DEFENDER_TYPE_ATTRIBUTES.put(i,
new Attributes(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt(),0,0,0));
}
switch (gameType) {
case NORMAL:
GameMap map = getInitialMap();
List<Defender> defenders = map.spawnDefenders();
State state = new State(new ArrayList<>(), defenders, Constants.MAX_NO_OF_COINS, 0);
Run run = new Run();
Game game = run.run(state);
output(state.getTurnNo(), game);
for (int i = 0; i < Constants.NO_OF_TURNS; i++) {
state = nextState(state.getTurnNo());
game = run.run(state);
output(state.getTurnNo(), game);
}
in.close();
break;
case PVP:
PvPState pvpState = new PvPState(new ArrayList<>(), new ArrayList<>(), Constants.PVP_FIXED_COINS, 0);
RunPvP runPvP = new RunPvP();
Game pvpGame = runPvP.run(pvpState);
output(pvpState.getTurnNo(), pvpGame);
for (int i = 0; i < Constants.NO_OF_TURNS; i++) {
pvpState = nextPvPState(pvpState.getTurnNo());
pvpGame = runPvP.run(pvpState);
output(pvpState.getTurnNo(), pvpGame);
}
break;
}
System.err.println(allLogs.toString());
}
}