org.jscience.computing.game
Class SocketPlayer

java.lang.Object
  extended by org.jscience.computing.game.SocketPlayer
All Implemented Interfaces:
java.io.Serializable, Player

public class SocketPlayer
extends java.lang.Object
implements Player, java.io.Serializable

SocketPlayer is a wrapper around a standard Player object. It handles all requests to the Player by routing it through the network to a SocketPlayerServer, who embedds the actual object that returns the results for the AutoPlay. Limitation: any exceptions that may be thrown by the SocketPlayerServer are not properly propagated, but show up as simple IOExceptions, which are not handled with much sophistication.

See Also:
SocketPlayerServer, Player, AutoPlay, Serialized Form

Field Summary
static int SO_TIMEOUT
          DOCUMENT ME!
 
Constructor Summary
SocketPlayer(java.lang.String hostName, int port)
          sets the host and port number where the SocketPlayerServer is listening
SocketPlayer(java.lang.String hostName, int port, boolean keepAlive)
          when keepAlive is set to true, the SocketPlayer will reuse the current socket connection for further requests
 
Method Summary
 boolean canPlayGame(GamePlay game)
          DOCUMENT ME!
protected  void cleanup()
          DOCUMENT ME!
 double evaluate(GamePlay game, GameMove move, int[] role, int level, long milliseconds)
          DOCUMENT ME!
protected  void finalize()
          DOCUMENT ME!
 java.lang.String getHostname()
          DOCUMENT ME!
 java.lang.String getPlayerName()
          DOCUMENT ME!
 int getPort()
          DOCUMENT ME!
protected  boolean handshake()
          DOCUMENT ME!
 double heuristic(GamePlay game, GameMove move, int[] role)
          DOCUMENT ME!
 boolean pruneMove(GamePlay game, GameMove move, int[] role)
          DOCUMENT ME!
 GameMove selectMove(GamePlay game, int[] role, int level, long milliseconds)
          DOCUMENT ME!
 void sendMessage(java.lang.Object message)
          DOCUMENT ME!
 java.lang.String toString()
          DOCUMENT ME!
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SO_TIMEOUT

public static int SO_TIMEOUT
DOCUMENT ME!

Constructor Detail

SocketPlayer

public SocketPlayer(java.lang.String hostName,
                    int port)
sets the host and port number where the SocketPlayerServer is listening

See Also:
SocketPlayerServer

SocketPlayer

public SocketPlayer(java.lang.String hostName,
                    int port,
                    boolean keepAlive)
when keepAlive is set to true, the SocketPlayer will reuse the current socket connection for further requests

Parameters:
hostName - DOCUMENT ME!
port - DOCUMENT ME!
keepAlive - DOCUMENT ME!
Method Detail

handshake

protected boolean handshake()
DOCUMENT ME!

Returns:
DOCUMENT ME!

cleanup

protected void cleanup()
DOCUMENT ME!


finalize

protected void finalize()
DOCUMENT ME!

Overrides:
finalize in class java.lang.Object

getPlayerName

public java.lang.String getPlayerName()
DOCUMENT ME!

Specified by:
getPlayerName in interface Player
Returns:
DOCUMENT ME!

sendMessage

public void sendMessage(java.lang.Object message)
DOCUMENT ME!

Parameters:
message - DOCUMENT ME!

canPlayGame

public boolean canPlayGame(GamePlay game)
DOCUMENT ME!

Specified by:
canPlayGame in interface Player
Parameters:
game - DOCUMENT ME!
Returns:
DOCUMENT ME!

pruneMove

public boolean pruneMove(GamePlay game,
                         GameMove move,
                         int[] role)
DOCUMENT ME!

Specified by:
pruneMove in interface Player
Parameters:
game - DOCUMENT ME!
move - DOCUMENT ME!
role - DOCUMENT ME!
Returns:
DOCUMENT ME!

heuristic

public double heuristic(GamePlay game,
                        GameMove move,
                        int[] role)
                 throws CannotPlayGameException
DOCUMENT ME!

Specified by:
heuristic in interface Player
Parameters:
game - DOCUMENT ME!
move - DOCUMENT ME!
role - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
CannotPlayGameException - DOCUMENT ME!
See Also:
TemplatePlayer

evaluate

public double evaluate(GamePlay game,
                       GameMove move,
                       int[] role,
                       int level,
                       long milliseconds)
                throws CannotPlayGameException
DOCUMENT ME!

Specified by:
evaluate in interface Player
Parameters:
game - DOCUMENT ME!
move - DOCUMENT ME!
role - DOCUMENT ME!
level - DOCUMENT ME!
milliseconds - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
CannotPlayGameException - DOCUMENT ME!
See Also:
GameUtils, TemplatePlayer, GamePlay.getResult(int)

selectMove

public GameMove selectMove(GamePlay game,
                           int[] role,
                           int level,
                           long milliseconds)
                    throws CannotPlayGameException
DOCUMENT ME!

Specified by:
selectMove in interface Player
Parameters:
game - DOCUMENT ME!
role - DOCUMENT ME!
level - DOCUMENT ME!
milliseconds - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
CannotPlayGameException - DOCUMENT ME!
See Also:
TemplatePlayer

getHostname

public java.lang.String getHostname()
DOCUMENT ME!

Returns:
DOCUMENT ME!

getPort

public int getPort()
DOCUMENT ME!

Returns:
DOCUMENT ME!

toString

public java.lang.String toString()
DOCUMENT ME!

Overrides:
toString in class java.lang.Object
Returns:
DOCUMENT ME!