Implemented special case round end (heap empty)
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@262 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
b20961b89d
commit
d9a0b0e37d
7 changed files with 82 additions and 10 deletions
|
@ -23,7 +23,7 @@ public interface IRoundState {
|
|||
* Sets the current {@link Table}
|
||||
*
|
||||
* @param table
|
||||
* The new Table
|
||||
* The new Table
|
||||
*/
|
||||
public void setTable(ITable table);
|
||||
|
||||
|
@ -55,9 +55,26 @@ public interface IRoundState {
|
|||
* Returns the player that would be the active player after i turns
|
||||
*
|
||||
* @param i
|
||||
* number of turns
|
||||
* number of turns
|
||||
* @return player active after i turns
|
||||
*/
|
||||
public IPlayer getNthNextPlayer(int i);
|
||||
|
||||
/**
|
||||
* Sets the player that will make the last turn before the round ends when
|
||||
* the heap is empty
|
||||
*
|
||||
* @param lastPlayer
|
||||
* the last player
|
||||
*/
|
||||
public abstract IPlayer getLastPlayer();
|
||||
|
||||
/**
|
||||
* Gets the player that will make the last turn before the round ends when
|
||||
* the heap is empty
|
||||
*
|
||||
* @return lastPlayer the last player
|
||||
*/
|
||||
public abstract void setLastPlayer(IPlayer lastPlayer);
|
||||
|
||||
}
|
|
@ -11,12 +11,13 @@ public class RoundState implements IRoundState {
|
|||
private List<Player> players;
|
||||
private int activePlayer;
|
||||
private StoneHeap gameHeap;
|
||||
private IPlayer lastPlayer;
|
||||
|
||||
/**
|
||||
* Create a new RoundState with an empty table
|
||||
*
|
||||
* @param gameSettings
|
||||
* the game settings
|
||||
* the game settings
|
||||
*/
|
||||
public RoundState(GameSettings gameSettings) {
|
||||
this.gameSettings = gameSettings;
|
||||
|
@ -54,7 +55,11 @@ public class RoundState implements IRoundState {
|
|||
|
||||
@Override
|
||||
public IPlayer getNthNextPlayer(int i) {
|
||||
return players.get((activePlayer + i) % players.size());
|
||||
int j = (activePlayer + i) % players.size();
|
||||
if (j < 0) {
|
||||
j += players.size();
|
||||
}
|
||||
return players.get(j);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,4 +76,14 @@ public class RoundState implements IRoundState {
|
|||
public GameSettings getGameSettings() {
|
||||
return gameSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastPlayer(IPlayer lastPlayer) {
|
||||
this.lastPlayer = lastPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPlayer getLastPlayer() {
|
||||
return lastPlayer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,9 @@ public class StoneHeap {
|
|||
* @return the drawn stone
|
||||
*/
|
||||
public Stone drawStone() {
|
||||
if (heap.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return heap.remove(generator.nextInt(heap.size()));
|
||||
}
|
||||
|
||||
|
@ -48,6 +51,7 @@ public class StoneHeap {
|
|||
*/
|
||||
public List<Stone> drawStones(int number) {
|
||||
List<Stone> drawnStones = new ArrayList<Stone>();
|
||||
number = Math.min(number, heap.size());
|
||||
for (int i = 0; i < number; i++) {
|
||||
drawnStones.add(drawStone());
|
||||
}
|
||||
|
|
Reference in a new issue