The AI now is only computing its turn for a reasonable amount of time

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@562 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Bennet Gerlach 2011-06-22 00:38:28 +02:00
parent 9861417ac1
commit 8c6bf9781f

View file

@ -102,14 +102,7 @@ public class AIControl extends AbstractTurnControl {
}
if (useBackgroundThread) {
Timer timer = new Timer(10000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
logic.autoAbort();
}
});
timer.setRepeats(false);
timer.start();
startTimers();
Thread computeThread = new Thread(new Runnable() {
@Override
@ -131,6 +124,28 @@ public class AIControl extends AbstractTurnControl {
}
private void startTimers() {
Timer timer = new Timer(10000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
logic.autoAbort();
}
});
timer.setRepeats(false);
timer.start();
timer = new Timer((int) (turnInfo.getRoundState().getGameSettings()
.getTotalTime() * 1000 * (0.5 + 0.25 * Math.random())),
new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
executeTurn();
}
});
timer.setRepeats(false);
timer.start();
}
private void addHandStones(List<Stone> handStones) {
for (Pair<Stone, Position> entry : turnInfo.getHand()) {
handStones.add(entry.getFirst());
@ -163,8 +178,8 @@ public class AIControl extends AbstractTurnControl {
for (StoneSet set : result) {
turnInfo.getTable().drop(
set,
new Position(10 * (Math.random() * 2 - 1), 5 * (Math
.random() * 2 - 1)));
new Position(10 * (Math.random() * 2 - 1),
5 * (Math.random() * 2 - 1)));
for (Stone stone : set) {
turnInfo.getHand().pickUp(stone);
}
@ -176,11 +191,10 @@ public class AIControl extends AbstractTurnControl {
private void doNotMoveExistingSets(List<StoneSet> result) {
outerLoop: for (Iterator<Pair<StoneSet, Position>> it = turnInfo
.getTable().iterator(); it.hasNext();) {
outerLoop: for (Iterator<Pair<StoneSet, Position>> it = turnInfo.getTable()
.iterator(); it.hasNext();) {
Pair<StoneSet, Position> pair = it.next();
setSearch: for (Iterator<StoneSet> it2 = result.iterator(); it2
.hasNext();) {
setSearch: for (Iterator<StoneSet> it2 = result.iterator(); it2.hasNext();) {
StoneSet set = it2.next();
if (set.getSize() != pair.getFirst().getSize()) {
continue;