Compare commits

..

6 Commits

Author SHA1 Message Date
Tim
14e77646ff src gelöscht 2025-02-12 11:30:44 +01:00
Tim
946e029c3f src gelöscht 2025-02-12 11:29:26 +01:00
Elias
4372c2a991 testing RumbleBot 2025-02-11 14:08:44 +01:00
Elias
e4dc5ec815 updated comments 2025-02-09 19:45:26 +01:00
Elias
0d6feebb8e Scuffed SnakeBot Solution 2025-02-09 19:17:36 +01:00
Elias
ac45ada088 Initial Commit 2024-11-27 13:13:05 +01:00
22 changed files with 268 additions and 74 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

6
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/ProgA-Bot.iml" filepath="$PROJECT_DIR$/ProgA-Bot.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

11
ProgA-Bot.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
out/production/ProgA-Bot/.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

6
out/production/ProgA-Bot/.idea/misc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/ProgA-Bot.iml" filepath="$PROJECT_DIR$/ProgA-Bot.iml" />
</modules>
</component>
</project>

6
out/production/ProgA-Bot/.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,3 @@
# ProgA-Bot
Jeder erstellt seinen eigenen Branch und wir mergen am ende das was am besten funktioniert

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

49
src/EscapeBot.java Normal file
View File

@ -0,0 +1,49 @@
package src;
public class EscapeBot extends Bot {
int stepCounter = 0;
int turnCount = 0;
int viewRange = 5;
int straightLength = 1;
protected EscapeBot(String[] args) {
super(args);
}
public static void main(String[] args) {
EscapeBot bot = new EscapeBot(args);
bot.run();
}
@Override
protected char nextMove(View view) throws Exception {
if (!view.data.contains("o")) {
if (turnCount == 2) {
turnCount = 0;
straightLength++;
}
if (stepCounter < straightLength * viewRange) {
stepCounter++;
return '^';
} else {
stepCounter = 0;
turnCount++;
return '>';
}
} else {
if (view.data.substring(0, 10).contains("o")) {
return '^';
} else if (view.data.substring(10, 12).contains("o")) {
return '<';
} else if (view.data.substring(13, 15).contains("o")) {
return '>';
} else if (view.data.substring(15, 25).contains("o")) {
return 'v';
}
}
return 0;
}
}

34
src/ManualBot.java Normal file
View File

@ -0,0 +1,34 @@
package src;
import java.util.Scanner;
public class ManualBot extends Bot {
Scanner scanner = new Scanner(System.in);
protected ManualBot(String[] args) {
super(args);
}
public static void main(String[] args) {
ManualBot bot = new ManualBot(args);
bot.run();
}
@Override
protected char nextMove(View view) throws Exception {
char ch = 0;
if (scanner.hasNextLine()) {
ch = scanner.nextLine().toCharArray()[0];
}
return switch (ch) {
case 'w' -> '^';
case 's' -> 'v';
case 'a' -> '<';
case 'd' -> '>';
case 'q' -> throw new Exception();
default -> 'l';
};
}
}

View File

