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 class
Episode.CODE
Return codes for the /move and /display API web API calls, and for the MOVE command in the captive game server.class
Episode.Display
Can be sent to the web client in JSON format, where it would be used to display the current state of the episodestatic class
Episode.FINISH_CODE
static class
Episode.Move
A Move instance describes an [attempted] act of picking a piece and dropping it into a bucket.static class
Episode.OutputMode
static class
Episode.Pick
A Pick instance describes the act of picking a piece, without specifying its destination -
Field Summary
Fields Modifier and Type Field Description String
episodeId
This is used to assign episode IDs, which are unique within a given server run.static int
NBU
static RandomRG
random
protected edu.wisc.game.sql.Episode.RuleLine
ruleLine
protected int
ruleLineNo
Which row of rules do we look at now? (0-based)static DateFormat
sdf
static DateFormat
sdf2
with millisecondsstatic String
version
The 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).protected
Episode(Game game, Episode.OutputMode _outputMode, Reader _in, PrintWriter _out, String _episodeId)
-
Method Summary
Modifier and Type Method Description protected int
accept(Episode.Pick move)
One normally should not use this method directly; use doPick() or doMove() instead.static String
doHtmlDisplay(Piece[] pieces, int lastMovePos, boolean weShowAllMovables, boolean[] isMoveable, int cellWidth)
Episode.Display
doMove(int y, int x, int by, int bx, int _attemptCnt)
Evaluate a move attemptEpisode.Display
doPick(int y, int x, int _attemptCnt)
Evaluate a pick attemptBoard
getCurrentBoard()
Shows the current board (without removed [dropped] pieces)String
getEpisodeId()
int
getNPiecesStart()
Date
getStartTime()
static String
getVersion()
FIXME: this shows up in Reflection, as if it's a property of each objectString
graphicDisplay()
Graphic display of the boardString
graphicDisplay(boolean html)
Generates an HTML table displaying the current board state,static String
graphicDisplayAscii(Piece[] pieces, int lastMovePos, boolean weShowAllMovables, boolean[] isMoveable, boolean html)
Retired from the web game server; still used in Captive Game Server.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)static BitSet
onBoard(Piece[] pieces)
boolean
playGame(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 String
randomWord(int len)
Creates a word made out of random letters and digitsString
report()
Concise report, handy for debuggingvoid
setEpisodeId(String _episodeId)
void
setNPiecesStart(int _nPiecesStart)
void
setStartTime(Date _startTime)
-
Field Details
-
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 ruleLineNoWhich row of rules do we look at now? (0-based) -
ruleLine
protected edu.wisc.game.sql.Episode.RuleLine ruleLine -
sdf
-
sdf2
with milliseconds -
random
-
version
The current version of the application- See Also:
- Constant Field Values
-
-
Constructor Details
-
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
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 Details
-
getEpisodeId
-
setEpisodeId
-
getStartTime
-
setStartTime
-
randomWord
Creates a word made out of random letters and digits -
getNPiecesStart
public int getNPiecesStart() -
setNPiecesStart
public void setNPiecesStart(int _nPiecesStart) -
onBoard
-
accept
One normally should not use this method directly; use doPick() or doMove() instead. -
graphicDisplay
Graphic display of the board -
graphicDisplay
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)
-
doHtmlDisplay
public static String doHtmlDisplay(Piece[] pieces, int lastMovePos, boolean weShowAllMovables, boolean[] isMoveable, int cellWidth)- Parameters:
pieces
- An array of N*N values, with nulls for empty cells
-
graphicDisplayAscii
public static String graphicDisplayAscii(Piece[] pieces, int lastMovePos, boolean weShowAllMovables, boolean[] isMoveable, boolean html)Retired from the web game server; still used in Captive Game Server. -
getCurrentBoard
Shows the current board (without removed [dropped] pieces) -
getVersion
FIXME: this shows up in Reflection, as if it's a property of each object -
mkDisplay0
Builds a Display objecy to be sent out over the web UI upon a /display call (rather than a /move or /pick) -
doPick
Evaluate a pick attempt- Throws:
IOException
-
doMove
Evaluate a move attempt- Throws:
IOException
-
playGame
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.- Parameters:
gameCnt
- 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
-
report
Concise report, handy for debugging
-