Skip to content

Instantly share code, notes, and snippets.

@zachpendleton
Last active July 26, 2016 03:37
Show Gist options
  • Save zachpendleton/dbdd0e78ab112772111f75b3ba2133ee to your computer and use it in GitHub Desktop.
Save zachpendleton/dbdd0e78ab112772111f75b3ba2133ee to your computer and use it in GitHub Desktop.
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.*;
class ConnectFourBot {
private static final ObjectMapper mapper = new ObjectMapper();
public static void main(String[] args) {
new ConnectFourBot().play();
}
public void play() {
try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out)) {
while (true) {
JsonNode gameState = mapper.readTree(in.readLine());
if (gameState.hasNonNull("winner")) {
return;
}
int rowCount = gameState.get("board").size();
int columnCount = gameState.get("board").get(0).size();
out.println((int) Math.floor(Math.random() * columnCount));
out.flush();
}
} catch (IOException e) {
System.err.println(e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment