diff options
Diffstat (limited to 'src/jrummikub/control/turn')
-rw-r--r-- | src/jrummikub/control/turn/AIControl.java | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/src/jrummikub/control/turn/AIControl.java b/src/jrummikub/control/turn/AIControl.java index f480143..9ce162f 100644 --- a/src/jrummikub/control/turn/AIControl.java +++ b/src/jrummikub/control/turn/AIControl.java @@ -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; |