Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package lightrider;
- /**
- *
- * @author POWER
- */
- import java.util.Scanner;
- public class MyBot {
- private Scanner scan = new Scanner(System.in);
- public void run() {
- // declares variables on initialization
- String direction = "up";
- String field = new String();
- String[] split = new String[256];
- String[][] matrix = new String[18][18];
- int field_width = 0;
- int field_height = 0;
- int bot_id = 0;
- while (scan.hasNextLine()) {
- String line = scan.nextLine();
- if (line.length() == 0) continue;
- String[] parts = line.split(" ");
- switch (parts[0]) {
- case "settings":
- if (parts[1].equals("field_width"))
- {
- field_width = Integer.parseInt(parts[2]);
- }
- if (parts[1].equals("field_height"))
- {
- field_height = Integer.parseInt(parts[2]);
- }
- if (parts[1].equals("your_botid"))
- {
- bot_id = Integer.parseInt(parts[2]);
- }
- break;
- case "update":
- // renders game field
- if (parts[1].equals("game") && parts[2].equals("field"))
- {
- field = parts[3];
- }
- break;
- case "action":
- int x = 0;
- split = field.split(",");
- for (int i = 0 ; i < field_height + 2 ; i++)
- {
- for (int j = 0 ; j < field_width + 2 ; j++)
- {
- // fill field with x's
- matrix[i][j] = "x";
- }
- }
- for (int i = 1 ; i < field_height + 1 ; i++)
- {
- for (int j = 1 ; j < field_width + 1 ; j++, x++)
- {
- // fill field, minus 1 space for borders
- matrix[i][j] = split[x];
- }
- }
- // moves the bot
- System.out.println(direction);
- System.out.flush();
- break;
- default:
- // error
- }
- }
- }
- public static void main(String[] args) {
- (new MyBot()).run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement