Package edu.wisc.game.sql
Class Episode
- java.lang.Object
-
- edu.wisc.game.sql.Episode
-
- Direct Known Subclasses:
EpisodeInfo,ReplayedEpisode
@Entity public class Episode extends Object
An Episode is a single instance of a Game played by a person or machine with our game server. It describes the current state of the game, and has methods for processing player's actions. The episode object contains the top-level controls describing the current state of the rule set associated with this episode.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEpisode.CODEReturn codes for the /move and /display API web API calls, and for the MOVE command in the captive game server.classEpisode.DisplayCan be sent to the web client in JSON format, where it would be used to display the current state of the episodestatic classEpisode.FINISH_CODEValues that may be returned by getFinishCode(), describing the episode's statusstatic classEpisode.MoveA Move instance describes an [attempted] act of picking a piece and dropping it into a bucket.static classEpisode.OutputModestatic classEpisode.PickA Pick instance describes the act of picking a piece, without specifying its destination
-
Field Summary
Fields Modifier and Type Field Description StringepisodeIdThis is used to assign episode IDs, which are unique within a given server run.static intNBUstatic RandomRGrandomprotected edu.wisc.game.sql.Episode.RuleLineruleLineprotected intruleLineNoWhich row of rules do we look at now? (0-based)static DateFormatsdfstatic DateFormatsdf2with millisecondsstatic StringversionThe current version of the application
-
Constructor Summary
Constructors Modifier Constructor Description Episode()Dummy constructor; only used for error code production, and maybe also by JPA when restoring a player's info (with all episodes) from the database.Episode(Game game, Episode.OutputMode _outputMode, Reader _in, PrintWriter _out)Creates a new Episode for a given Game (which defines rules and the properties of the initial board).protectedEpisode(Game game, Episode.OutputMode _outputMode, Reader _in, PrintWriter _out, String _episodeId)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intaccept(Episode.Pick move)One normally should not use this method directly; use doPick() or doMove() instead.protected StringdisplayJson()Episode.DisplaydoMove(int y, int x, int by, int bx, int _attemptCnt)Evaluate a move attemptEpisode.DisplaydoMove2(int pieceId, int bucketId, int _attemptCnt)Episode.DisplaydoPick(int y, int x, int _attemptCnt)Evaluate a pick attemptEpisode.DisplaydoPick2(int pieceId, int _attemptCnt)Processes a /pick?id=...protected intfindJ(Episode.Pick pick)Where in the values array do we have a game piece referred to by this Pick or Move? (The match is by piece ID)intgetAttemptCnt()BoardgetCurrentBoard()Shows the current board (without removed [dropped] pieces)BoardgetCurrentBoard(boolean showRemoved)Returns the current board, or, on a restored-from-SQL-server episodes, null (or empty board, to keep the client from crashing).StringgetEpisodeId()boolean[]getIsJMoveable()Episode.PickgetLastMove()intgetLastMovePos()intgetNPiecesStart()DategetStartTime()Vector<Episode.Pick>getTranscript()Vector<Piece>getValues()static StringgetVersion()FIXME: this shows up in Reflection, as if it's a property of each objectStringgraphicDisplay()Graphic display of the boardStringgraphicDisplay(boolean html)Generates an HTML table displaying the current board state,static StringgraphicDisplayAscii(Vector<Piece> values, Episode.Pick lastMove, boolean weShowAllMovables, boolean[] isJMoveable, boolean html)Retired from the web game server; still used in Captive Game Server.booleanisCompleted()Episode.DisplaymkDisplay0()Builds a Display objecy to be sent out over the web UI upon a /display call (rather than a /move or /pick)static BitSetonBoard(Vector<Piece> values)booleanplayGame(GameGenerator gg, int gameCnt)Lets this episode play out until either all pieces are cleared, or a stalemate is reached, or the player gives up (sends an EXIT or NEW command).static StringrandomWord(int len)Creates a word made out of random letters and digitsStringreport()Concise report, handy for debuggingvoidsetEpisodeId(String _episodeId)voidsetNPiecesStart(int _nPiecesStart)voidsetStartTime(Date _startTime)booleanweShowAllMovables()The basic mode tells the player where all movable pieces are, but EpisodeInfo will override it if the para set mandates "free" mode.
-
-
-
Field Detail
-
episodeId
public String episodeId
This is used to assign episode IDs, which are unique within a given server run. The IDs are not meant to be persistent.
-
NBU
public static final int NBU
-
ruleLineNo
protected int ruleLineNo
Which row of rules do we look at now? (0-based)
-
ruleLine
protected edu.wisc.game.sql.Episode.RuleLine ruleLine
-
sdf
public static final DateFormat sdf
-
sdf2
public static final DateFormat sdf2
with milliseconds
-
random
public static final RandomRG random
-
version
public static final String version
The current version of the application- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Episode
public Episode()
Dummy constructor; only used for error code production, and maybe also by JPA when restoring a player's info (with all episodes) from the database.
-
Episode
public Episode(Game game, Episode.OutputMode _outputMode, Reader _in, PrintWriter _out)
Creates a new Episode for a given Game (which defines rules and the properties of the initial board). Depending on what the Game is, the episode may use a pre-created board stored in the Game object, or a random board created on the fly.- Parameters:
_in- The input stream for commands; it will be null in the web app_out- Will be null in the web app.
-
Episode
protected Episode(Game game, Episode.OutputMode _outputMode, Reader _in, PrintWriter _out, String _episodeId)
-
-
Method Detail
-
getEpisodeId
public String getEpisodeId()
-
setEpisodeId
public void setEpisodeId(String _episodeId)
-
getStartTime
public Date getStartTime()
-
setStartTime
public void setStartTime(Date _startTime)
-
findJ
protected int findJ(Episode.Pick pick)
Where in the values array do we have a game piece referred to by this Pick or Move? (The match is by piece ID)
-
getAttemptCnt
public int getAttemptCnt()
-
getTranscript
public Vector<Episode.Pick> getTranscript()
-
randomWord
public static String randomWord(int len)
Creates a word made out of random letters and digits
-
getNPiecesStart
public int getNPiecesStart()
-
setNPiecesStart
public void setNPiecesStart(int _nPiecesStart)
-
getLastMove
public Episode.Pick getLastMove()
-
getLastMovePos
public int getLastMovePos()
-
accept
protected int accept(Episode.Pick move)
One normally should not use this method directly; use doPick() or doMove() instead.
-
weShowAllMovables
public boolean weShowAllMovables()
The basic mode tells the player where all movable pieces are, but EpisodeInfo will override it if the para set mandates "free" mode.
-
graphicDisplay
public String graphicDisplay()
Graphic display of the board
-
graphicDisplay
public String graphicDisplay(boolean html)
Generates an HTML table displaying the current board state,- Parameters:
html- If false, call the ASCII-graphics routine instead (for printing on terminal, instead of a web browser)
-
graphicDisplayAscii
public static String graphicDisplayAscii(Vector<Piece> values, Episode.Pick lastMove, boolean weShowAllMovables, boolean[] isJMoveable, boolean html)
Retired from the web game server; still used in Captive Game Server.
-
getCurrentBoard
public Board getCurrentBoard(boolean showRemoved)
Returns the current board, or, on a restored-from-SQL-server episodes, null (or empty board, to keep the client from crashing).
-
getCurrentBoard
public Board getCurrentBoard()
Shows the current board (without removed [dropped] pieces)
-
displayJson
protected String displayJson()
- Returns:
- The description of the current board in the form of a JSON string.
-
getVersion
public static String getVersion()
FIXME: this shows up in Reflection, as if it's a property of each object
-
mkDisplay0
public Episode.Display mkDisplay0()
Builds a Display objecy to be sent out over the web UI upon a /display call (rather than a /move or /pick)
-
doPick
public Episode.Display doPick(int y, int x, int _attemptCnt) throws IOException
Evaluate a pick attempt- Throws:
IOException
-
doPick2
public Episode.Display doPick2(int pieceId, int _attemptCnt) throws IOException
Processes a /pick?id=... call. The call is only entered into the transcript if the args are valid, or if the error is due to invalid object id ZZZZ- Throws:
IOException
-
doMove
public Episode.Display doMove(int y, int x, int by, int bx, int _attemptCnt) throws IOException
Evaluate a move attempt- Parameters:
x- the x-coordinate (1 thru 6) of the game piece the player tries to movey- the y-coordinate of the game piece the player tries to movebx- the x-coordinate of the destination bucket (0 or 7)by- the y-coordinate of the destination bucket (0 or 7)_attemptCnt- the number of previously made attempts in this episode, according to the client that has sent this request. This number must match this.attemptCnt- Throws:
IOException
-
doMove2
public Episode.Display doMove2(int pieceId, int bucketId, int _attemptCnt) throws IOException
- Throws:
IOException
-
playGame
public boolean playGame(GameGenerator gg, int gameCnt) throws IOException
Lets this episode play out until either all pieces are cleared, or a stalemate is reached, or the player gives up (sends an EXIT or NEW command). The episode takes commands from the reader, as in the Captive Game Server.- Parameters:
game- This is passed just so that we can access the feature list for the FEATURES commandgameCnt- The sequential number of the current episode. This is only used in a message.- Returns:
- true if another episode is requested, i.e. the player has entered a NEW command. false is returned if the player enters an EXIT command, or simply closes the input stream.
- Throws:
IOException
-
isCompleted
public boolean isCompleted()
- Returns:
- true if this episode cannot accept any more move attempts, for any reason (board cleared, stalemate, given up, lost, abandoned).
-
report
public String report()
Concise report, handy for debugging
-
getIsJMoveable
public boolean[] getIsJMoveable()
-
-