Compare commits

..

2 Commits

Author SHA1 Message Date
Tim
20d45ce4ca snake und bot 2025-02-11 14:10:09 +01:00
Tim
d0ae96def8 Crapy rumble bot 2025-02-11 14:07:15 +01:00
22 changed files with 74 additions and 268 deletions

8
.idea/.gitignore generated vendored
View File

@ -1,8 +0,0 @@
# 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
View File

@ -1,6 +0,0 @@
<?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
View File

@ -1,8 +0,0 @@
<?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
View File

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

View File

@ -1,11 +0,0 @@
<?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

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

View File

@ -1,6 +0,0 @@
<?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

@ -1,8 +0,0 @@
<?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>

View File

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

View File

@ -1,11 +0,0 @@
<?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

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

View File

@ -1,49 +0,0 @@
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;
}
}

View File

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

View File

@ -1,31 +0,0 @@
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;
}
}