Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package lightrider;
  7.  
  8. /**
  9. *
  10. * @author POWER
  11. */
  12. import java.util.Scanner;
  13.  
  14. public class MyBot {
  15.  
  16. private Scanner scan = new Scanner(System.in);
  17.  
  18. public void run() {
  19.  
  20. // declares variables on initialization
  21. String direction = "up";
  22. String field = new String();
  23. String[] split = new String[256];
  24. String[][] matrix = new String[18][18];
  25. int field_width = 0;
  26. int field_height = 0;
  27. int bot_id = 0;
  28.  
  29. while (scan.hasNextLine()) {
  30. String line = scan.nextLine();
  31.  
  32. if (line.length() == 0) continue;
  33.  
  34. String[] parts = line.split(" ");
  35. switch (parts[0]) {
  36. case "settings":
  37.  
  38. if (parts[1].equals("field_width"))
  39. {
  40. field_width = Integer.parseInt(parts[2]);
  41. }
  42. if (parts[1].equals("field_height"))
  43. {
  44. field_height = Integer.parseInt(parts[2]);
  45. }
  46. if (parts[1].equals("your_botid"))
  47. {
  48. bot_id = Integer.parseInt(parts[2]);
  49. }
  50. break;
  51.  
  52. case "update":
  53.  
  54. // renders game field
  55. if (parts[1].equals("game") && parts[2].equals("field"))
  56. {
  57. field = parts[3];
  58. }
  59. break;
  60.  
  61. case "action":
  62.  
  63. int x = 0;
  64. split = field.split(",");
  65.  
  66. for (int i = 0 ; i < field_height + 2 ; i++)
  67. {
  68. for (int j = 0 ; j < field_width + 2 ; j++)
  69. {
  70. // fill field with x's
  71. matrix[i][j] = "x";
  72. }
  73. }
  74.  
  75. for (int i = 1 ; i < field_height + 1 ; i++)
  76. {
  77. for (int j = 1 ; j < field_width + 1 ; j++, x++)
  78. {
  79. // fill field, minus 1 space for borders
  80. matrix[i][j] = split[x];
  81.  
  82. }
  83. }
  84.  
  85.  
  86.  
  87. // moves the bot
  88. System.out.println(direction);
  89. System.out.flush();
  90. break;
  91. default:
  92. // error
  93. }
  94. }
  95. }
  96.  
  97. public static void main(String[] args) {
  98. (new MyBot()).run();
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement