import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;
/**
* This example program in Java illustrates how the IO works with the CodeCup
* System. This example is written by Jaap Taal for the CodeCup game 2009
* Pillars. Feel free to modify or use this code. The use of this code is not
* compulsary.
*/
public class Pillars {
private static boolean[][] board = new boolean[10][10];
private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
private static Random random = new Random();
/**
* In this example program the tiles and pillars are stored in
* board[10][10]. It is up to you to use this or not. In the function
* read_pillars the board will be initialized and will the pillars be read
* in.
*/
private static void readPillars() throws IOException {
int i, j;
for (i = 0; i < 10; ++i) {
for (j = 0; j < 10; ++j) {
board[i][j] = false;
}
}
for (i = 0; i < 10; ++i) {
String pillar = in.readLine();
board[pillar.charAt(0) - 'A'][pillar.charAt(1) - 'a'] = true;
}
}
/**
* In the method processOpponentsMove the opponent's move is processed.
*/
private static void processOpponentsMove(String move) {
int i1 = move.charAt(0) - 'A';
int j1 = move.charAt(1) - 'a';
int i2 = move.charAt(2) - 'A';
int j2 = move.charAt(3) - 'a';
for (int i = i1; i <= i2; i++) {
for (int j = j1; j <= j2; j++) {
board[i][j] = true;
}
}
}
/**
* In the function doOwnMove you have to calculate on basis of the positions
* on the board what the best move is.
* In this example only a simple random player is programmed.
* It's up to you to fill the body of this function with the best you can achieve!
* Good luck!
*/
private static void doOwnMove() {
// Generate a random number from 0 up to 99:
int i = random.nextInt(10), j = random.nextInt(10);
while (board[i][j]) {
if (i < 9) {
++i;
} else {
i = 0;
j++;
if (j == 10) {
j = 0;
}
}
}
// If you get here you've found an empty spot:
// Then you pick the found empty spot to perform your random move:
board[i][j] = true;
System.out.printf("%c%c%c%c%n", i + 'A', j + 'a', i + 'A', j + 'a');
System.out.flush();
}
public static void main(String[] args) throws IOException {
readPillars();
String move = in.readLine();
if (move.equals("Start")) {
move = null;
}
while (move == null || !move.equals("Quit")) {
if (move != null) {
processOpponentsMove(move);
}
doOwnMove();
move = in.readLine();
}
}
}
syntax highlighted by Code2HTML, v. 0.9.1