heurgame.event.turn
Class RoundRobinIterator

java.lang.Object
  extended byheurgame.event.turn.AbstractTurnIterator
      extended byheurgame.event.turn.AbstractTokenBasedIterator
          extended byheurgame.event.turn.RoundRobinIterator
All Implemented Interfaces:
TokenBased
Direct Known Subclasses:
SecondChanceRRIterator

public class RoundRobinIterator
extends AbstractTokenBasedIterator

Author:
David Kaplin This particular iterator is token-based. In a given round the iterator offers turns in correspondance with each token. For any reason if the order changes in the middle of a round, the new order will not take effect until the next round. When a person is disqualified it would be good to notify this iterator of the new order so they do not get a turn in the next round.

Field Summary
protected  int currentRound
          Round will start with 1 currentRound
protected  PlayerToken currentToken
          handle to the current player currentToken
protected  java.util.Vector latestTokens
          Buffer to store incomming tokens latestTokens This buffer will be used at the end of the current round.
protected  java.util.ListIterator playerHelper
          A ListIterator is doing the real dirty work playerHelper
protected  java.util.Vector playerTokens
          The source of the order is playerTokens
protected  LogBox rrLog
          Handle for easy debugging access rrLog
protected  int totalRounds
          Only positive numbers for totalRounds
 
Fields inherited from class heurgame.event.turn.AbstractTurnIterator
mylisteners
 
Constructor Summary
RoundRobinIterator()
           
 
Method Summary
 PlayerToken getCurrentToken()
           
 boolean hasMore()
           
protected  void logState(java.lang.String shortMessage)
          Helper method to simplify adding log entries
 void next()
          Shifts state to the next turn, and broadcasts the turnChanged Event
 void setup(int totalRounds, java.util.Vector pTokens)
          Sets or Resets the state of the Iterator
 void updateActiveTokens(java.util.Vector newTokens)
          When there is some change in the order of players or the actual number of the players themselves it would be good for the iterator to compensate.
 
Methods inherited from class heurgame.event.turn.AbstractTurnIterator
addTurnListener, notifyTurnListeners, removeAllTurnListeners, removeTurnListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rrLog

protected LogBox rrLog
Handle for easy debugging access rrLog


playerTokens

protected java.util.Vector playerTokens
The source of the order is playerTokens


currentRound

protected volatile int currentRound
Round will start with 1 currentRound


totalRounds

protected volatile int totalRounds
Only positive numbers for totalRounds


playerHelper

protected java.util.ListIterator playerHelper
A ListIterator is doing the real dirty work playerHelper


currentToken

protected volatile PlayerToken currentToken
handle to the current player currentToken


latestTokens

protected java.util.Vector latestTokens
Buffer to store incomming tokens latestTokens This buffer will be used at the end of the current round.

Constructor Detail

RoundRobinIterator

public RoundRobinIterator()
Method Detail

setup

public void setup(int totalRounds,
                  java.util.Vector pTokens)
Sets or Resets the state of the Iterator

Parameters:
totalRounds - Positive integer
pTokens - A Vector of Player Tokens in the desired order

next

public void next()
Shifts state to the next turn, and broadcasts the turnChanged Event

Specified by:
next in class AbstractTurnIterator
See Also:
AbstractTurnIterator.next()

hasMore

public boolean hasMore()
Specified by:
hasMore in class AbstractTurnIterator
Returns:
True while the current round is less than or equal to the total. If the game has 10 rounds the number of the last round will be 10 and the iterator will be exhausted before the start of 11.
See Also:
AbstractTurnIterator.hasMore()

updateActiveTokens

public void updateActiveTokens(java.util.Vector newTokens)
When there is some change in the order of players or the actual number of the players themselves it would be good for the iterator to compensate.

Parameters:
newTokens - The new order of the tokens for the next round

logState

protected void logState(java.lang.String shortMessage)
Helper method to simplify adding log entries

Parameters:
shortMessage - Describes the turn

getCurrentToken

public PlayerToken getCurrentToken()
Returns:
The player token of the current turn's player
See Also:
TokenBased.getCurrentToken()