SnakeBot implementiert
testForWagon Fehlerhaft wird noch überprüft
This commit is contained in:
parent
00796bed61
commit
9de3f327e5
BIN
out/production/Prog3/Praktikum05/Bot$View.class
Normal file
BIN
out/production/Prog3/Praktikum05/Bot$View.class
Normal file
Binary file not shown.
BIN
out/production/Prog3/Praktikum05/Bot.class
Normal file
BIN
out/production/Prog3/Praktikum05/Bot.class
Normal file
Binary file not shown.
BIN
out/production/Prog3/Praktikum05/EscapeBot.class
Normal file
BIN
out/production/Prog3/Praktikum05/EscapeBot.class
Normal file
Binary file not shown.
BIN
out/production/Prog3/Praktikum05/ManualBot.class
Normal file
BIN
out/production/Prog3/Praktikum05/ManualBot.class
Normal file
Binary file not shown.
@ -1,20 +1,40 @@
|
|||||||
package Praktikum05;
|
package Praktikum05;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class EscapeBot extends Bot{
|
public class EscapeBot extends Bot{
|
||||||
protected EscapeBot(String args[]){
|
protected EscapeBot(String args[]){
|
||||||
super(args);
|
super(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Random schritte = new Random();
|
||||||
|
|
||||||
|
private int s = 5;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected char nextMove(View view) throws Exception {
|
protected char nextMove(View view) throws Exception {
|
||||||
|
boolean exit = false;
|
||||||
|
while(!exit){
|
||||||
|
/*if(view.data.contains("o")){
|
||||||
|
|
||||||
|
}*/
|
||||||
|
if(s == 5){
|
||||||
|
for(int i = 1; i == s; i++ ){
|
||||||
|
return '^';
|
||||||
|
}
|
||||||
|
boolean turn = schritte.nextBoolean();
|
||||||
|
if(turn == true){
|
||||||
|
return '<';
|
||||||
|
}else{
|
||||||
|
return '>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
throw new Exception("Quit");
|
throw new Exception("Quit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String args[]){
|
public static void main(String args[]){
|
||||||
Bot ebot = new EscapeBot(args);
|
Bot ebot = new EscapeBot(args);
|
||||||
ebot.run();
|
ebot.run();
|
||||||
|
@ -28,7 +28,7 @@ public class ManualBot extends Bot {
|
|||||||
case "d":
|
case "d":
|
||||||
return '>';
|
return '>';
|
||||||
case "q":
|
case "q":
|
||||||
exit = true;
|
command = null;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
System.out.println("Kommando nicht verfügbar bitte einen anderes Kommando eingeben");
|
System.out.println("Kommando nicht verfügbar bitte einen anderes Kommando eingeben");
|
||||||
|
75
src/Praktikum05/SnakeBot.java
Normal file
75
src/Praktikum05/SnakeBot.java
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
package Praktikum05;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class SnakeBot extends Bot {
|
||||||
|
|
||||||
|
|
||||||
|
protected SnakeBot(String[] args) {
|
||||||
|
super(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int counter = 0;
|
||||||
|
private Random leftOrRight = new Random();
|
||||||
|
@Override
|
||||||
|
protected char nextMove(View view) throws Exception{
|
||||||
|
boolean exit = false;
|
||||||
|
while(!exit){
|
||||||
|
System.out.println(counter);
|
||||||
|
int rockPosition = findNextRock(view);
|
||||||
|
if(rockPosition != -1){
|
||||||
|
testForWagon(view);
|
||||||
|
return determineNextStep(rockPosition);
|
||||||
|
}else{
|
||||||
|
testForWagon(view);
|
||||||
|
++counter;
|
||||||
|
if (counter < 8)
|
||||||
|
return '^';
|
||||||
|
else{
|
||||||
|
if(leftOrRight.nextBoolean() == true) {
|
||||||
|
counter = 0;
|
||||||
|
return '<';
|
||||||
|
}else {
|
||||||
|
counter = 0;
|
||||||
|
return '>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Exception("Beendet");
|
||||||
|
}
|
||||||
|
|
||||||
|
private char determineNextStep(int rockPosition) {
|
||||||
|
if (rockPosition < 10)
|
||||||
|
return '^';
|
||||||
|
else if(rockPosition == 13 || rockPosition == 14 || rockPosition == 18 || rockPosition == 19 || rockPosition == 23 || rockPosition == 24)
|
||||||
|
return '>';
|
||||||
|
else if(rockPosition == 10 || rockPosition == 11 || rockPosition == 15 || rockPosition == 16 || rockPosition == 20 || rockPosition == 21)
|
||||||
|
return '<';
|
||||||
|
else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int findNextRock(View view) {
|
||||||
|
return view.data.indexOf('@');
|
||||||
|
}
|
||||||
|
// test funktioniert nicht muss angepasst werden vielleicht als boolean oder so
|
||||||
|
private char testForWagon(View view){
|
||||||
|
if (view.data.charAt(7) == '*'){
|
||||||
|
if (view.data.charAt(11) != '*') {
|
||||||
|
return '<';
|
||||||
|
}else {
|
||||||
|
if (view.data.charAt(13) == '*') {
|
||||||
|
return 'V';
|
||||||
|
} else {
|
||||||
|
return '>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String args[]){
|
||||||
|
Bot sbot = new SnakeBot(args);
|
||||||
|
sbot.run();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user