-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalMain.java
More file actions
192 lines (170 loc) · 8.95 KB
/
FinalMain.java
File metadata and controls
192 lines (170 loc) · 8.95 KB
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
182
183
184
185
186
187
188
189
190
191
192
package battlehub;
import battleship.core.*;
import battleship.games.*;
import battleship.ships.*;
import java.util.*;
/*
* INSTRUCTIONS
* $ javac battlehub/FinalMain.java
* $ java battlehub.FinalMain
*/
public class FinalMain {
public static void main(String[] args) {
int seed = (int) Math.floor(Math.random() * 100);
if (args.length >= 1) {
seed = Integer.parseInt(args[0]);
}
String instructorTeam = "Instructors";
String studentTeam = "Students";
System.out.println("Seed: " + seed);
CustomBattle battle = initBattle(seed, instructorTeam, studentTeam);
battle.setCanPrint(false);
battle.setMaxTurns(100);
battle.setArenaFile("files/final-arena.txt");
battle.setTurnFile("files/final-turns.txt");
battle.setLogFile("files/final-log.txt");
battle.run();
showBattleResults(battle, instructorTeam, studentTeam);
}
public static CustomBattle initBattle(int seed, String instructorTeam, String studentTeam) {
char[][] layout = {
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, // 0
{' ', 'X', 'Y', ' ', ' ', 'A', 'B', ' ', 'C', 'D', ' ', ' ', 'E', 'F', ' '}, // 1
{' ', 'W', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'G', ' '}, // 2
{' ', ' ', ' ', ' ', '#', ' ', ' ', '#', ' ', ' ', '#', ' ', ' ', ' ', ' '}, // 3
{' ', ' ', ' ', '#', ' ', ' ', '#', '@', '#', ' ', ' ', '#', ' ', ' ', ' '}, // 4
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, // 5
{' ', 'V', ' ', ' ', '#', ' ', ' ', '^', ' ', ' ', '#', ' ', ' ', 'H', ' '}, // 6
{' ', 'U', ' ', ' ', '@', ' ', '<', ' ', '>', ' ', '@', ' ', ' ', 'I', ' '}, // 7
{' ', 'T', ' ', ' ', '#', ' ', ' ', '&', ' ', ' ', '#', ' ', ' ', 'J', ' '}, // 8
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, // 9
{' ', ' ', ' ', '#', ' ', ' ', '#', '@', '#', ' ', ' ', '#', ' ', ' ', ' '}, // 10
{' ', ' ', ' ', ' ', '#', ' ', ' ', ' ', ' ', ' ', '#', ' ', ' ', ' ', ' '}, // 11
{' ', 'S', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 'K', ' '}, // 12
{' ', 'R', 'Q', ' ', ' ', ' ', 'P', 'O', 'N', ' ', ' ', ' ', 'M', 'L', ' '}, // 13
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, // 14
};
Map<Character, Class<? extends Ship>> shipMap = new HashMap<Character, Class<? extends Ship>>();
Map<Character, String> teamMap = new HashMap<Character, String>();
//shipMap.put('^', battleship.ships.DummyShip.class);
shipMap.put('^', esi17.hli109.DavyJonesLocker.class);
shipMap.put('<', esi17.smallcpu.SmallcpuShip.class);
shipMap.put('>', esi17.DoomDawn.DoomShip.class);
shipMap.put('%', battleship.ships.DummyShip.class);
shipMap.put('&', esi17.vkannan3.GeneticShip.class);
shipMap.put('@', battleship.ships.QueenShip.class);
shipMap.put('#', battleship.ships.HiveShip.class);
teamMap.put('^', instructorTeam);
teamMap.put('<', instructorTeam);
teamMap.put('>', instructorTeam);
teamMap.put('%', instructorTeam);
teamMap.put('&', instructorTeam);
teamMap.put('@', instructorTeam);
teamMap.put('#', instructorTeam);
shipMap.put('A', esi17.Nickthegreat.MoistNoodle.class);
shipMap.put('B', esi17.ssoto7713.SotoShip.class);
shipMap.put('C', esi17.slee1713.MakeAmericaGreatAgain.class);
shipMap.put('D', esi17.vsandrade99.TheBlackPearl.class);
shipMap.put('E', esi17.kaminoshimobe.KSsinker.class);
shipMap.put('F', esi17.AusWorley1.Mars.class);
shipMap.put('G', esi17.jtcrane.RoboShip.class);
shipMap.put('H', esi17.UnknownUser02.RoldanShip.class);
shipMap.put('I', esi17.cmercado995.MercadoShip.class);
shipMap.put('J', esi17.joshuatgonzalez.TheShip.class);
shipMap.put('K', esi17.ageorgescu17.Maverick.class);
shipMap.put('L', esi17.abilling.Ironsides.class);
shipMap.put('M', esi17.npatel6219.NehaShip.class);
shipMap.put('N', esi17.aproctor1.AlecShip.class);
shipMap.put('O', esi17.chrisjtoohey.TooheyShip.class);
shipMap.put('P', esi17.ririgoyen99.Immigrant.class);
shipMap.put('Q', esi17.cguy1.Pirateship.class);
shipMap.put('R', esi17.caesarsalad64.CuevasShip.class);
shipMap.put('S', esi17.jbrimm.ColossusofClout.class);
shipMap.put('T', esi17.estefaniaLopez4645.FriendShip.class);
shipMap.put('U', esi17.jjmun.PieceofShip.class);
shipMap.put('V', esi17.aquafreeze.AquafreezeShip.class);
shipMap.put('W', esi17.Dolphin20.Dolphin20Ship.class);
shipMap.put('X', esi17.Kahsel.KahselShip.class);
shipMap.put('Y', esi17.mruiz9.guppy.class);
/*shipMap.put('A', battleship.ships.DummyShip.class);
shipMap.put('B', battleship.ships.DummyShip.class);
shipMap.put('C', battleship.ships.DummyShip.class);
shipMap.put('D', battleship.ships.DummyShip.class);
shipMap.put('E', battleship.ships.DummyShip.class);
shipMap.put('F', battleship.ships.DummyShip.class);
shipMap.put('G', battleship.ships.DummyShip.class);
shipMap.put('H', battleship.ships.DummyShip.class);
shipMap.put('I', battleship.ships.DummyShip.class);
shipMap.put('J', battleship.ships.DummyShip.class);
shipMap.put('K', battleship.ships.DummyShip.class);
shipMap.put('L', battleship.ships.DummyShip.class);
shipMap.put('M', battleship.ships.DummyShip.class);
shipMap.put('N', battleship.ships.DummyShip.class);
shipMap.put('O', battleship.ships.DummyShip.class);
shipMap.put('P', battleship.ships.DummyShip.class);
shipMap.put('Q', battleship.ships.DummyShip.class);
shipMap.put('R', battleship.ships.DummyShip.class);
shipMap.put('S', battleship.ships.DummyShip.class);
shipMap.put('T', battleship.ships.DummyShip.class);
shipMap.put('U', battleship.ships.DummyShip.class);
shipMap.put('V', battleship.ships.DummyShip.class);
shipMap.put('W', battleship.ships.DummyShip.class);
shipMap.put('X', battleship.ships.DummyShip.class);
shipMap.put('Y', battleship.ships.DummyShip.class);*/
for (Character key : shipMap.keySet()) {
if (!teamMap.containsKey(key)) {
teamMap.put(key, studentTeam);
}
}
/*for (Character key : shipMap.keySet()) {
System.out.println(shipMap.get(key) + " --> " + teamMap.get(key));
}*/
List<Spawn> c = new ArrayList<Spawn>();
for (int y = 0; y < layout.length; y++) {
for (int x = 0; x < layout[y].length; x++) {
Character marker = layout[y][x];
if (shipMap.containsKey(marker) && teamMap.containsKey(marker)) {
Class<? extends Ship> shipClass = shipMap.get(marker);
String team = teamMap.get(marker);
Spawn spawn = new Spawn(shipClass, team, x, y);
c.add(spawn);
//System.out.println(c.size() + " " + shipClass + " " + team);
}
}
}
CustomBattle battle = new CustomBattle(c, seed, layout.length, layout[0].length);
return battle;
}
public static void showBattleResults(CustomBattle battle, String instructorTeam, String studentTeam) {
Arena arena = battle.getArena();
Map<String, Integer> scoreMap = new HashMap<String, Integer>();
scoreMap.put(instructorTeam, 0);
scoreMap.put(studentTeam, 0);
for (Ship ship : arena.getAllSpawnedShips()) {
if (ship.isSunk()) {
if (ship.getTeam().equals(instructorTeam)) {
int ss = scoreMap.get(studentTeam);
ss++;
scoreMap.put(studentTeam, ss);
} else {
int is = scoreMap.get(instructorTeam);
is++;
scoreMap.put(instructorTeam, is);
}
}
}
int sfs = scoreMap.get(studentTeam);
int ifs = scoreMap.get(instructorTeam);
String winner = "Draw";
if (sfs > ifs) {
winner = studentTeam;
} else if (sfs < ifs) {
winner = instructorTeam;
}
System.out.println("Final Battle Results");
System.out.println(String.format("Winner: %s", winner));
System.out.println(String.format("- %s sunk %d ships.", studentTeam, sfs));
System.out.println(String.format("- %s sunk %d ships.", instructorTeam, ifs));
}
}