Update AI.java
Joker-Funktionalität
This commit is contained in:
parent
efa26657ba
commit
f2d1105344
1 changed files with 65 additions and 0 deletions
|
|
@ -3,6 +3,15 @@ package game;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import base.Edge;
|
||||||
|
import game.map.Castle;
|
||||||
|
import game.map.GameMap;
|
||||||
|
import gui.components.JokerPanel.JokerTypes;
|
||||||
|
|
||||||
|
|
||||||
public abstract class AI extends Player {
|
public abstract class AI extends Player {
|
||||||
|
|
||||||
private AIThread aiThread;
|
private AIThread aiThread;
|
||||||
|
|
@ -40,6 +49,62 @@ public abstract class AI extends Player {
|
||||||
Thread.sleep(10);
|
Thread.sleep(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void playTroopsJoker() {
|
||||||
|
if(getJokers()[0] == JokerTypes.ADD_TROOPS_USED)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.addTroops(5);
|
||||||
|
this.setJoker(0, JokerTypes.ADD_TROOPS_USED);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void playScareJoker(Castle scared, Game game) {
|
||||||
|
if(getJokers()[1] == JokerTypes.SCARE_TROOPS_USED)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Verscheuchen-Joker
|
||||||
|
if(scared == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
GameMap map = game.getMap();
|
||||||
|
List<Edge<Castle>> castleEdges = map.getEdges();
|
||||||
|
List<Castle> adjacentCastles = new ArrayList<>();
|
||||||
|
for(Edge<Castle> edge : castleEdges) {
|
||||||
|
if(edge.getNodeA().getValue().equals(scared)) {
|
||||||
|
if(edge.getNodeB().getValue().getOwner() != game.getCurrentPlayer() && !edge.getNodeB().getValue().equals(scared)) {
|
||||||
|
adjacentCastles.add(edge.getNodeB().getValue());
|
||||||
|
}
|
||||||
|
} else if(edge.getNodeB().getValue().equals(scared)) {
|
||||||
|
if(edge.getNodeA().getValue().getOwner() != game.getCurrentPlayer() && !edge.getNodeA().getValue().equals(scared)) {
|
||||||
|
adjacentCastles.add(edge.getNodeA().getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int troopsToDistribute = scared.getTroopCount() - 1;
|
||||||
|
System.out.println(troopsToDistribute);
|
||||||
|
scared.removeTroops(troopsToDistribute);
|
||||||
|
System.out.println(adjacentCastles.size());
|
||||||
|
for(Castle c : adjacentCastles) {
|
||||||
|
System.out.print(c.getName() + " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(adjacentCastles.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Random random = new Random();
|
||||||
|
for(int i = 0; i < troopsToDistribute; i++) {
|
||||||
|
int castleNumber = random.nextInt(adjacentCastles.size());
|
||||||
|
System.out.print(castleNumber + " ");
|
||||||
|
adjacentCastles.get(castleNumber).addTroops(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setJoker(1, JokerTypes.SCARE_TROOPS_USED);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
private class AIThread extends Thread {
|
private class AIThread extends Thread {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue