Escape, Snake aufgeräumt + RumbleBot fertig
This commit is contained in:
parent
fc9c8c6695
commit
f66359ec72
@ -1,13 +1,12 @@
|
||||
public class EscapeBot extends Bot {
|
||||
|
||||
//Rechts,Unten,Links,Oben
|
||||
enum Direction {
|
||||
Right,
|
||||
Down,
|
||||
Left,
|
||||
Up
|
||||
}
|
||||
//5 nach rechts, 5 nach unten, 10 nach links, 10 hoch, 15 nach rechts und 15 nach unten
|
||||
|
||||
int[] dx = {3,0,6,0};
|
||||
int[] dy = {0,3,0,6};
|
||||
char[] Commands = {'>','v','<','^'};
|
||||
@ -17,7 +16,7 @@ public class EscapeBot extends Bot {
|
||||
int NextIncrement = StepsToGoUntilNextEvaluation *2;
|
||||
boolean first_time = true;
|
||||
public EscapeBot(String[] args) {
|
||||
super(args); // Konstruktor von Elternklasse Bot
|
||||
super(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,24 +28,21 @@ public class EscapeBot extends Bot {
|
||||
if(first_time) {
|
||||
first_time = false ;
|
||||
return this.Commands[Direction.Right.ordinal()];
|
||||
|
||||
}
|
||||
if(-1 != rocketIndex) {
|
||||
|
||||
if (-1 != rocketIndex) {
|
||||
Y_Rocket = rocketIndex / view.width;
|
||||
X_Rocket = rocketIndex % view.width;
|
||||
|
||||
//System.out.println("X_Rocket: " + X_Rocket + " Y_Rocket: " + Y_Rocket);
|
||||
|
||||
if(2 != Y_Rocket) {
|
||||
if (2 != Y_Rocket) {
|
||||
return (2 > Y_Rocket ) ? this.Commands[Direction.Up.ordinal()] : this.Commands[Direction.Down.ordinal()];
|
||||
}
|
||||
|
||||
if(X_Rocket != 2) {
|
||||
return (2>X_Rocket) ? this.Commands[Direction.Left.ordinal()] : this.Commands[Direction.Right.ordinal()];
|
||||
if (X_Rocket != 2) {
|
||||
return (2 > X_Rocket) ? this.Commands[Direction.Left.ordinal()] : this.Commands[Direction.Right.ordinal()];
|
||||
}
|
||||
}
|
||||
else if(0 < this.StepsToGoUntilNextEvaluation) {
|
||||
//System.out.println("CurrentDirection:" + this.CurrentDirection.toString() + " StepsToGo: " + this.StepsToGoUntilNextEvaluation);
|
||||
else if (0 < this.StepsToGoUntilNextEvaluation) {
|
||||
StepsToGoUntilNextEvaluation--;
|
||||
return this.Commands[Direction.Up.ordinal()];
|
||||
}
|
||||
@ -73,12 +69,12 @@ public class EscapeBot extends Bot {
|
||||
StepsToGoUntilNextEvaluation = this.dx[Direction.Right.ordinal()];
|
||||
break;
|
||||
}
|
||||
|
||||
this.Start = StepsToGoUntilNextEvaluation;
|
||||
return this.Commands[Direction.Right.ordinal()];
|
||||
}
|
||||
|
||||
throw new Exception("This Line should not be reacher!!");
|
||||
|
||||
throw new Exception("This Line should not be reached!");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
88
src/RumbleBot.java
Normal file
88
src/RumbleBot.java
Normal file
@ -0,0 +1,88 @@
|
||||
public class RumbleBot extends Bot {
|
||||
|
||||
//Rechts,Unten,Links,Oben
|
||||
enum Direction {
|
||||
Right,
|
||||
Down,
|
||||
Left,
|
||||
Up
|
||||
}
|
||||
int[] dx = {3,0,6,0};
|
||||
int[] dy = {0,3,0,6};
|
||||
char[] Commands = {'>','v','<','^'};
|
||||
Direction CurrentDirection = Direction.Right;
|
||||
int StepsToGoUntilNextEvaluation = 3;
|
||||
int Start = StepsToGoUntilNextEvaluation;
|
||||
int NextIncrement = StepsToGoUntilNextEvaluation *2;
|
||||
char[] Enemies = {'>','v','<','^'};
|
||||
boolean first_time = true;
|
||||
public RumbleBot(String[] args) {
|
||||
super(args);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected char nextMove(View view) throws Exception {
|
||||
for (char enemy : Enemies) {
|
||||
int enemyIndex = view.data.indexOf(enemy);
|
||||
if (-1 != enemyIndex) {
|
||||
//System.out.println("Gefunden: " + enemy + " bei Index " + enemyIndex);
|
||||
|
||||
int Y_Enemy = enemyIndex / view.width;
|
||||
int X_Enemy = enemyIndex % view.width;
|
||||
|
||||
if(4 != Y_Enemy) {
|
||||
return (4 > Y_Enemy ) ? 'f' : this.Commands[Direction.Down.ordinal()];
|
||||
//return (4 > Y_Enemy ) ? this.Commands[Direction.Up.ordinal()] : this.Commands[Direction.Down.ordinal()];
|
||||
}
|
||||
|
||||
if(X_Enemy != 4) {
|
||||
return (4 > X_Enemy) ? 'f' : this.Commands[Direction.Right.ordinal()];
|
||||
//return (4 > X_Enemy) ? this.Commands[Direction.Left.ordinal()] : this.Commands[Direction.Right.ordinal()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(first_time) {
|
||||
first_time = false ;
|
||||
return this.Commands[Direction.Right.ordinal()];
|
||||
}
|
||||
|
||||
else if(0 < this.StepsToGoUntilNextEvaluation) {
|
||||
StepsToGoUntilNextEvaluation--;
|
||||
return this.Commands[Direction.Up.ordinal()];
|
||||
}
|
||||
else if (0 == this.StepsToGoUntilNextEvaluation){
|
||||
switch(this.CurrentDirection) {
|
||||
case Direction.Right:
|
||||
dx[Direction.Right.ordinal()]+= this.NextIncrement;
|
||||
this.CurrentDirection = Direction.Down;
|
||||
StepsToGoUntilNextEvaluation = this.dy[Direction.Down.ordinal()];
|
||||
break;
|
||||
case Direction.Down:
|
||||
dy[Direction.Down.ordinal()] += this.NextIncrement;
|
||||
this.CurrentDirection = Direction.Left;
|
||||
StepsToGoUntilNextEvaluation = this.dx[Direction.Left.ordinal()];
|
||||
break;
|
||||
case Direction.Left:
|
||||
dx[Direction.Left.ordinal()] += this.NextIncrement;
|
||||
this.CurrentDirection = Direction.Up;
|
||||
StepsToGoUntilNextEvaluation = this.dy[Direction.Up.ordinal()];
|
||||
break;
|
||||
case Direction.Up:
|
||||
dy[Direction.Up.ordinal()] += this.NextIncrement;
|
||||
this.CurrentDirection = Direction.Right;
|
||||
StepsToGoUntilNextEvaluation = this.dx[Direction.Right.ordinal()];
|
||||
break;
|
||||
}
|
||||
this.Start = StepsToGoUntilNextEvaluation;
|
||||
return this.Commands[Direction.Right.ordinal()];
|
||||
}
|
||||
|
||||
throw new Exception("This Line should not be reached!");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
RumbleBot rumbleBot = new RumbleBot(args);
|
||||
rumbleBot.run();
|
||||
}
|
||||
}
|
@ -4,8 +4,8 @@ import java.awt.Point;
|
||||
|
||||
public class SnakeBot extends Bot {
|
||||
|
||||
List<Point> tail = new ArrayList<>(); // speichert Positionen der Schlange
|
||||
Point currentPos = new Point(2, 2); // Startposition des Bots
|
||||
List<Point> tail = new ArrayList<>();
|
||||
Point currentPos = new Point(2, 2);
|
||||
|
||||
public SnakeBot(String[] args) {
|
||||
super(args);
|
||||
@ -41,7 +41,7 @@ public class SnakeBot extends Bot {
|
||||
return safeDirection(null); // falls gefährlich, neue Richtung wählen
|
||||
}
|
||||
|
||||
// Erst aktualisieren, wenn sichergestellt ist, dass die Bewegung sicher ist
|
||||
// Erst aktualisieren, wenn sichergestellt ist, dass Bewegung sicher ist
|
||||
currentPos.setLocation(newX, newY);
|
||||
tail.add(new Point(newX, newY));
|
||||
return direction;
|
||||
|
Loading…
x
Reference in New Issue
Block a user