Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.16 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3.  
  4. public class MyBot {
  5.  
  6.     private Scanner scan = new Scanner(System.in);
  7.  
  8.     int timebank;
  9.     int time_per_move;
  10.     String[] player_names;
  11.     String your_bot;
  12.     int your_botid;
  13.    
  14.     boolean[][] checked = new boolean[3][3];
  15.     int[][] thisfield;
  16.     int round;
  17.     char[][][] field = new char[9][3][3];
  18.     String[] macroboard;
  19.     int score = 0;
  20.     public void run()
  21.     {
  22.         for(int q=0;q<3;q++) {
  23.             for(int w=0;w<3;w++) {
  24.                 checked[q][w] = false;
  25.             }
  26.         }
  27.        
  28.         while (scan.hasNextLine()) {
  29.             String line = scan.nextLine();
  30.  
  31.             if (line.length() == 0) continue;
  32.  
  33.             String[] parts = line.split(" ");
  34.             switch (parts[0]) {
  35.                 case "settings":
  36.                     switch(parts[1]) {
  37.                     case "timebank": timebank = Integer.parseInt(parts[2]); break;
  38.                     case "time_per_move": time_per_move = Integer.parseInt(parts[2]); break;
  39.                     case "your_botid": your_botid = Integer.parseInt(parts[2]); break;
  40.                     case "your_bot": your_bot = parts[2];
  41.                     case "player_names": player_names = parts[2].split(","); break;
  42.                     default:
  43.                     }
  44.                     break;
  45.                 case "update":
  46.                     switch(parts[2]) {
  47.                     case "round": round = Integer.parseInt(parts[3]); break;
  48.                     case "field":
  49.                         byte check = 0;
  50.                         String g = parts[3];
  51.                         g = g.replaceAll(",","");
  52.                         char[] buff = g.toCharArray();
  53.                         for (int k=0;k<9;k++) {
  54.                             for (int h=0;h<3;h++) {
  55.                                 for (int j=0;j<3;j++) {
  56.                                     field[k][h][j] = buff[(18*(k/3)+(k*3)+j+h*9)];
  57.                                 }
  58.                             }
  59.                         }
  60.                     break;
  61.                     case "macroboard":
  62.                         String f = parts[3];
  63.                         macroboard = f.split(",");
  64.                         break;
  65.                     default:
  66.                     }
  67.                     break;
  68.                 case "action":
  69.                     int x = 0;
  70.                     int y = 0;
  71.                     int z = 0;
  72.                     boolean done = false;
  73.                    
  74.                     for (int j=0;macroboard.length>j;j++) {
  75.                         try {
  76.                             Integer.parseInt(macroboard[j]);
  77.                             if (Integer.parseInt(macroboard[j]) == -1) {
  78.                             z=j;
  79.                             break;
  80.                             }
  81.                         }
  82.                         catch (NumberFormatException e) {
  83.                         }
  84.                     }
  85.                    
  86.                     for(int i=0;i<3;i++) {
  87.                         for(int c=0;c<3;c++) {
  88.                             if (field[z][i][c] == '.') {
  89.                                 thisfield[i][c]=calc(z,i,c);
  90.                             }
  91.                             else thisfield[i][c] = 0;
  92.                         }
  93.                     }
  94.                     for(int s : thisfield) {
  95.                         y=c+(3*(z%3));
  96.                         x=i+(3*(z/3));
  97.                         done = true;
  98.                         break;
  99.                     }
  100.                        
  101.                     System.out.println("place_move "+x+" "+y);
  102.                     System.out.flush();
  103.                     break;
  104.                 default:
  105.                     // error
  106.             }
  107.         }
  108.     }
  109.  
  110.     public static void main(String[] args) {
  111.         (new MyBot()).run();
  112.     }
  113.    
  114.     public int calc(int z, int c, int i) {
  115.        
  116.         if (i<0 || i>2 || c<0 || c>2 || checked[i][c]) {
  117.             return score;
  118.         }
  119.         try {
  120.            
  121.             if(Character.isDigit(field[z][i][c])) {
  122.                 if(field[z][i][c] == your_botid) {
  123.                 score += 1;
  124.                 }
  125.                 else if(field[z][i][c] == '.') {
  126.                 }
  127.                 else score -= 1;;
  128.                 System.out.println(score + ".");
  129.             }
  130.         }
  131.         catch (NumberFormatException e) {
  132.         }
  133.         checked[i][c] = true;
  134.         calc(z,i,c+1);
  135.         calc(z,i,c-1);
  136.         calc(z,i+1,c);
  137.         calc(z,i-1,c);
  138.         calc(z,i-1,c-1);
  139.         calc(z,i+1,c+1);
  140.         return score;
  141.     }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement