Implemented view code for AI turns

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@319 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-05-30 01:31:36 +02:00
parent 15558d7138
commit b19a46b7b2
8 changed files with 82 additions and 15 deletions

View file

@ -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();
}

View file

@ -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 {