Compare commits

...
20 Commits
Author SHA1 Message Date
Your Average Code 3f96b89a47 outsource record Move 2024-01-26 16:38:39 +01:00
Your Average Code a3de94a4f8 SnakeBot enemies 2024-01-25 21:27:20 +01:00
Your Average Code 59514963eb simplify RumbleBot 2024-01-25 21:26:53 +01:00
Your Average Code 13955b7b29 RumbleBot random turn 2024-01-25 19:16:42 +01:00
Your Average Code 6391e9d149 RumbleBot shorter path to line of sight 2024-01-25 19:04:30 +01:00
Your Average Code 4e4b2c6d08 RumbleBot movement, markLine, more Enemies 2024-01-25 18:42:35 +01:00
Your Average Code e408032f5d SnakeBot reformat 2024-01-25 18:05:13 +01:00
Your Average Code a242381a9d EnemyBot has line of sight 2024-01-25 18:04:53 +01:00
Your Average Code 9c555c9cde DummyBot -> EnemyBot 2024-01-25 17:45:32 +01:00
Your Average Code 53482674e6 simplify markFiringLines 2024-01-25 16:01:26 +01:00
Your Average Code 8c40d7bacb RumbleBot markFiringLines 2024-01-25 15:49:53 +01:00
Your Average Code 49fffe2a27 RumbleBot dummy arguments 2024-01-25 15:06:06 +01:00
Your Average Code f3d09aabb6 intellij files 2024-01-25 14:57:58 +01:00
Your Average Code 0bcdabe75e RumbleBot detect players with direction 2024-01-25 14:57:34 +01:00
Your Average Code 3744c8232e DummyBot remove main 2024-01-25 14:56:44 +01:00
Your Average Code f98c5a1295 override print 2024-01-25 14:54:03 +01:00
Your Average Code c9a3937a12 Bot make print overridable 2024-01-25 14:53:50 +01:00
Your Average Code 0410084441 DummyBot more options 2024-01-25 14:18:12 +01:00
Your Average Code 475e5c1c5d Redundant 'close()' 2024-01-25 14:17:42 +01:00
Your Average Code 5fc6cb8216 Bot implements Runnable 2024-01-25 14:16:21 +01:00
8 changed files with 293 additions and 93 deletions

No files matched your search

