Skip to content

Commit

Permalink
Merge pull request #13 from SharifAIChallenge/feat/team-name-log
Browse files Browse the repository at this point in the history
Add teams names parameter
  • Loading branch information
Parsa2820 authored Sep 1, 2022
2 parents 5bd6bb5 + 7fa5279 commit 24234a5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
8 changes: 4 additions & 4 deletions map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ agents:
nodeId: 1
token: "token_3"
team: FIRST
type: THIEF
type: JOKER
balance: 100.0
- id: 4
nodeId: 1
Expand Down Expand Up @@ -45,7 +45,7 @@ agents:
nodeId: 1
token: "token_8"
team: FIRST
type: POLICE
type: BATMAN
balance: 100.0
- id: 9
nodeId: 1
Expand All @@ -63,7 +63,7 @@ agents:
nodeId: 1
token: "token_11"
team: SECOND
type: THIEF
type: JOKER
balance: 100.0
- id: 12
nodeId: 1
Expand Down Expand Up @@ -93,7 +93,7 @@ agents:
nodeId: 1
token: "token_16"
team: SECOND
type: POLICE
type: BATMAN
balance: 100.0

income:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ir.sharif.aic.hideandseek.api.grpc.HideAndSeek;
import ir.sharif.aic.hideandseek.core.exceptions.NotFoundException;
import ir.sharif.aic.hideandseek.core.models.*;
import ir.sharif.aic.hideandseek.core.watchers.EventLogger;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
Expand All @@ -27,19 +28,22 @@ public class GameConfigInjector {
private static final String JAVA_EXEC_CMD = "java -jar";
private static final Logger LOGGER = LoggerFactory.getLogger(GameConfigInjector.class);
private static String FIRST_TEAM_PATH = null;
private static String FIRST_TEAM_NAME = null;
private static String SECOND_TEAM_PATH = null;
private static String SECOND_TEAM_NAME = null;
private static String GAME_CONFIG_PATH = null;
private static String MAP_PATH = null;
private final static int INF = Integer.MAX_VALUE;


public static void handleCMDArgs(String[] args) {
int namedArgsCount = 0;
for (String arg : args) {
handleArg(arg);
namedArgsCount += handleArg(arg) ? 1 : 0;
}
try {
GAME_CONFIG_PATH = args[2];
MAP_PATH = args[3];
GAME_CONFIG_PATH = args[namedArgsCount];
MAP_PATH = args[namedArgsCount+1];
} catch (Exception ignore) {
LOGGER.error("Invalid args.");
}
Expand All @@ -56,19 +60,34 @@ public static void handleCMDArgs(String[] args) {
if (MAP_PATH == null) {
LOGGER.warn("No path for map.json");
}

String teamsNames;
if (FIRST_TEAM_NAME != null && SECOND_TEAM_NAME != null) {
teamsNames = String.format("{\"first\":\"%s\", \"second\":\"%s\"}", FIRST_TEAM_NAME, SECOND_TEAM_NAME);
} else {
teamsNames = "{\"first\":\"FIRST\", \"second\":\"SECOND\"}";
}
GraphicLogger.getInstance().appendLog(teamsNames);
}

private static void handleArg(String arg) {
private static boolean handleArg(String arg) {
String[] split = arg.split("=");
try {
if (split[0].equals("--first-team")) {
FIRST_TEAM_PATH = split[1];
} else if (split[0].equals("--second-team")) {
SECOND_TEAM_PATH = split[1];
} else if (split[0].equals("--first-team-name")) {
FIRST_TEAM_NAME = split[1];
} else if (split[0].equals("--second-team-name")) {
SECOND_TEAM_NAME = split[1];
} else {
return false;
}
} catch (Exception e) {
e.printStackTrace();
}
return true;
}

private static String createRunCMD(String path) {
Expand Down

0 comments on commit 24234a5

Please sign in to comment.