Commit c79f7b56 authored by Nicholas Ardavin's avatar Nicholas Ardavin
Browse files

Updates for 2020 & replays

parent f08d2f7b
No related merge requests found
Pipeline #29562 canceled with stage
Showing with 27 additions and 27 deletions
+27 -27
......@@ -10,8 +10,8 @@ import edu.caltech.cs2.project08.game.Move;
import edu.caltech.cs2.project08.game.SimpleEvaluator;
public class Bot {
public static final String BOT_NAME = "FILL_IN_YOUR_NAME_FROM_SERVER";
public static final String BOT_PASS = "FILL_IN_YOUR_PASSWORD_FROM_SERVER";
public static final String BOT_NAME = "MyBotName";
public static final String BOT_PASS = "MyBotPassword";
private Evaluator<ArrayBoard> evaluator;
private BoardFactory<ArrayBoard> boardFactory;
......
......@@ -13,7 +13,7 @@ import java.net.*;
import java.util.*;
public class Play {
public static final String SERVER = "http://othello.countablethoughts.com/";
public static final String SERVER = "http://missing.coffee/";
private static boolean WAITING = false;
public static JSONArray bots;
......@@ -31,33 +31,16 @@ public class Play {
Socket socket = IO.socket(SERVER + "?bot=" + Bot.BOT_NAME + "&pw=" + Bot.BOT_PASS, opts);
socket.on(Socket.EVENT_CONNECT, (arg) -> {
//System.out.println("Connected to server.");
System.out.println("Connected to server.");
isConnected = true;
}).on(Socket.EVENT_DISCONNECT, (arg) -> {
//System.out.println("Disconnected from server.");
System.out.println("Disconnected from server.");
}).on("bad_connect", (arg) -> {
try {
System.out.println(((JSONObject) arg[1]).getString("message"));
} catch (JSONException e) { }
System.exit(1);
})/*.on("gameover", (arg) -> {
JSONObject obj = (JSONObject) arg[0];
try {
String result = obj.getString("result");
if (result.equals("draw")) {
System.out.println("The game was a draw!");
}
else {
System.out.println(result + " won!");
}
} catch (JSONException e) {
e.printStackTrace();
}
if (WAITING) {
System.out.print(">> ");
WAITING = false;
}
})*/.on("failure", (arg) -> {
}).on("failure", (arg) -> {
JSONObject obj = (JSONObject) arg[0];
String message = "";
try {
......@@ -84,7 +67,8 @@ public class Play {
} catch (JSONException e) { }
if (!games.contains(gameId)) {
System.out.println("Watch the game at: " + SERVER + "watch?game=" + gameId);
System.out.println("Watch the game LIVE at: " + SERVER + "watch?game=" + gameId);
System.out.println("Replay will be available at: " + SERVER + "replay?game=" + gameId);
games.add(gameId);
}
......@@ -99,8 +83,22 @@ public class Play {
int finalOpTime = opTime;
String finalId = gameId;
Thread thread = new Thread(() -> {
Move best = bot.getBestMove(finalPos, finalMyTime, finalOpTime);
socket.emit("move", best, finalId);
Move best;
try {
best = bot.getBestMove(finalPos, finalMyTime, finalOpTime);
socket.emit("move", best, finalId);
} catch (Exception e) {
// If the searcher crashed, return a purposeful bad move
e.printStackTrace();
try {
Thread.sleep(100);
} catch (Exception e2) {}
System.out.println("The move searcher crashed. Sending a bad move to end the game.");
System.out.print(">> ");
best = new Move(-1);
socket.emit("move", best, finalId);
}
});
thread.start();
}).on("info", (arg) -> {
......@@ -160,7 +158,9 @@ public class Play {
JSONObject botObj = bots.getJSONObject(i);
String name = botObj.getString("name");
String status = botObj.getString("status");
System.out.printf("\t%s - %s%s\n", name, status, name.equals(Bot.BOT_NAME) ? " - You" : "");
if (!status.equals("Not Connected")) {
System.out.printf("\t%s - %s%s\n", name, status, name.equals(Bot.BOT_NAME) ? " - You" : "");
}
} catch (JSONException e) { }
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment