Compare commits
No commits in common. "4e4b2c6d084b5ff95ed3d8294dd154444b8cdbae" and "9c555c9cde2529b9b5fb984a6989fbebe83c85cd" have entirely different histories.
4e4b2c6d08
...
9c555c9cde
@ -9,16 +9,13 @@ public class EnemyBot extends Bot {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected char nextMove(View view) {
|
protected char nextMove(View view) {
|
||||||
int size = view.width;
|
|
||||||
String data = view.data
|
String data = view.data
|
||||||
.replace('^', '*')
|
.replace('^', '*')
|
||||||
.replace('<', '*')
|
.replace('<', '*')
|
||||||
.replace('>', '*')
|
.replace('>', '*')
|
||||||
.replace('v', '*');
|
.replace('v', '*');
|
||||||
|
|
||||||
char[][] grid = dataToGrid(data, size);
|
if (data.contains("*") && random.nextFloat() < 0.8)
|
||||||
|
|
||||||
if (data.contains("*") && isInLineOfSight(grid))
|
|
||||||
return 'f';
|
return 'f';
|
||||||
|
|
||||||
return switch (random.nextInt(10)) {
|
return switch (random.nextInt(10)) {
|
||||||
@ -32,21 +29,4 @@ public class EnemyBot extends Bot {
|
|||||||
@Override
|
@Override
|
||||||
protected void print(View view) {
|
protected void print(View view) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected char[][] dataToGrid(String data, int size) {
|
|
||||||
char[][] grid = new char[size][size];
|
|
||||||
for (int i = 0; i < data.length(); i++) {
|
|
||||||
grid[i % size][i / size] = data.charAt(i);
|
|
||||||
}
|
|
||||||
return grid;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isInLineOfSight(char[][] grid) {
|
|
||||||
int size = grid.length;
|
|
||||||
for (int y = size / 2; y > 0; y--) {
|
|
||||||
if (grid[size / 2][y] == '*')
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,18 @@
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class RumbleBot extends Bot {
|
public class RumbleBot extends Bot {
|
||||||
protected final static String obstacles = "~#X*";
|
protected final static String obstacles = "~#X*";
|
||||||
protected final static String targets = "v^<>";
|
protected final static String targets = "v^<>";
|
||||||
|
protected boolean offByOne = true;
|
||||||
protected Random random = new Random();
|
protected int currentStepCount = 0;
|
||||||
protected int steps = 0;
|
protected int steps = 0;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
if(args.length == 0) {
|
if(args.length == 0) {
|
||||||
String[] dummyArgs = {"localhost", "63187"};
|
String[] dummyArgs = {"localhost", "63187"};
|
||||||
new Thread(new EnemyBot(dummyArgs)).start();
|
Bot dummy = new EnemyBot(dummyArgs);
|
||||||
new Thread(new EnemyBot(dummyArgs)).start();
|
new Thread(dummy).start();
|
||||||
new Thread(new EnemyBot(dummyArgs)).start();
|
|
||||||
new Thread(new EnemyBot(dummyArgs)).start();
|
|
||||||
new Thread(new EnemyBot(dummyArgs)).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Bot bot = new RumbleBot(args);
|
Bot bot = new RumbleBot(args);
|
||||||
@ -49,10 +45,7 @@ public class RumbleBot extends Bot {
|
|||||||
protected char[][] dataToGrid(String data, int size) {
|
protected char[][] dataToGrid(String data, int size) {
|
||||||
char[][] grid = new char[size][size];
|
char[][] grid = new char[size][size];
|
||||||
for (int i = 0; i < data.length(); i++) {
|
for (int i = 0; i < data.length(); i++) {
|
||||||
char c = data.charAt(i);
|
grid[i % size][i / size] = data.charAt(i);
|
||||||
if("ABCDEFGHIJKLMNOPQRSTUVWYZ".contains("" + c))
|
|
||||||
c = 'A';
|
|
||||||
grid[i % size][i / size] = c;
|
|
||||||
}
|
}
|
||||||
return grid;
|
return grid;
|
||||||
}
|
}
|
||||||
@ -61,34 +54,26 @@ public class RumbleBot extends Bot {
|
|||||||
int size = grid.length;
|
int size = grid.length;
|
||||||
for (int x = 0; x < size; x++) {
|
for (int x = 0; x < size; x++) {
|
||||||
for (int y = 0; y < size; y++) {
|
for (int y = 0; y < size; y++) {
|
||||||
int[][] dir = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
|
|
||||||
|
|
||||||
switch (grid[x][y]) {
|
switch (grid[x][y]) {
|
||||||
case '^' -> markLine(grid, x, y, dir[0], '*');
|
case 'v' -> markLine(grid, x, y, 0, 1);
|
||||||
case 'v' -> markLine(grid, x, y, dir[1], '*');
|
case '^' -> markLine(grid, x, y, 0, -1);
|
||||||
case '>' -> markLine(grid, x, y, dir[2], '*');
|
case '>' -> markLine(grid, x, y, 1, 0);
|
||||||
case '<' -> markLine(grid, x, y, dir[3], '*');
|
case '<' -> markLine(grid, x, y, -1, 0);
|
||||||
}
|
|
||||||
|
|
||||||
if(targets.contains("" + grid[x][y])) {
|
|
||||||
for (int[] direction : dir) {
|
|
||||||
markLine(grid, x, y, direction, 'o');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void markLine(char[][] grid, int x, int y, int[] dir, char c) {
|
private void markLine(char[][] grid, int x, int y, int dx, int dy) {
|
||||||
int size = grid.length;
|
int size = grid.length;
|
||||||
x += dir[0];
|
x += dx;
|
||||||
y += dir[1];
|
y += dy;
|
||||||
while (x >= 0 && x < size && y >= 0 && y < size && !obstacles.contains("" + grid[x][y])) {
|
while (x >= 0 && x < size && y >= 0 && y < size && !obstacles.contains("" + grid[x][y])) {
|
||||||
if (grid[x][y] == '.') {
|
if (grid[x][y] == '.') {
|
||||||
grid[x][y] = c;
|
grid[x][y] = '*';
|
||||||
}
|
}
|
||||||
x += dir[0];
|
x += dx;
|
||||||
y += dir[1];
|
y += dy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +91,12 @@ public class RumbleBot extends Bot {
|
|||||||
|
|
||||||
protected char walkAround(char[][] grid) {
|
protected char walkAround(char[][] grid) {
|
||||||
if (steps == 0) {
|
if (steps == 0) {
|
||||||
steps = random.nextInt(20);
|
currentStepCount = (currentStepCount + 1) % 10;
|
||||||
|
if (offByOne) {
|
||||||
|
currentStepCount++;
|
||||||
|
}
|
||||||
|
offByOne = !offByOne;
|
||||||
|
steps = currentStepCount;
|
||||||
return '>';
|
return '>';
|
||||||
} else {
|
} else {
|
||||||
steps--;
|
steps--;
|
||||||
|
@ -8,8 +8,8 @@ public class SnakeBot extends Bot {
|
|||||||
protected int steps = 0;
|
protected int steps = 0;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Bot bot = new SnakeBot(args);
|
Bot bot = new SnakeBot(args);
|
||||||
bot.run();
|
bot.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SnakeBot(String[] args) {
|
protected SnakeBot(String[] args) {
|
||||||
@ -72,8 +72,10 @@ public class SnakeBot extends Bot {
|
|||||||
int rightStars = 0;
|
int rightStars = 0;
|
||||||
for (int x = 0; x < size / 2; x++) {
|
for (int x = 0; x < size / 2; x++) {
|
||||||
for (int y = 0; y < size; y++) {
|
for (int y = 0; y < size; y++) {
|
||||||
if (grid[x][y] == '*') leftStars++;
|
if (grid[x][y] == '*')
|
||||||
if (grid[size - x - 1][y] == '*') rightStars++;
|
leftStars++;
|
||||||
|
if (grid[size - x - 1][y] == '*')
|
||||||
|
rightStars++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user