* @param gameId Name of the game to terminate.
* @param prevMoves The last set of moves made in the game.
*/
public static synchronized void endGame(String gameId, GdlList prevMoves)
{
Gamer gamer = games_.get(gameId);
if (gamer == null)
{
logger_.severe(gameId + ": WARNING: Attempting to terminate game [" + gameId
+ "], but no such game");
return;
}
try
{
StringBuilder prevMovesStr = new StringBuilder();
prevMovesStr.append(" Previous moves: ");
for ( GdlExpression exp : prevMoves )
{
prevMovesStr.append(exp.toString());
prevMovesStr.append(" ");
}
logger_.info(gameId + ": Beginning payoff computation." + prevMovesStr);
// Get the list of payoffs: <Role, Payoff, IsMe>
List<Triple<String, Integer, Boolean>> results = gamer.getPayoffs(prevMoves);
// Figure out what the longest role is
int maxRoleLength = 0;
for ( Triple<String, Integer, Boolean> res : results )
maxRoleLength = Math.max(maxRoleLength, res.first.length());
// Print out the payoffs
for ( Triple<String, Integer, Boolean> res : results )
{
// print the right amount of spaces (so that things line up right)
StringBuilder spacing = new StringBuilder();
for ( int i = 0; i < maxRoleLength - res.first.length(); i++ )
spacing.append(" ");
logger_.info(" " + ( res.third ? "->" : " " ) + " " + res.first
+ spacing + " " + res.second + " "
+ ( res.third ? "<-" : " " ));
}
}
catch (Exception e)
{
logger_.severe(gameId + ": Error computing payoff: " + e.getClass().getName() + " - " + e.getMessage());
}
// tell the game it's time to die.
gamer.stopIt();
games_.remove(gameId);
}