AIUtil now needs game settings, both hand and player do not anymore
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@342 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
278edc37a9
commit
d276b03c39
10 changed files with 140 additions and 137 deletions
|
@ -18,18 +18,6 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
|||
*/
|
||||
public final static int WIDTH = 14;
|
||||
|
||||
private GameSettings settings;
|
||||
|
||||
/**
|
||||
* Create a new empty hand with given game settings
|
||||
*
|
||||
* @param settings
|
||||
* the game settings
|
||||
*/
|
||||
public Hand(GameSettings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFreeRowSpace(int row) {
|
||||
int count = 0;
|
||||
|
@ -74,7 +62,8 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
|||
}
|
||||
}
|
||||
|
||||
public int getStonePoints() {
|
||||
@Override
|
||||
public int getStonePoints(GameSettings settings) {
|
||||
int points = 0;
|
||||
|
||||
for (Pair<Stone, Position> entry : this) {
|
||||
|
@ -89,7 +78,9 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialMeldPossible() {
|
||||
public boolean isInitialMeldPossible(GameSettings settings) {
|
||||
AIUtil aiUtil = new AIUtil(settings);
|
||||
|
||||
List<Stone> stones = new ArrayList<Stone>();
|
||||
|
||||
for (Iterator<Pair<Stone, Position>> iter = this.iterator(); iter.hasNext();) {
|
||||
|
@ -99,11 +90,9 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
|||
Pair<TreeMap<Pair<Integer, StoneColor>, Integer>, Integer> stoneCounts = AIUtil
|
||||
.countStones(stones);
|
||||
|
||||
Pair<List<StoneSet>, Integer> result = AIUtil.findSetsWithTotalPoints(
|
||||
Pair<List<StoneSet>, Integer> result = aiUtil.findSetsWithTotalPoints(
|
||||
settings.getInitialMeldThreshold(), stoneCounts.getFirst(),
|
||||
stoneCounts.getSecond());
|
||||
|
||||
System.out.println(result);
|
||||
|
||||
return (result.getSecond() >= settings.getInitialMeldThreshold());
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public interface IHand extends IStoneTray<Stone> {
|
|||
* Gets the amount of free space in a hand row
|
||||
*
|
||||
* @param row
|
||||
* the row number
|
||||
* the row number
|
||||
* @return the number of stones that can fit into the row
|
||||
*/
|
||||
int getFreeRowSpace(int row);
|
||||
|
@ -24,17 +24,23 @@ public interface IHand extends IStoneTray<Stone> {
|
|||
/**
|
||||
* Get the accumulated number of points of stones in the hand
|
||||
*
|
||||
* @param settings
|
||||
* the game settings
|
||||
*
|
||||
* @return points
|
||||
*/
|
||||
int getStonePoints();
|
||||
int getStonePoints(GameSettings settings);
|
||||
|
||||
/**
|
||||
* Tests whether it is possible to lay down an initial meld using the stones
|
||||
* on the hand
|
||||
*
|
||||
* @param settings
|
||||
* the game settings
|
||||
*
|
||||
* @return true if an initial meld is possible
|
||||
*/
|
||||
public boolean isInitialMeldPossible();
|
||||
public boolean isInitialMeldPossible(GameSettings settings);
|
||||
|
||||
/**
|
||||
* Counts the pairs of identical stones
|
||||
|
|
|
@ -10,14 +10,12 @@ public class Player implements IPlayer {
|
|||
* Create a new player with a given name and color
|
||||
*
|
||||
* @param settings
|
||||
* the player settings
|
||||
* @param gameSettings
|
||||
* the game settings
|
||||
* the player settings
|
||||
*/
|
||||
public Player(PlayerSettings settings, GameSettings gameSettings) {
|
||||
public Player(PlayerSettings settings) {
|
||||
this.settings = settings;
|
||||
|
||||
hand = new Hand(gameSettings);
|
||||
hand = new Hand();
|
||||
laidOut = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,13 +12,13 @@ public class RoundState implements IRoundState {
|
|||
private int activePlayer;
|
||||
private StoneHeap gameHeap;
|
||||
private IPlayer lastPlayer;
|
||||
private int turnNumber;
|
||||
private int turnNumber;
|
||||
|
||||
/**
|
||||
* Create a new RoundState with an empty table
|
||||
*
|
||||
* @param gameSettings
|
||||
* the game settings
|
||||
* the game settings
|
||||
*/
|
||||
public RoundState(GameSettings gameSettings) {
|
||||
this.gameSettings = gameSettings;
|
||||
|
@ -27,11 +27,11 @@ public class RoundState implements IRoundState {
|
|||
players = new ArrayList<Player>();
|
||||
|
||||
for (PlayerSettings playerSettings : gameSettings.getPlayerList()) {
|
||||
players.add(new Player(playerSettings, gameSettings));
|
||||
players.add(new Player(playerSettings));
|
||||
}
|
||||
|
||||
turnNumber = 1-gameSettings.getPlayerList().size();
|
||||
|
||||
turnNumber = 1 - gameSettings.getPlayerList().size();
|
||||
|
||||
activePlayer = 0;
|
||||
gameHeap = new StoneHeap(gameSettings);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ public class RoundState implements IRoundState {
|
|||
}
|
||||
return players.get(j);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IPlayer getNthPlayer(int i) {
|
||||
int j = i % players.size();
|
||||
|
@ -107,7 +107,7 @@ public class RoundState implements IRoundState {
|
|||
public IPlayer getLastPlayer() {
|
||||
return lastPlayer;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getTurnNumber() {
|
||||
return turnNumber;
|
||||
|
|
Reference in a new issue