diff options
author | Bennet Gerlach <bennet_gerlach@web.de> | 2011-06-22 00:38:28 +0200 |
---|---|---|
committer | Bennet Gerlach <bennet_gerlach@web.de> | 2011-06-22 00:38:28 +0200 |
commit | 8c6bf9781f0d1ebab406e403b0b8865f7b06b536 (patch) | |
tree | 3ccea88a4c133db98dccf0ccf59bcf027fc9beff | |
parent | 9861417ac10271103d74abeb591518ec2a50b43a (diff) | |
download | JRummikub-8c6bf9781f0d1ebab406e403b0b8865f7b06b536.tar JRummikub-8c6bf9781f0d1ebab406e403b0b8865f7b06b536.zip |
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
-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; |