Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.Arrays;
- public class MyBot {
- private Scanner scan = new Scanner(System.in);
- int timebank;
- int time_per_move;
- String[] player_names;
- String your_bot;
- int your_botid;
- boolean[][] checked = new boolean[3][3];
- int[][] thisfield;
- int round;
- char[][][] field = new char[9][3][3];
- String[] macroboard;
- int score = 0;
- public void run()
- {
- for(int q=0;q<3;q++) {
- for(int w=0;w<3;w++) {
- checked[q][w] = false;
- }
- }
- while (scan.hasNextLine()) {
- String line = scan.nextLine();
- if (line.length() == 0) continue;
- String[] parts = line.split(" ");
- switch (parts[0]) {
- case "settings":
- switch(parts[1]) {
- case "timebank": timebank = Integer.parseInt(parts[2]); break;
- case "time_per_move": time_per_move = Integer.parseInt(parts[2]); break;
- case "your_botid": your_botid = Integer.parseInt(parts[2]); break;
- case "your_bot": your_bot = parts[2];
- case "player_names": player_names = parts[2].split(","); break;
- default:
- }
- break;
- case "update":
- switch(parts[2]) {
- case "round": round = Integer.parseInt(parts[3]); break;
- case "field":
- byte check = 0;
- String g = parts[3];
- g = g.replaceAll(",","");
- char[] buff = g.toCharArray();
- for (int k=0;k<9;k++) {
- for (int h=0;h<3;h++) {
- for (int j=0;j<3;j++) {
- field[k][h][j] = buff[(18*(k/3)+(k*3)+j+h*9)];
- }
- }
- }
- break;
- case "macroboard":
- String f = parts[3];
- macroboard = f.split(",");
- break;
- default:
- }
- break;
- case "action":
- int x = 0;
- int y = 0;
- int z = 0;
- boolean done = false;
- for (int j=0;macroboard.length>j;j++) {
- try {
- Integer.parseInt(macroboard[j]);
- if (Integer.parseInt(macroboard[j]) == -1) {
- z=j;
- break;
- }
- }
- catch (NumberFormatException e) {
- }
- }
- for(int i=0;i<3;i++) {
- for(int c=0;c<3;c++) {
- if (field[z][i][c] == '.') {
- thisfield[i][c]=calc(z,i,c);
- }
- else thisfield[i][c] = 0;
- }
- }
- for(int s : thisfield) {
- y=c+(3*(z%3));
- x=i+(3*(z/3));
- done = true;
- break;
- }
- System.out.println("place_move "+x+" "+y);
- System.out.flush();
- break;
- default:
- // error
- }
- }
- }
- public static void main(String[] args) {
- (new MyBot()).run();
- }
- public int calc(int z, int c, int i) {
- if (i<0 || i>2 || c<0 || c>2 || checked[i][c]) {
- return score;
- }
- try {
- if(Character.isDigit(field[z][i][c])) {
- if(field[z][i][c] == your_botid) {
- score += 1;
- }
- else if(field[z][i][c] == '.') {
- }
- else score -= 1;;
- System.out.println(score + ".");
- }
- }
- catch (NumberFormatException e) {
- }
- checked[i][c] = true;
- calc(z,i,c+1);
- calc(z,i,c-1);
- calc(z,i+1,c);
- calc(z,i-1,c);
- calc(z,i-1,c-1);
- calc(z,i+1,c+1);
- return score;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement