summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r--src/jrummikub/control/RoundControl.java28
-rw-r--r--src/jrummikub/control/turn/BaseAIControl.java3
2 files changed, 25 insertions, 6 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index 5f46fd5..e1d2e97 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -7,6 +7,7 @@ import java.util.Set;
import jrummikub.control.turn.ITurnControl;
import jrummikub.control.turn.TurnControlFactory;
+import static jrummikub.control.turn.TurnControlFactory.Type.*;
import jrummikub.model.Hand;
import jrummikub.model.IHand;
import jrummikub.model.IPlayer;
@@ -35,6 +36,7 @@ public class RoundControl {
private Event restartRoundEvent = new Event();
private Event1<Score> endOfRoundEvent = new Event1<Score>();
private List<Connection> connections = new ArrayList<Connection>();
+ private ITurnControl turnControl;
private boolean roundFinished;
/**
@@ -76,26 +78,39 @@ public class RoundControl {
}
private void prepareTurn() {
+ boolean isHuman = roundState.getActivePlayer().getPlayerSettings().getTurnControlType() == HUMAN;
clonedTable = (ITable) roundState.getTable().clone();
- view.enableStartTurnPanel(true);
+
+ if (isHuman) {
+ view.enableStartTurnPanel(true);
+ } else {
+ view.enableThinkPanel(true);
+ }
+
view.getTablePanel().setStoneSets(clonedTable);
view.setCurrentPlayerName(roundState.getActivePlayer()
.getPlayerSettings().getName());
view.setCurrentPlayerColor(roundState.getActivePlayer()
.getPlayerSettings().getColor());
view.setHasLaidOut(roundState.getActivePlayer().getLaidOut());
-
+
+ if (!isHuman)
+ startTurn();
}
private void startTurn() {
+ if (turnControl != null)
+ return;
+ boolean isHuman = roundState.getActivePlayer().getPlayerSettings().getTurnControlType() == HUMAN;
boolean inspectOnly = roundState.getTurnNumber() < 1;
boolean mayRedeal = inspectOnly
&& roundState.getActivePlayer().getHand()
.getIdenticalStoneCount() >= 3;
- view.getPlayerPanel().setEndTurnMode(inspectOnly, mayRedeal);
-
- ITurnControl turnControl = TurnControlFactory.getFactory(roundState.getActivePlayer()
+ if (isHuman) {
+ view.getPlayerPanel().setEndTurnMode(inspectOnly, mayRedeal);
+ }
+ turnControl = TurnControlFactory.getFactory(roundState.getActivePlayer()
.getPlayerSettings().getTurnControlType()).create();
turnControl.setup(roundState.getActivePlayer(), clonedTable,
view, inspectOnly, mayRedeal);
@@ -142,6 +157,8 @@ public class RoundControl {
}
private void endOfTurn() {
+ view.enableThinkPanel(false);
+ turnControl = null;
if (roundState.getTurnNumber() >= 1) {
checkTurn();
}
@@ -335,6 +352,7 @@ public class RoundControl {
}
private void redeal() {
+ turnControl = null;
for (Connection c : new ArrayList<Connection>(connections)) {
c.remove();
}
diff --git a/src/jrummikub/control/turn/BaseAIControl.java b/src/jrummikub/control/turn/BaseAIControl.java
index 2ed4c6e..d143dc1 100644
--- a/src/jrummikub/control/turn/BaseAIControl.java
+++ b/src/jrummikub/control/turn/BaseAIControl.java
@@ -51,7 +51,8 @@ public class BaseAIControl extends AbstractTurnControl {
private void emitEndOfTurn() {
long timeElapsed = System.currentTimeMillis() - startTime;
- long waitTime = 2000 - timeElapsed;
+ long timeNeeded = Math.min((long)(1000 + Math.random() * hand.getSize() * 100), 50000);
+ long waitTime = timeNeeded - timeElapsed;
if (waitTime > 0) {
try {