SnakeBot fertig
This commit is contained in:
parent
9de3f327e5
commit
4332f7d10a
BIN
out/production/Prog3/Praktikum05/SnakeBot.class
Normal file
BIN
out/production/Prog3/Praktikum05/SnakeBot.class
Normal file
Binary file not shown.
@ -13,59 +13,83 @@ public class SnakeBot extends Bot {
|
|||||||
public int counter = 0;
|
public int counter = 0;
|
||||||
private Random leftOrRight = new Random();
|
private Random leftOrRight = new Random();
|
||||||
@Override
|
@Override
|
||||||
protected char nextMove(View view) throws Exception{
|
protected char nextMove(View view) throws Exception {
|
||||||
boolean exit = false;
|
boolean exit = false;
|
||||||
while(!exit){
|
while (!exit) {
|
||||||
System.out.println(counter);
|
|
||||||
int rockPosition = findNextRock(view);
|
int rockPosition = findNextRock(view);
|
||||||
if(rockPosition != -1){
|
if (rockPosition != -1) {
|
||||||
testForWagon(view);
|
System.out.println(counter + "| RockPosition: " + rockPosition);
|
||||||
return determineNextStep(rockPosition);
|
return testForWagon(view, rockPosition);
|
||||||
}else{
|
} else {
|
||||||
testForWagon(view);
|
|
||||||
++counter;
|
++counter;
|
||||||
if (counter < 8)
|
if (counter < 8)
|
||||||
return '^';
|
return testForWagon(view, rockPosition);
|
||||||
else{
|
else {
|
||||||
if(leftOrRight.nextBoolean() == true) {
|
if (view.data.charAt(10) == '*' || view.data.charAt(11) == '*') {
|
||||||
counter = 0;
|
|
||||||
return '<';
|
|
||||||
}else {
|
|
||||||
counter = 0;
|
counter = 0;
|
||||||
return '>';
|
return '>';
|
||||||
|
} else if (view.data.charAt(13) == '*' || view.data.charAt(14) == '*') {
|
||||||
|
counter = 0;
|
||||||
|
return '<';
|
||||||
|
}else{
|
||||||
|
if(leftOrRight.nextBoolean() == true) {
|
||||||
|
counter = 0;
|
||||||
|
return '<';
|
||||||
|
}else {
|
||||||
|
counter = 0;
|
||||||
|
return '>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Exception("Beendet");
|
throw new Exception("Quit");
|
||||||
}
|
}
|
||||||
|
|
||||||
private char determineNextStep(int rockPosition) {
|
|
||||||
|
private char determineNextStep(int rockPosition,View view) {
|
||||||
if (rockPosition < 10)
|
if (rockPosition < 10)
|
||||||
return '^';
|
return '^';
|
||||||
else if(rockPosition == 13 || rockPosition == 14 || rockPosition == 18 || rockPosition == 19 || rockPosition == 23 || rockPosition == 24)
|
else if(rockPosition == 13 || rockPosition == 14 || rockPosition == 18 || rockPosition == 19 || rockPosition == 23 || rockPosition == 24 && !(view.data.charAt(13) != '*' && view.data.charAt(14) != '*'))
|
||||||
return '>';
|
return '>';
|
||||||
else if(rockPosition == 10 || rockPosition == 11 || rockPosition == 15 || rockPosition == 16 || rockPosition == 20 || rockPosition == 21)
|
else if((rockPosition == 10 || rockPosition == 11 || rockPosition == 15 || rockPosition == 16 || rockPosition == 20 || rockPosition == 21) && !(view.data.charAt(10) != '*' && view.data.charAt(11) != '*'))
|
||||||
return '<';
|
return '<';
|
||||||
else return 0;
|
else return '^';
|
||||||
}
|
}
|
||||||
|
|
||||||
private int findNextRock(View view) {
|
private int findNextRock(View view) {
|
||||||
return view.data.indexOf('@');
|
return view.data.indexOf('@');
|
||||||
}
|
}
|
||||||
// test funktioniert nicht muss angepasst werden vielleicht als boolean oder so
|
|
||||||
private char testForWagon(View view){
|
private char testForWagon(View view, int rP){
|
||||||
|
char move = ' ';
|
||||||
if (view.data.charAt(7) == '*'){
|
if (view.data.charAt(7) == '*'){
|
||||||
if (view.data.charAt(11) != '*') {
|
if(view.data.charAt(11) == '*' || view.data.charAt(13) == '*'){
|
||||||
return '<';
|
if(view.data.charAt(11) == '*' || view.data.charAt(10) == '*'){
|
||||||
}else {
|
|
||||||
if (view.data.charAt(13) == '*') {
|
|
||||||
return 'V';
|
|
||||||
} else {
|
|
||||||
return '>';
|
return '>';
|
||||||
|
}else if(view.data.charAt(13) == '*' || view.data.charAt(14) == '*'){
|
||||||
|
return '<';
|
||||||
|
}
|
||||||
|
}else if(view.data.charAt(11) != '*' && view.data.charAt(13) != '*'){
|
||||||
|
if(view.data.charAt(8) == '*' || view.data.charAt(9) == '*'){
|
||||||
|
if(view.data.charAt(10) == '*'){
|
||||||
|
return '>';
|
||||||
|
}else if(view.data.charAt(14) == '*'){
|
||||||
|
return '<';
|
||||||
|
}
|
||||||
|
}else if(view.data.charAt(5) == '+' || view.data.charAt(6) == '*'){
|
||||||
|
if(view.data.charAt(10) == '*'){
|
||||||
|
return '>';
|
||||||
|
}else if(view.data.charAt(14) == '*'){
|
||||||
|
return '<';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else return 0;
|
}else{
|
||||||
|
move = determineNextStep(rP, view);
|
||||||
|
}
|
||||||
|
System.out.println(move);
|
||||||
|
return move;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String args[]){
|
public static void main(String args[]){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user