Skip to content

Commit 6d18be5

Browse files
remove height and width from map.config
1 parent 9156036 commit 6d18be5

File tree

7 files changed

+19
-14
lines changed

7 files changed

+19
-14
lines changed

map.config

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ CHAT_LIMIT = 5
1212
MAX_MESSAGE_LENGTH = 32
1313
GAME_MAXIMUM_TURN_COUNT = 50
1414
RATE_DEATH_RESOURCE = 0.8
15-
MAP_WIDTH = 32
16-
MAP_HEIGHT = 32
1715
BASE_MAX_ATTACK_DISTANCE = 6
1816
BASE_ATTACK_DAMAGE = 3
1917
BASE_INIT_HEALTH = 10

src/main/java/ir/sharif/aichallenge/server/engine/network/ClientHandler.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class ClientHandler {
3333
/**
3434
* Maximum number of exceptions during connection.
3535
*/
36-
public static final int MAX_NUM_EXCEPTIONS = 20;
36+
public static final int MAX_NUM_EXCEPTIONS = 5;
3737

3838
/**
3939
* Logging tag.
@@ -79,6 +79,8 @@ public class ClientHandler {
7979
*/
8080
private final Object messageNotifier;
8181

82+
private int maxSendingFails = 0;
83+
8284
/**
8385
* Message queue. These messages will be sent to the client asap.
8486
*/
@@ -181,6 +183,11 @@ public Runnable getSender() {
181183
client.send(msg);
182184
} catch (Exception e) {
183185
Log.i(logTag, "Message sending failure", e);
186+
maxSendingFails++;
187+
if (maxSendingFails > MAX_NUM_EXCEPTIONS) {
188+
Log.e("ClientHandler", "Max number of sending failure expections reached");
189+
System.exit(-1);
190+
}
184191
}
185192
}
186193
};

src/main/java/ir/sharif/aichallenge/server/logic/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private static int extractExtraTime(String[] args) {
4545
class ShutDownHookThread extends Thread {
4646
@Override
4747
public void run() {
48-
System.out.println("\u001B[31m" + "Bye!" + "\u001B[0m");
48+
Log.i("Server", "\u001B[31m" + "Bye!" + "\u001B[0m");
4949
// kill ants
5050
AntGenerator.killAnts();
5151
super.run();

src/main/java/ir/sharif/aichallenge/server/logic/config/ConfigReader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public static void readConfigFile() {
4545
ConstConfigs.MAX_MESSAGE_LENGTH = Integer.parseInt(props.getProperty("MAX_MESSAGE_LENGTH"));
4646
ConstConfigs.GAME_MAXIMUM_TURN_COUNT = Integer.parseInt(props.getProperty("GAME_MAXIMUM_TURN_COUNT"));
4747
ConstConfigs.RATE_DEATH_RESOURCE = Float.parseFloat(props.getProperty("RATE_DEATH_RESOURCE"));
48-
ConstConfigs.MAP_WIDTH = Integer.parseInt(props.getProperty("MAP_WIDTH"));
49-
ConstConfigs.MAP_HEIGHT = Integer.parseInt(props.getProperty("MAP_HEIGHT"));
48+
// ConstConfigs.MAP_WIDTH = Integer.parseInt(props.getProperty("MAP_WIDTH"));
49+
// ConstConfigs.MAP_HEIGHT = Integer.parseInt(props.getProperty("MAP_HEIGHT"));
5050
ConstConfigs.BASE_MAX_ATTACK_DISTANCE = Integer.parseInt(props.getProperty("BASE_MAX_ATTACK_DISTANCE"));
5151
ConstConfigs.BASE_ATTACK_DAMAGE = Integer.parseInt(props.getProperty("BASE_ATTACK_DAMAGE"));
5252
ConstConfigs.BASE_INIT_HEALTH = Integer.parseInt(props.getProperty("BASE_INIT_HEALTH"));

src/main/java/ir/sharif/aichallenge/server/logic/model/map/MapGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ else if (cellTypeSelector < breadCellProb + grassCellProb + wallCellProb)
6262
}
6363

6464
public static MapGeneratorResult generateFromFile(String fileName) {
65-
int height = ConstConfigs.MAP_HEIGHT;
66-
int width = ConstConfigs.MAP_WIDTH;
65+
// int height = ConstConfigs.MAP_HEIGHT;
66+
// int width = ConstConfigs.MAP_WIDTH;
6767
try {
68-
ExternalMap externalMap = JsonUtility.readMapFromFile(fileName, height, width);
69-
GameMap gameMap = new GameMap(externalMap.getCells(), height, width);
68+
ExternalMap externalMap = JsonUtility.readMapFromFile(fileName);
69+
GameMap gameMap = new GameMap(externalMap.getCells(), ConstConfigs.MAP_HEIGHT, ConstConfigs.MAP_WIDTH);
7070
List<BaseCell> baseCells = externalMap.getUnAllocatedBaseCells();
7171
if (baseCells.size() < 2) {
7272
Log.e("MapGenerator", "There should be two base cells in map.json!");

src/main/java/ir/sharif/aichallenge/server/logic/utility/AntGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void run() {
3939
try {
4040
Thread.sleep(PROCESS_TIMEOUT_SECONDS * 1000);
4141
if (waitingProcessIDs.contains(antID)) {
42-
System.out.println("\u001B[31mClient Process Timeout passed\u001B[0m");
42+
Log.e("DEAD_POINT", "\u001B[31mClient Process Timeout passed\u001B[0m");
4343
killAnts();
4444
System.exit(-1);
4545
}

src/main/java/ir/sharif/aichallenge/server/logic/utility/JsonUtility.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
public class JsonUtility {
1919

20-
public static ExternalMap readMapFromFile(String fileName, int height, int width)
20+
public static ExternalMap readMapFromFile(String fileName)
2121
throws IOException, ParseException {
2222

2323
JSONParser jsonParser = new JSONParser();
@@ -31,8 +31,8 @@ public static ExternalMap readMapFromFile(String fileName, int height, int width
3131
System.exit(-1);
3232
}
3333
JSONArray cells = (JSONArray) map.get("cells_type");
34-
height = ConstConfigs.MAP_HEIGHT;
35-
width = ConstConfigs.MAP_WIDTH;
34+
int height = ConstConfigs.MAP_HEIGHT;
35+
int width = ConstConfigs.MAP_WIDTH;
3636
Cell[][] mapCells = new Cell[height][width];
3737
ExternalMap externalMap = new ExternalMap(mapCells);
3838
for (Object o : cells) {

0 commit comments

Comments
 (0)