diff options
author | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-05-31 05:34:24 +0200 |
---|---|---|
committer | Jannis Harder <harder@informatik.uni-luebeck.de> | 2011-05-31 05:34:24 +0200 |
commit | f1abd1b564a64b79c9f6eff25c95df6c6bd142d8 (patch) | |
tree | ef0a4fffacec1007bc7aef97dbbedfaddff88549 | |
parent | c1651e531792ad58560393691a9e9bf6d9e1a934 (diff) | |
download | JRummikub-f1abd1b564a64b79c9f6eff25c95df6c6bd142d8.tar JRummikub-f1abd1b564a64b79c9f6eff25c95df6c6bd142d8.zip |
Some AI fixes
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@350 72836036-5685-4462-b002-a69064685172
-rw-r--r-- | src/jrummikub/control/RoundControl.java | 2 | ||||
-rw-r--r-- | src/jrummikub/control/turn/BaseAIControl.java | 20 |
2 files changed, 12 insertions, 10 deletions
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<Stone, Position> entry : hand){ + for (Pair<Stone, Position> 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<Stone, Position> entry : hand){ + for (Pair<Stone, Position> 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<Stone> stones = new ArrayList<Stone>(); @@ -109,20 +110,21 @@ public class BaseAIControl extends AbstractTurnControl { AIUtil aiUtil = new AIUtil(settings); 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() && result.getSecond() < settings.getInitialMeldThreshold()) { emitEndOfTurn(); return; } - + for (StoneSet set : result.getFirst()) { List<Stone> handStones = new ArrayList<Stone>(); 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) { |