Last active
July 26, 2016 03:37
-
-
Save zachpendleton/dbdd0e78ab112772111f75b3ba2133ee to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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