diff --git a/.gitignore b/.gitignore index ac27821453644e39bbac8e16fc24da32c7f5f873..661502e55544327b27011e692ab196d6320a40ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ target/ +*.txt # Intellij *.iml diff --git a/src/main/java/com/fossgalaxy/games/fireworks/NetClient.java b/src/main/java/com/fossgalaxy/games/fireworks/NetClient.java index a7c5cc0c5ca3bf7d93b0fe365e35c30a146f4892..a9993e4ac63b665a52248d272a6e77d3e4caf1fa 100644 --- a/src/main/java/com/fossgalaxy/games/fireworks/NetClient.java +++ b/src/main/java/com/fossgalaxy/games/fireworks/NetClient.java @@ -3,7 +3,6 @@ package com.fossgalaxy.games.fireworks; import com.fossgalaxy.games.fireworks.human.ui.UIPlayer; import com.fossgalaxy.games.fireworks.human.ui.pretty.HumanUIAgent; import com.fossgalaxy.games.fireworks.state.actions.Action; -import com.fossgalaxy.games.fireworks.utils.AgentUtils; import java.io.IOException; @@ -18,12 +17,11 @@ import java.net.UnknownHostException; public class NetClient { public static void main(String[] args) { - try ( - Socket socket = new Socket("localhost", NetServer.FIREWORKS_SERVER_PORT); + Socket socket = new Socket(args[0], NetServer.FIREWORKS_SERVER_PORT); ) { - UIPlayer player = new UIPlayer("iggi", new HumanUIAgent(), true); + UIPlayer player = new UIPlayer("human", new HumanUIAgent(), true); //important, this MUST be the other way round to the server or they deadlock. ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream()); diff --git a/src/main/java/com/fossgalaxy/games/fireworks/NetServer.java b/src/main/java/com/fossgalaxy/games/fireworks/NetServer.java index 84415c4b4f05370bbb5d6d11328d28fad90d7790..2ec9ec9ac6912ef576f39be83c75fdea08b5b4bf 100644 --- a/src/main/java/com/fossgalaxy/games/fireworks/NetServer.java +++ b/src/main/java/com/fossgalaxy/games/fireworks/NetServer.java @@ -1,7 +1,10 @@ package com.fossgalaxy.games.fireworks; +import com.fossgalaxy.games.fireworks.ai.AgentPlayer; import com.fossgalaxy.games.fireworks.cluster.PredictorRunnerSingle; import com.fossgalaxy.games.fireworks.players.Player; +import com.fossgalaxy.games.fireworks.utils.AgentUtils; +import com.fossgalaxy.games.fireworks.utils.SetupUtils; import java.io.File; import java.io.FileNotFoundException; @@ -20,6 +23,8 @@ public class NetServer { public static void main(String[] args) throws FileNotFoundException { boolean running = true; + int nPlayers = 2; + int nAI = 1; Random r = new Random(); try ( @@ -32,11 +37,11 @@ public class NetServer { System.out.println("Waiting for players"); - String[] agentNames = new String[4]; - ServerNetworkPlayer[] networkPlayers = new ServerNetworkPlayer[4]; + String[] agentNames = new String[nPlayers+nAI]; + Player[] networkPlayers = new Player[nPlayers+nAI]; - for (int playerID = 0; playerID < agentNames.length; playerID++) { + for (int playerID = 0; playerID < nPlayers; playerID++) { try { Socket socket = serverSocket.accept(); @@ -52,6 +57,11 @@ public class NetServer { } } + for (int i=0; i<nAI; i++) { + agentNames[nPlayers+i] = "iggi"; + networkPlayers[nPlayers+i] = new AgentPlayer("iggi", AgentUtils.buildAgent("iggi")); + } + System.out.println("The game is ready to start"); playGame(agentNames, networkPlayers, r.nextLong(), statOut); @@ -69,7 +79,7 @@ public class NetServer { } - public static void playGame(String[] agentNames, ServerNetworkPlayer[] players, long seed, PrintStream out) { + public static void playGame(String[] agentNames, Player[] players, long seed, PrintStream out) { String gameID = "net-"+System.currentTimeMillis(); GameRunner runner = new GameRunner(gameID, players.length);