From f1abd1b564a64b79c9f6eff25c95df6c6bd142d8 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Tue, 31 May 2011 05:34:24 +0200 Subject: Some AI fixes git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@350 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/RoundControl.java | 2 +- src/jrummikub/control/turn/BaseAIControl.java | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src/jrummikub') diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index 67c177f..40894eb 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -88,7 +88,7 @@ public class RoundControl { view.enableThinkPanel(true); } - view.getTablePanel().setStoneSets(clonedTable); + view.getTablePanel().setStoneSets(clonedTable.clone()); view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings() .getName()); view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings() diff --git a/src/jrummikub/control/turn/BaseAIControl.java b/src/jrummikub/control/turn/BaseAIControl.java index 55cece8..b02c127 100644 --- a/src/jrummikub/control/turn/BaseAIControl.java +++ b/src/jrummikub/control/turn/BaseAIControl.java @@ -75,13 +75,14 @@ public class BaseAIControl extends AbstractTurnControl { } private Stone findMatchingStone(Stone target) { - for(Pair entry : hand){ + for (Pair entry : hand) { Stone stone = entry.getFirst(); - if (stone.getValue() == target.getValue() && stone.getColor() == target.getColor()) { + if (stone.getValue() == target.getValue() + && stone.getColor() == target.getColor()) { return stone; } } - for(Pair entry : hand){ + for (Pair entry : hand) { Stone stone = entry.getFirst(); if (stone.isJoker()) { return stone; @@ -95,7 +96,7 @@ public class BaseAIControl extends AbstractTurnControl { hand.pickUp(match); return match; } - + private void turn() { List stones = new ArrayList(); @@ -109,20 +110,21 @@ public class BaseAIControl extends AbstractTurnControl { AIUtil aiUtil = new AIUtil(settings); Pair, Integer> result = aiUtil.findSetsWithTotalPoints( - Integer.MAX_VALUE, counts.getFirst(), counts.getSecond()); + Math.max(30, settings.getInitialMeldThreshold() * 2), + counts.getFirst(), counts.getSecond()); if (!player.getLaidOut() && result.getSecond() < settings.getInitialMeldThreshold()) { emitEndOfTurn(); return; } - + for (StoneSet set : result.getFirst()) { List handStones = new ArrayList(); for (Stone stone : set) { 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(); @@ -142,8 +144,8 @@ public class BaseAIControl extends AbstractTurnControl { private void emitEndOfTurn() { long timeElapsed = System.currentTimeMillis() - startTime; - long timeNeeded = Math.min((long) (1000 + Math.random() * hand.getSize() - * 100), 50000); + long timeNeeded = Math.min( + (long) (1000 + Math.random() * hand.getSize() * 100), 50000); long waitTime = timeNeeded - timeElapsed; if (waitTime > 0) { -- cgit v1.2.3