|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.game.SocketPlayer
public class SocketPlayer
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.
SocketPlayerServer,
Player,
AutoPlay,
Serialized Form| Field Summary | |
|---|---|
static int |
SO_TIMEOUT
|
| Constructor Summary | |
|---|---|
SocketPlayer(String hostName,
int port)
sets the host and port number where the SocketPlayerServer is listening |
|
SocketPlayer(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)
canPlayGame() returns true only if the Player provides an applicable heuristic for the type of game given. |
protected void |
cleanup()
|
double |
evaluate(GamePlay game,
GameMove move,
int[] role,
int level,
long milliseconds)
evaluate() asks the Player to rate a move in the context of a given game stage relative to its role (if the Player has multiple roles in the game, they will all be found in the role array - giving the Player maximum flexibility) while considering the game level for potential game tree search operations and then using heuristic() to evaluate the leaves of the game tree. |
protected void |
finalize()
|
String |
getHostname()
|
String |
getPlayerName()
|
int |
getPort()
|
protected boolean |
handshake()
|
double |
heuristic(GamePlay game,
GameMove move,
int[] role)
This function - often used as a callback function - evaluates the given move in the context of the given game; it is expected to return quickly. |
boolean |
pruneMove(GamePlay game,
GameMove move,
int[] role)
This method allows the Player to prune a game tree branch by determining that a particular move is not to be considered for further recursive tree search; this method is expected to return quickly. |
GameMove |
selectMove(GamePlay game,
int[] role,
int level,
long milliseconds)
selectMove() asks the Player to select a move out of GamePlay.legalMove() based on the role it plays; milliseconds is an indication of how long the calling function is willing to wait for an answer before continuing with potentially a randomMove or something else. |
void |
sendMessage(Object message)
|
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static int SO_TIMEOUT
| Constructor Detail |
|---|
public SocketPlayer(String hostName,
int port)
SocketPlayerServer
public SocketPlayer(String hostName,
int port,
boolean keepAlive)
| Method Detail |
|---|
protected boolean handshake()
protected void cleanup()
protected void finalize()
finalize in class Objectpublic String getPlayerName()
getPlayerName in interface Playerpublic void sendMessage(Object message)
public boolean canPlayGame(GamePlay game)
Player
//Example:
if (game instanceof MyGameClass) return true; else return false;
// or:
if (game.getClass() == myFavoriteGame.getClass()) return true; else return false;
canPlayGame in interface Player
public boolean pruneMove(GamePlay game,
GameMove move,
int[] role)
PlayerBy default, this method should always return false unless there is a good reason found by a Player to dismiss the tree branch emerging from this move.
pruneMove in interface Player
public double heuristic(GamePlay game,
GameMove move,
int[] role)
throws CannotPlayGameException
Player
heuristic in interface PlayerCannotPlayGameException - if the game cannot be played by the playerTemplatePlayer
public double evaluate(GamePlay game,
GameMove move,
int[] role,
int level,
long milliseconds)
throws CannotPlayGameException
Player
evaluate in interface PlayerCannotPlayGameException - if the game cannot be played by the playerGameUtilities,
TemplatePlayer,
GamePlay.getResult(int)
public GameMove selectMove(GamePlay game,
int[] role,
int level,
long milliseconds)
throws CannotPlayGameException
Player
selectMove in interface PlayerCannotPlayGameExceptionTemplatePlayerpublic String getHostname()
public int getPort()
public String toString()
toString in class Object
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||