@ -1,10 +1,18 @@
package src; package src;
public class RumbleBot extends Bot { public class RumbleBot extends Bot{
int stepCounter = 0;
int turnCount = 0;
int viewRange = 30; String[] playerChars = {"<",">","^","v"};
int straightLength = 1; int angle = 0;
int x = 0;
int y = 0;
boolean left = false;
boolean right = false;
boolean up = false;
boolean down = false;
int turnCounter = 0;
int waitTimer = 80;
protected RumbleBot(String[] args) { protected RumbleBot(String[] args) {
super(args); super(args);
@ -15,79 +23,70 @@ public class RumbleBot extends Bot {
bot.run(); bot.run();
} }
@Override protected char nextMove(View view){
protected char nextMove(View view) throws Exception {
// Definition der gegnerischen Symbole
String enemySymbols = "<>v^";
// Annahme: Sichtfeld ist 9x9, der Bot steht immer in der Mitte (Zeile 4, Spalte 4) if(waitTimer > 0){
final int gridSize = 9; waitTimer--;
final int centerRow = gridSize / 2; // 4 return 0;
final int centerCol = gridSize / 2; // 4 }
//back away if possible
// 1. Prüfe, ob sich ein Gegner in der direkten Schusslinie befindet. if(playerAhead(view) && !view.data.substring(49,50).contains("X")){
// Dabei werden die Zellen in der zentralen Spalte oberhalb des Bots untersucht (Reihen 0 bis 3). return 'v';
for (int row = 0; row < centerRow; row++) { }
int index = row * gridSize + centerCol; //shoot target
char cell = view.data.charAt(index); if(playerAhead(view)){
if (enemySymbols.indexOf(cell) != -1) { return 'f';
// Ein Gegner befindet sich direkt vor dem Bot feuere!
return 'f';
}
} }
// 2. Falls kein Gegner in der Schusslinie ist, prüfe, ob überhaupt ein Gegner sichtbar ist. if(view.data.substring(39,40).contains("X") && view.data.substring(49,50).contains("X")){
// Wenn keiner der gegnerischen Symbole im Sichtfeld vorkommt, folgt das Standard-Bewegungsmuster. return '^';
if (view.data.indexOf('<') == -1 && }else turnRight();
view.data.indexOf('>') == -1 && // if (x <= 15 && !up){
view.data.indexOf('^') == -1 && // x++;
view.data.indexOf('v') == -1) { // return '^';
// Kein Gegner im Sichtfeld bewege dich gemäß dem Bewegungsmuster: // }else if(angle != 180){
if (turnCount == 2) { // up = true;
turnCount = 0; // return turnRight();
straightLength++; // }else if (x >= -15 && !down){
} // x--;
if (stepCounter < straightLength * viewRange) { // return '^';
stepCounter++; // } else if (angle != 0) {
return '^'; // down = true;
} else { // return turnRight();
stepCounter = 0; // }else if (x < 0){
turnCount++; // x++;
return '>'; // return '^';
} // } else if (angle != 90 && x == 0) {
} // return turnRight();
// } else if (y <= 15 && !right) {
// 3. Es ist ein Gegner sichtbar, allerdings nicht direkt in der Schusslinie. // y++;
// Bestimme, ob der Gegner eher links oder rechts liegt, und drehe in die entsprechende Richtung, // return '^';
// um den Gegner in Zukunft in die Schusslinie zu bekommen. // } else if (angle != 270) {
boolean enemyOnLeft = false; // right = true;
boolean enemyOnRight = false; // return turnRight();
// } else if(y >= -15 && !left){
// Untersuche dazu alle Zellen des Sichtfelds: // y--;
for (int row = 0; row < gridSize; row++) { // return '^';
for (int col = 0; col < gridSize; col++) { // }else if(angle != 90){
int index = row * gridSize + col; // turnRight();
char cell = view.data.charAt(index); // }else if (y > 0){
if (enemySymbols.indexOf(cell) != -1) { // y++;
// Vergleiche die Spalte der Zelle mit der Mitte (centerCol) // return '^';
if (col < centerCol) { // }
enemyOnLeft = true; return 0;
} else if (col > centerCol) {
enemyOnRight = true;
}
}
}
}
if (enemyOnLeft) {
return '<';
} else if (enemyOnRight) {
return '>';
}
// Sollte zwar ein Gegner sichtbar sein, aber weder links noch rechts als Fallback fahre vorwärts.
return '^';
} }
private boolean playerAhead(View view){
for (String s : playerChars){
if(view.data.substring(4,5).contains(s) || view.data.substring(43,45).contains(s)){
return true;
}
}
return false;
}
private char turnRight(){
angle = (angle + 90) % 360;
return '>';
}
} }

31
src/test.java Normal file
View File

@ -0,0 +1,31 @@
package src;
public class test extends Bot{
String[] playerChars = {"<",">","^","v"};
protected test(String[] args) {
super(args);
}
public static void main(String[] args) {
test bot = new test(args);
bot.run();
}
protected char nextMove(View view){
if(playerAhead(view)){
return 'f';
}
return '>';
}
private boolean playerAhead(View view){
for (String s : playerChars){
if(view.data.substring(4,5).contains(s) || view.data.substring(13,14).contains(s)){
return true;
}
}
return false;
}
}