com.bolinfest.prisonerbot
Class DefaultManager

java.lang.Object
  extended by com.bolinfest.prisonerbot.DefaultManager
All Implemented Interfaces:
Manager
Direct Known Subclasses:
DaimManager, SmackManager

public class DefaultManager
extends Object
implements Manager

DefaultManager is an implementation of the Manager interface.

Author:
mbolin

Field Summary
protected  Map buddies
          Each entry represents a Buddy with which this Manager is maintaining a conversation.
protected  Map games
          Maps names of players to the games in which they are involved
protected  GameLogger logger
           
protected  MessageProxy proxy
           
protected  Set waitingToPlay
          These are the buddies who are waiting to play a game.
 
Fields inherited from interface com.bolinfest.prisonerbot.Manager
ASK_NUM_ROUNDS_MESSAGE, ASK_TO_PLAY_AGAIN_MESSAGE, ASK_TO_PLAY_MESSAGE, CHOICE_ALREADY_ENTERED_MESSAGE, CONFUSED_MESSAGE, DOES_NOT_WANT_TO_PLAY_MESSAGE, FINDING_AN_OPPONENT_MESSAGE, FOUND_OPPONENT_MESSAGE, HELP_MESSAGE, HTML_PATTERN, INTRODUCTORY_MESSAGE, MAX_ROUNDS, MESSAGE_FROM_OPPONENT_DISCLAIMER, MIN_ROUNDS, NUM_ROUNDS_BOUNDS_ERROR_MESSAGE, NUM_ROUNDS_ENTERED_MESSAGE, NUM_ROUNDS_NAN_ERROR_MESSAGE, WAITING_FOR_OPPONENT_CHOICE_MESSAGE
 
Constructor Summary
DefaultManager(MessageProxy proxy)
           
 
Method Summary
protected  Buddy addBuddy(String name)
           
protected static String createGameOverMessage(Buddy buddy, SimpleIterativeGame game)
           
protected static String createLastRoundSummary(Buddy buddy, SimpleIterativeGame game)
           
protected static String createRoundMessage(Buddy buddy, SimpleIterativeGame game)
          This should return a message telling the player: what round it is what his score is what his opponent's score is
protected static String createScoreSummary(Buddy buddy, SimpleIterativeGame game)
           
protected  void gameOver(SimpleIterativeGame game)
           
 int getBuddyCount()
           
 int getBuddyStatus(String buddyName)
           
 UnmodifiableGame getGame(String buddyName)
          Get an unmodifiable view of the game in which the buddy with this name is involved.
 GameLogger getLogger()
           
protected  void goToNextRound(SimpleIterativeGame game)
           
protected  void handleActivePlayerMessage(Buddy buddy, String message)
           
 void handleMessage(String sender, String message)
           
protected  void handleNegotiatingRoundsResponse(Buddy buddy, String message)
           
protected  void handleWantsToPlayResponse(Buddy buddy, String message)
           
 boolean hasBuddy(String buddyName)
           
 boolean isOpponentAvailable()
           
protected  void pairUp(Buddy player1, Buddy player2)
          Pair up the two buddies to play a game
 void removeAllBuddies()
           
protected  void removeBuddy(String name)
           
protected  void sendMessage(Buddy buddy, String message)
          sends the message to the buddy
 void setLogger(GameLogger logger)
           
static String stripTags(String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buddies

protected Map buddies
Each entry represents a Buddy with which this Manager is maintaining a conversation. foreach in buddies, k = v.getName()


waitingToPlay

protected Set waitingToPlay
These are the buddies who are waiting to play a game. Ideally, the size of this Set should always be 0 or 1, but it could become more if people request to play faster than the Manager can assign people to games. A LinkedHashSet is used so that no buddy is in this Collection more than once, and so that removing a Buddy from this Collection behaves as a FIFO queue.


games

protected Map games
Maps names of players to the games in which they are involved


proxy

protected MessageProxy proxy

logger

protected GameLogger logger
Constructor Detail

DefaultManager

public DefaultManager(MessageProxy proxy)
Method Detail

stripTags

public static String stripTags(String s)

handleMessage

public void handleMessage(String sender,
                          String message)
Specified by:
handleMessage in interface Manager
Parameters:
sender -
message -

handleWantsToPlayResponse

protected void handleWantsToPlayResponse(Buddy buddy,
                                         String message)

handleNegotiatingRoundsResponse

protected void handleNegotiatingRoundsResponse(Buddy buddy,
                                               String message)

createRoundMessage

protected static String createRoundMessage(Buddy buddy,
                                           SimpleIterativeGame game)
This should return a message telling the player:


createGameOverMessage

protected static String createGameOverMessage(Buddy buddy,
                                              SimpleIterativeGame game)

createScoreSummary

protected static String createScoreSummary(Buddy buddy,
                                           SimpleIterativeGame game)

createLastRoundSummary

protected static String createLastRoundSummary(Buddy buddy,
                                               SimpleIterativeGame game)

pairUp

protected void pairUp(Buddy player1,
                      Buddy player2)
Pair up the two buddies to play a game

Parameters:
player1 -
player2 -

goToNextRound

protected void goToNextRound(SimpleIterativeGame game)

handleActivePlayerMessage

protected void handleActivePlayerMessage(Buddy buddy,
                                         String message)

gameOver

protected void gameOver(SimpleIterativeGame game)

addBuddy

protected Buddy addBuddy(String name)

removeBuddy

protected void removeBuddy(String name)

sendMessage

protected void sendMessage(Buddy buddy,
                           String message)
sends the message to the buddy


getBuddyCount

public int getBuddyCount()
Specified by:
getBuddyCount in interface Manager

hasBuddy

public boolean hasBuddy(String buddyName)
Specified by:
hasBuddy in interface Manager

getBuddyStatus

public int getBuddyStatus(String buddyName)
Specified by:
getBuddyStatus in interface Manager

isOpponentAvailable

public boolean isOpponentAvailable()
Specified by:
isOpponentAvailable in interface Manager

getGame

public UnmodifiableGame getGame(String buddyName)
Description copied from interface: Manager
Get an unmodifiable view of the game in which the buddy with this name is involved. If the buddy is not involved in a game, this method will return null

Specified by:
getGame in interface Manager

removeAllBuddies

public void removeAllBuddies()
Specified by:
removeAllBuddies in interface Manager

getLogger

public GameLogger getLogger()
Specified by:
getLogger in interface Manager

setLogger

public void setLogger(GameLogger logger)
Specified by:
setLogger in interface Manager