Compare commits
8 Commits
7e5d807862
...
f3d09aabb6
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f3d09aabb6 | ||
![]() |
0bcdabe75e | ||
![]() |
3744c8232e | ||
![]() |
f98c5a1295 | ||
![]() |
c9a3937a12 | ||
![]() |
0410084441 | ||
![]() |
475e5c1c5d | ||
![]() |
5fc6cb8216 |
124
.idea/uiDesigner.xml
generated
Normal file
124
.idea/uiDesigner.xml
generated
Normal 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>
|
11
src/Bot.java
11
src/Bot.java
@ -5,7 +5,7 @@ import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
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
|
||||
// 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
|
||||
// Kommunikation mit dem Server. Die Methode wird von der main-Methode
|
||||
// aufgerufen.
|
||||
protected void run() {
|
||||
public void run() {
|
||||
try (Socket socket = new Socket()) {
|
||||
socket.connect(new InetSocketAddress(host, port));
|
||||
OutputStream out = socket.getOutputStream();
|
||||
@ -32,19 +32,22 @@ public abstract class Bot {
|
||||
View view = new View();
|
||||
while (true) {
|
||||
view.read(in);
|
||||
view.print();
|
||||
print(view);
|
||||
try {
|
||||
char ch = nextMove(view);
|
||||
out.write(ch);
|
||||
}
|
||||
catch (Exception e) { break; }
|
||||
}
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected void print(View view) {
|
||||
view.print();
|
||||
}
|
||||
|
||||
// Diese Methode ermittelt den nächsten Zug des Bots. Sie wird von der
|
||||
// run-Methode aufgerufen, nachdem der Server das Spielfeld gesendet hat.
|
||||
// Subklassen müssen diese Methode implementieren.
|
||||
|
@ -3,21 +3,30 @@ 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)) {
|
||||
String data = view.data
|
||||
.replace('^', '*')
|
||||
.replace('<', '*')
|
||||
.replace('>', '*')
|
||||
.replace('v', '*');
|
||||
|
||||
if (data.contains("*") && random.nextFloat() < 0.8)
|
||||
return 'f';
|
||||
|
||||
return switch (random.nextInt(10)) {
|
||||
case 1 -> '<';
|
||||
case 2 -> '>';
|
||||
case 3 -> 'v';
|
||||
default -> '^';
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void print(View view) {
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,18 @@ import java.util.LinkedList;
|
||||
import java.util.Queue;
|
||||
|
||||
public class RumbleBot extends Bot {
|
||||
protected final static String obstacles = "~#X";
|
||||
protected final static String obstacles = "~#X*";
|
||||
protected final static String targets = "v^<>";
|
||||
protected boolean offByOne = true;
|
||||
protected int currentStepCount = 0;
|
||||
protected int steps = 0;
|
||||
|
||||
public static void main(String[] args) {
|
||||
if(args.length == 0) {
|
||||
DummyBot dummy = new DummyBot(args);
|
||||
new Thread(dummy).start();
|
||||
}
|
||||
|
||||
Bot bot = new RumbleBot(args);
|
||||
bot.run();
|
||||
}
|
||||
@ -19,15 +25,12 @@ public class RumbleBot extends Bot {
|
||||
@Override
|
||||
protected char nextMove(View view) {
|
||||
System.out.println();
|
||||
|
||||
int size = view.width;
|
||||
String data = view.data
|
||||
.replace('^', '*')
|
||||
.replace('<', '*')
|
||||
.replace('>', '*')
|
||||
.replace('v', '*');
|
||||
String data = view.data;
|
||||
char[][] grid = dataToGrid(data, size);
|
||||
|
||||
if (data.contains("*")) {
|
||||
if (data.contains("v") || data.contains("^") || data.contains("<") || data.contains(">")) {
|
||||
if (isInLineOfSight(grid)) {
|
||||
return 'f';
|
||||
} else {
|
||||
@ -43,18 +46,21 @@ public class RumbleBot extends Bot {
|
||||
for (int i = 0; i < data.length(); i++) {
|
||||
grid[i % size][i / size] = data.charAt(i);
|
||||
}
|
||||
return markFiringLines(grid);
|
||||
}
|
||||
|
||||
protected char[][] markFiringLines(char[][] grid) {
|
||||
return grid;
|
||||
}
|
||||
|
||||
boolean isInLineOfSight(char[][] grid) {
|
||||
protected boolean isInLineOfSight(char[][] grid) {
|
||||
int size = grid.length;
|
||||
for (int y = size / 2; y > 0; y--) {
|
||||
if (obstacles.contains("" + grid[size / 2][y]))
|
||||
break;
|
||||
|
||||
if (grid[size / 2][y] == '*') {
|
||||
if (targets.contains("" + grid[size / 2][y]))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -91,7 +97,7 @@ public class RumbleBot extends Bot {
|
||||
Queue<Move> queue = new LinkedList<>();
|
||||
|
||||
int[][] directions = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
|
||||
char[] commands = {'^', '>', '>', '<'};
|
||||
char[] commands = {'^', 'v', '>', '<'};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
queue.add(new Move(start + directions[i][0], start + directions[i][1], commands[i]));
|
||||
}
|
||||
@ -101,7 +107,7 @@ public class RumbleBot extends Bot {
|
||||
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;
|
||||
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) {
|
||||
queue.add(new Move(move.x + direction[0], move.y + direction[1], move.direction));
|
||||
|
Loading…
x
Reference in New Issue
Block a user