+124
View File
@@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
+8 -4
View File
@@ -5,7 +5,7 @@ import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
public abstract class Bot { public abstract class Bot implements Runnable {
// Ein Bot ist ein Programm, das sich mit einem Server verbindet und // Ein Bot ist ein Programm, das sich mit einem Server verbindet und
// mit diesem kommuniziert. Der Server sendet dem Bot eine Zeichenkette, // mit diesem kommuniziert. Der Server sendet dem Bot eine Zeichenkette,
@@ -24,7 +24,7 @@ public abstract class Bot {
// Diese Methode stellt die Verbindung zum Server her und startet die // Diese Methode stellt die Verbindung zum Server her und startet die
// Kommunikation mit dem Server. Die Methode wird von der main-Methode // Kommunikation mit dem Server. Die Methode wird von der main-Methode
// aufgerufen. // aufgerufen.
protected void run() { public void run() {
try (Socket socket = new Socket()) { try (Socket socket = new Socket()) {
socket.connect(new InetSocketAddress(host, port)); socket.connect(new InetSocketAddress(host, port));
OutputStream out = socket.getOutputStream(); OutputStream out = socket.getOutputStream();
@@ -32,19 +32,23 @@ public abstract class Bot {
View view = new View(); View view = new View();
while (true) { while (true) {
view.read(in); view.read(in);
view.print(); print(view);
try { try {
char ch = nextMove(view); char ch = nextMove(view);
out.write(ch); out.write(ch);
} }
catch (Exception e) { break; } catch (Exception e) { break; }
} }
socket.close();
} catch (IOException e) { } catch (IOException e) {
System.err.println("Error: " + e.getMessage()); System.err.println("Error: " + e.getMessage());
} }
} }
protected void print(View view) {
view.print();
System.out.println();
}
// Diese Methode ermittelt den nächsten Zug des Bots. Sie wird von der // Diese Methode ermittelt den nächsten Zug des Bots. Sie wird von der
// run-Methode aufgerufen, nachdem der Server das Spielfeld gesendet hat. // run-Methode aufgerufen, nachdem der Server das Spielfeld gesendet hat.
// Subklassen müssen diese Methode implementieren. // Subklassen müssen diese Methode implementieren.
-23
View File
@@ -1,23 +0,0 @@
import java.util.Random;
public class DummyBot extends Bot {
protected final Random random = new Random();
public static void main(String[] args) {
Bot bot = new DummyBot(args);
bot.run();
}
protected DummyBot(String[] args) {
super(args);
}
@Override
protected char nextMove(View view) {
return switch (random.nextInt(3)) {
case 1 -> '<';
case 2 -> '>';
default -> '^';
};
}
}
+52
View File
@@ -0,0 +1,52 @@
import java.util.Random;
public class EnemyBot extends Bot {
protected final Random random = new Random();
protected EnemyBot(String[] args) {
super(args);
}
@Override
protected char nextMove(View view) {
int size = view.width;
String data = view.data
.replace('^', '*')
.replace('<', '*')
.replace('>', '*')
.replace('v', '*');
char[][] grid = dataToGrid(data, size);
if (data.contains("*") && isInLineOfSight(grid))
return 'f';
return switch (random.nextInt(10)) {
case 1 -> '<';
case 2 -> '>';
case 3 -> 'v';
default -> '^';
};
}
@Override
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;
}
}
+7 -8
View File
@@ -1,3 +1,5 @@
import records.Move;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
@@ -80,13 +82,13 @@ public class EscapeBot extends Bot {
while (!queue.isEmpty()) { while (!queue.isEmpty()) {
Move move = queue.poll(); Move move = queue.poll();
if (move.x < 0 || move.x >= size || move.y < 0 || move.y >= size || visited[move.x][move.y]) continue; if (move.x() < 0 || move.x() >= size || move.y() < 0 || move.y() >= size || visited[move.x()][move.y()]) continue;
visited[move.x][move.y] = true; visited[move.x()][move.y()] = true;
if (obstacles.contains("" + grid[move.x][move.y])) continue; if (obstacles.contains("" + grid[move.x()][move.y()])) continue;
if (grid[move.x][move.y] == 'o') return move.direction; if (grid[move.x()][move.y()] == 'o') return move.direction();
for (int[] direction : directions) { for (int[] direction : directions) {
queue.add(new Move(move.x + direction[0], move.y + direction[1], move.direction)); queue.add(new Move(move.x() + direction[0], move.y() + direction[1], move.direction()));
} }
} }
@@ -94,7 +96,4 @@ public class EscapeBot extends Bot {
return safeMove(grid); return safeMove(grid);
} }
protected record Move(int x, int y, char direction) {
}
} }
+80 -46
View File
@@ -1,13 +1,25 @@
import records.Move;
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 boolean offByOne = true; protected final static String players = "v^<>";
protected int currentStepCount = 0; protected final static String targets = players + "o";
protected Random random = new Random();
protected int steps = 0; protected int steps = 0;
public static void main(String[] args) { public static void main(String[] args) {
if (args.length == 0) {
String[] dummyArgs = {"localhost", "63187"};
for (int i = 0; i < 5; i++) {
new Thread(new EnemyBot(dummyArgs)).start();
}
}
Bot bot = new RumbleBot(args); Bot bot = new RumbleBot(args);
bot.run(); bot.run();
} }
@@ -18,21 +30,14 @@ public class RumbleBot extends Bot {
@Override @Override
protected char nextMove(View view) { protected char nextMove(View view) {
System.out.println();
int size = view.width; int size = view.width;
String data = view.data String data = view.data;
.replace('^', '*')
.replace('<', '*')
.replace('>', '*')
.replace('v', '*');
char[][] grid = dataToGrid(data, size); char[][] grid = dataToGrid(data, size);
if (data.contains("*")) {
if (isInLineOfSight(grid)) { if (isInLineOfSight(grid)) {
return 'f'; return 'f';
} else { } else if (data.contains("v") || data.contains("^") || data.contains("<") || data.contains(">")) {
return breadthFirstSearch(grid); return breadthFirstSearch(grid);
}
} else { } else {
return walkAround(grid); return walkAround(grid);
} }
@@ -41,78 +46,107 @@ 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++) {
grid[i % size][i / size] = data.charAt(i); char c = data.charAt(i);
if (Character.isUpperCase(c) && c != 'X') c = 'A';
grid[i % size][i / size] = c;
} }
return grid; return grid;
} }
boolean isInLineOfSight(char[][] grid) { protected void markFiringLines(char[][] grid) {
int[][] dir = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
int size = grid.length; int size = grid.length;
for (int y = size / 2; y > 0; y--) {
for (int x = 0; x < size; x++) {
for (int y = 0; y < size; y++) {
switch (grid[x][y]) {
case '^' -> markLine(grid, x, y, dir[0], '*', false);
case 'v' -> markLine(grid, x, y, dir[1], '*', false);
case '>' -> markLine(grid, x, y, dir[2], '*', false);
case '<' -> markLine(grid, x, y, dir[3], '*', false);
}
if (players.contains("" + grid[x][y])) {
for (int[] direction : dir) {
markLine(grid, x, y, direction, 'o', true);
}
}
}
}
}
private void markLine(char[][] grid, int x, int y, int[] dir, char c, boolean block) {
int size = grid.length;
x += dir[0];
y += dir[1];
while (x >= 0 && x < size && y >= 0 && y < size && !obstacles.contains("" + grid[x][y])) {
if (grid[x][y] == 'A' && block) break;
if (grid[x][y] == '.') {
grid[x][y] = c;
}
x += dir[0];
y += dir[1];
}
}
protected boolean isInLineOfSight(char[][] grid) {
int size = grid.length;
for (int y = size / 2; y >= 0; y--) {
if (players.contains("" + grid[size / 2][y]))
return true;
if (obstacles.contains("" + grid[size / 2][y])) if (obstacles.contains("" + grid[size / 2][y]))
break; break;
if (grid[size / 2][y] == '*') {
return true;
}
} }
return false; return false;
} }
protected char walkAround(char[][] grid) { protected char walkAround(char[][] grid) {
int size = grid.length;
if (steps == 0) { if (steps == 0) {
currentStepCount = (currentStepCount + 1) % 10; steps = random.nextInt(20);
if (offByOne) { return random.nextBoolean() ? '<' : '>';
currentStepCount++;
}
offByOne = !offByOne;
steps = currentStepCount;
return '>';
} else { } else {
steps--; steps--;
return safeMove(grid); return obstacles.contains("" + grid[size / 2][size / 2 - 1]) ? '<' : '^';
}
}
protected char safeMove(char[][] grid) {
int size = grid.length;
if (obstacles.contains("" + grid[size / 2][size / 2 - 1])) {
return '<';
} else {
return '^';
} }
} }
protected char breadthFirstSearch(char[][] grid) { protected char breadthFirstSearch(char[][] grid) {
markFiringLines(grid);
int size = grid.length; int size = grid.length;
int start = size / 2; int start = size / 2;
for (int y = 0; y < size; y++) {
for (char[] chars : grid) System.err.print(chars[y]);
System.err.println();
}
boolean[][] visited = new boolean[size][size]; boolean[][] visited = new boolean[size][size];
Queue<Move> queue = new LinkedList<>(); Queue<Move> queue = new LinkedList<>();
int[][] directions = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; int[][] directions = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
char[] commands = {'^', '>', '>', '<'}; char[] commands = {'^', 'v', '>', '<'};
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
queue.add(new Move(start + directions[i][0], start + directions[i][1], commands[i])); queue.add(new Move(start + directions[i][0], start + directions[i][1], commands[i]));
} }
while (!queue.isEmpty()) { while (!queue.isEmpty()) {
Move move = queue.poll(); Move move = queue.poll();
if (move.x < 0 || move.x >= size || move.y < 0 || move.y >= size || visited[move.x][move.y]) continue; if (move.x() < 0 || move.x() >= size || move.y() < 0 || move.y() >= size || visited[move.x()][move.y()]) continue;
visited[move.x][move.y] = true; visited[move.x()][move.y()] = true;
if (obstacles.contains("" + grid[move.x][move.y])) continue; if (obstacles.contains("" + grid[move.x()][move.y()])) continue;
if (grid[move.x][move.y] == '*') return move.direction; if (targets.contains("" + grid[move.x()][move.y()])) return move.direction();
for (int[] direction : directions) { for (int[] direction : directions) {
queue.add(new Move(move.x + direction[0], move.y + direction[1], move.direction)); queue.add(new Move(move.x() + direction[0], move.y() + direction[1], move.direction()));
} }
} }
System.err.println("No path found"); System.err.println("No path found");
return safeMove(grid); return walkAround(grid);
}
protected record Move(int x, int y, char direction) {
} }
} }
+18 -12
View File
@@ -1,13 +1,24 @@
import records.Move;
import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Queue; import java.util.Queue;
public class SnakeBot extends Bot { public class SnakeBot extends Bot {
protected final static String obstacles = "~#X*"; protected final static String obstacles = "~#X*";
protected final static char target = '@';
protected boolean offByOne = true; protected boolean offByOne = true;
protected int currentStepCount = 0; 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) {
String[] dummyArgs = {"localhost", "63187"};
for (int i = 0; i < 5; i++) {
new Thread(new SnakeBot(dummyArgs)).start();
}
}
Bot bot = new SnakeBot(args); Bot bot = new SnakeBot(args);
bot.run(); bot.run();
} }
@@ -72,10 +83,8 @@ 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] == '*') if (grid[x][y] == '*') leftStars++;
leftStars++; if (grid[size - x - 1][y] == '*') rightStars++;
if (grid[size - x - 1][y] == '*')
rightStars++;
} }
} }
@@ -101,13 +110,13 @@ public class SnakeBot extends Bot {
while (!queue.isEmpty()) { while (!queue.isEmpty()) {
Move move = queue.poll(); Move move = queue.poll();
if (move.x < 0 || move.x >= size || move.y < 0 || move.y >= size || visited[move.x][move.y]) continue; if (move.x() < 0 || move.x() >= size || move.y() < 0 || move.y() >= size || visited[move.x()][move.y()]) continue;
visited[move.x][move.y] = true; visited[move.x()][move.y()] = true;
if (obstacles.contains("" + grid[move.x][move.y])) continue; if (obstacles.contains("" + grid[move.x()][move.y()])) continue;
if (grid[move.x][move.y] == '@') return move.direction; if (grid[move.x()][move.y()] == target) return move.direction();
for (int[] direction : directions) { for (int[] direction : directions) {
queue.add(new Move(move.x + direction[0], move.y + direction[1], move.direction)); queue.add(new Move(move.x() + direction[0], move.y() + direction[1], move.direction()));
} }
} }
@@ -115,7 +124,4 @@ public class SnakeBot extends Bot {
return safeMove(grid); return safeMove(grid);
} }
protected record Move(int x, int y, char direction) {
}
} }
+4
View File
@@ -0,0 +1,4 @@
package records;
public record Move(int x, int y, char direction) {
}