From 8c6bf9781f0d1ebab406e403b0b8865f7b06b536 Mon Sep 17 00:00:00 2001 From: Bennet Gerlach Date: Wed, 22 Jun 2011 00:38:28 +0200 Subject: 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 --- src/jrummikub/control/turn/AIControl.java | 42 ++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'src/jrummikub') 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 handStones) { for (Pair 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 result) { - outerLoop: for (Iterator> it = turnInfo - .getTable().iterator(); it.hasNext();) { + outerLoop: for (Iterator> it = turnInfo.getTable() + .iterator(); it.hasNext();) { Pair pair = it.next(); - setSearch: for (Iterator it2 = result.iterator(); it2 - .hasNext();) { + setSearch: for (Iterator it2 = result.iterator(); it2.hasNext();) { StoneSet set = it2.next(); if (set.getSize() != pair.getFirst().getSize()) { continue; -- cgit v1.2.3