Some AI fixes

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@350 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-05-31 05:34:24 +02:00
parent c1651e5317
commit f1abd1b564
2 changed files with 12 additions and 10 deletions

View file

@ -88,7 +88,7 @@ public class RoundControl {
view.enableThinkPanel(true); view.enableThinkPanel(true);
} }
view.getTablePanel().setStoneSets(clonedTable); view.getTablePanel().setStoneSets(clonedTable.clone());
view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings() view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings()
.getName()); .getName());
view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings() view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings()

View file

@ -75,13 +75,14 @@ public class BaseAIControl extends AbstractTurnControl {
} }
private Stone findMatchingStone(Stone target) { private Stone findMatchingStone(Stone target) {
for(Pair<Stone, Position> entry : hand){ for (Pair<Stone, Position> entry : hand) {
Stone stone = entry.getFirst(); Stone stone = entry.getFirst();
if (stone.getValue() == target.getValue() && stone.getColor() == target.getColor()) { if (stone.getValue() == target.getValue()
&& stone.getColor() == target.getColor()) {
return stone; return stone;
} }
} }
for(Pair<Stone, Position> entry : hand){ for (Pair<Stone, Position> entry : hand) {
Stone stone = entry.getFirst(); Stone stone = entry.getFirst();
if (stone.isJoker()) { if (stone.isJoker()) {
return stone; return stone;
@ -95,7 +96,7 @@ public class BaseAIControl extends AbstractTurnControl {
hand.pickUp(match); hand.pickUp(match);
return match; return match;
} }
private void turn() { private void turn() {
List<Stone> stones = new ArrayList<Stone>(); List<Stone> stones = new ArrayList<Stone>();
@ -109,20 +110,21 @@ public class BaseAIControl extends AbstractTurnControl {
AIUtil aiUtil = new AIUtil(settings); AIUtil aiUtil = new AIUtil(settings);
Pair<List<StoneSet>, Integer> result = aiUtil.findSetsWithTotalPoints( Pair<List<StoneSet>, Integer> result = aiUtil.findSetsWithTotalPoints(
Integer.MAX_VALUE, counts.getFirst(), counts.getSecond()); Math.max(30, settings.getInitialMeldThreshold() * 2),
counts.getFirst(), counts.getSecond());
if (!player.getLaidOut() if (!player.getLaidOut()
&& result.getSecond() < settings.getInitialMeldThreshold()) { && result.getSecond() < settings.getInitialMeldThreshold()) {
emitEndOfTurn(); emitEndOfTurn();
return; return;
} }
for (StoneSet set : result.getFirst()) { for (StoneSet set : result.getFirst()) {
List<Stone> handStones = new ArrayList<Stone>(); List<Stone> handStones = new ArrayList<Stone>();
for (Stone stone : set) { for (Stone stone : set) {
handStones.add(pickUpMatchingStone(stone)); handStones.add(pickUpMatchingStone(stone));
} }
table.drop(new StoneSet(handStones), new Position(0, 0)); table.drop(new StoneSet(handStones), new Position((float)Math.random() * 30 - 15, (float)Math.random() * 6 - 3));
} }
emitEndOfTurn(); emitEndOfTurn();
@ -142,8 +144,8 @@ public class BaseAIControl extends AbstractTurnControl {
private void emitEndOfTurn() { private void emitEndOfTurn() {
long timeElapsed = System.currentTimeMillis() - startTime; long timeElapsed = System.currentTimeMillis() - startTime;
long timeNeeded = Math.min((long) (1000 + Math.random() * hand.getSize() long timeNeeded = Math.min(
* 100), 50000); (long) (1000 + Math.random() * hand.getSize() * 100), 50000);
long waitTime = timeNeeded - timeElapsed; long waitTime = timeNeeded - timeElapsed;
if (waitTime > 0) { if (waitTime > 0) {