programmieren-projekt/src/AiPlayer.java

27 lines
944 B
Java

import java.util.Random;
public abstract class AiPlayer extends LocalPlayer {
public AiPlayer() {
this.setName("AI Player");
}
public Point RandomPoint() {
Random random = new Random(); // Pseudo Random für zufallszahlen
int posx = random.nextInt(super.board.getSize()); // Generiert 0 - 13
int posy = random.nextInt(super.board.getSize()); //
return new Point(posx,posy);
}
public void AiSetShips() {
for(int i = 0; i < super.board.getShips().size(); i++) { // Interiert durch alle Shiffe
//TODO: set horizontal
while(!super.board.getShips().get(i).setPosition(RandomPoint(), true, super.board.getShips(), super.board.getSize())) {}
} // Versucht das Aktuelle Shiff zu setzten und wiederholt solange bis es funktioniert
return;
}
public void AiShoot() {
super.board.hit(RandomPoint());
return;
}
}