1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package praktikum05;
-
- import java.util.Random;
-
- public class RumbleBot extends Bot {
-
- public static void main(String[] args) {
- RumbleBot rumbleBot = new RumbleBot(args);
- rumbleBot.run();
- }
-
- protected RumbleBot(String[] args) {
- super(args);
- }
-
- @Override
- protected char nextMove(View view) throws Exception {
- if (view.data.indexOf('*') > -1) {
- return shootIfEnemyInRange(view);
- } else {
- return moveRandomly();
- }
- }
-
- protected char moveRandomly() {
- Random random = new Random();
- int randomDirection = random.nextInt(4);
-
- switch (randomDirection) {
- case 0:
- return '^'; // Vorwärts
- case 1:
- return 'v'; // Rückwärts
- case 2:
- return '<'; // Linksdrehung
- case 3:
- return '>'; // Rechtsdrehung
- default:
- return 'q'; // Abbruch der Verbindung
- }
- }
-
- protected char shootIfEnemyInRange(View view) {
- int positionEnemy = view.data.indexOf('B');
- int positionRover = view.data.indexOf('A');
-
- // Überprüfen, ob der Feind in derselben Zeile istdocker run --rm -p 63187:63187 mediaeng/bots escape
- if (positionRover / 5 == positionEnemy / 5) {
- return 'f'; // Feuerbefehl
- }
-
- // Ansonsten zufällig bewegen
- return moveRandomly();
- }
- }
|