-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add brutaltester settings for vindinium Ref. (And comment out the Sys…
…tem.err.print in Referee)
- Loading branch information
me
committed
Aug 28, 2018
1 parent
b10c9fd
commit 9fc460f
Showing
4 changed files
with
192 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/main/java/com/codingame/gameengine/runner/CommandLineInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package com.codingame.gameengine.runner; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Method; | ||
import java.nio.charset.Charset; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.DefaultParser; | ||
import org.apache.commons.cli.HelpFormatter; | ||
import org.apache.commons.cli.Options; | ||
|
||
import com.codingame.gameengine.runner.dto.GameResult; | ||
import com.google.common.io.Files; | ||
|
||
public class CommandLineInterface { | ||
|
||
public static void main(String[] args) { | ||
try { | ||
Options options = new Options(); | ||
|
||
options.addOption("h", false, "Print the help").addOption("p1", true, "Required. Player 1 command line.") | ||
.addOption("p2", true, "Required. Player 2 command line.") | ||
.addOption("p3", true, "Player 3 command line.").addOption("p4", true, "Player 4 command line.") | ||
.addOption("s", false, "Server mode").addOption("l", true, "File output for logs") | ||
.addOption("d", true, "Referee initial data"); | ||
|
||
CommandLine cmd = new DefaultParser().parse(options, args); | ||
|
||
if (cmd.hasOption("h") || !cmd.hasOption("p1") || !cmd.hasOption("p2") || !cmd.hasOption("p3") || !cmd.hasOption("p4")) { | ||
new HelpFormatter().printHelp( | ||
"-p1 <player1 command line> -p2 <player2 command line> -p3 <player3 command line> -p4 <player4 command line> [-s -l <File output for logs>]", | ||
options); | ||
System.exit(0); | ||
} | ||
|
||
MultiplayerGameRunner runner = new MultiplayerGameRunner(); | ||
|
||
Field getGameResult = GameRunner.class.getDeclaredField("gameResult"); | ||
getGameResult.setAccessible(true); | ||
GameResult result = (GameResult) getGameResult.get(runner); | ||
|
||
if (cmd.hasOption("d")) { | ||
String data = cmd.getOptionValue("d"); | ||
Properties prop = new Properties(); | ||
for (String entry : data.split(";")) { | ||
String[] values = entry.split("="); | ||
prop.setProperty(values[0], values[1]); | ||
} | ||
runner.setGameParameters(prop); | ||
// result.refereeInput = cmd.getOptionValue("d"); | ||
} | ||
|
||
int playerCount = 0; | ||
|
||
for (int i = 1; i <= 4; ++i) { | ||
if (cmd.hasOption("p" + i)) { | ||
runner.addAgent(cmd.getOptionValue("p" + i)); | ||
playerCount += 1; | ||
} | ||
} | ||
|
||
if (cmd.hasOption("s")) { | ||
runner.start(); | ||
} else { | ||
Method initialize = GameRunner.class.getDeclaredMethod("initialize", Properties.class); | ||
initialize.setAccessible(true); | ||
initialize.invoke(runner, new Properties()); | ||
|
||
Method runAgents = GameRunner.class.getDeclaredMethod("runAgents"); | ||
runAgents.setAccessible(true); | ||
runAgents.invoke(runner); | ||
|
||
if (cmd.hasOption("l")) { | ||
Method getJSONResult = GameRunner.class.getDeclaredMethod("getJSONResult"); | ||
getJSONResult.setAccessible(true); | ||
|
||
Files.asCharSink(Paths.get(cmd.getOptionValue("l")).toFile(), Charset.defaultCharset()) | ||
.write((String) getJSONResult.invoke(runner)); | ||
} | ||
|
||
for (int i = 0; i < playerCount; ++i) { | ||
System.out.println(result.scores.get(i)); | ||
} | ||
|
||
for (String line : result.uinput) { | ||
System.out.println(line); | ||
} | ||
} | ||
|
||
// We have to clean players process properly | ||
Field getPlayers = GameRunner.class.getDeclaredField("players"); | ||
getPlayers.setAccessible(true); | ||
@SuppressWarnings("unchecked") | ||
List<Agent> players = (List<Agent>) getPlayers.get(runner); | ||
|
||
if (players != null) { | ||
for (Agent player : players) { | ||
Field getProcess = CommandLinePlayerAgent.class.getDeclaredField("process"); | ||
getProcess.setAccessible(true); | ||
Process process = (Process) getProcess.get(player); | ||
|
||
process.destroy(); | ||
} | ||
} | ||
} catch (Exception e) { | ||
System.err.println(e); | ||
e.printStackTrace(System.err); | ||
System.exit(1); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration package="log4j.test" | ||
status="WARN"> | ||
<Appenders> | ||
<Console name="Console" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> | ||
</Console> | ||
</Appenders> | ||
<Loggers> | ||
<Logger name="log4j.test.Log4jTest" level="trace"> | ||
<AppenderRef ref="Console"/> | ||
</Logger> | ||
<Root level="error"> | ||
<AppenderRef ref="Console"/> | ||
</Root> | ||
</Loggers> | ||
</Configuration> |