Package edu.wisc.game.sql

## Class Episode

- java.lang.Object
- - edu.wisc.game.sql.Episode

- Direct Known Subclasses:
    `EpisodeInfo`

      @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 episode
    `static 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` |
    `protected int` | `ruleLineNo` | Which row of rules do we look at now? (0-based)
    `static String` | `version` |

  - ### Constructor Summary

    Constructors
    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).

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `Episode.Display` | `doMove​(int y, int x, int by, int bx, int _attemptCnt)` | Evaluate a move attempt
    `Episode.Display` | `doPick​(int y, int x, int _attemptCnt)` | Evaluate a pick attempt
    `Board` | `getCurrentBoard()` | Shows the current board (without removed [dropped] pieces)
    `String` | `getEpisodeId()` |
    `int` | `getNPiecesStart()` |
    `Date` | `getStartTime()` |
    `String` | `graphicDisplay()` | Graphic display of the board
    `String` | `graphicDisplay​(boolean html)` |
    `String` | `graphicDisplayAscii​(boolean html)` | Retired from the web game server; still used in Captive Game Server.
    `Episode.Display` | `mkDisplay()` | Builds a Display objecy to be sent out over the web UI upon a /display call (rather than a /move or /pick)
    `boolean` | `playGame​(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)
    `String` | `report()` | Concise report, handy for debugging
    `void` | `setEpisodeId​(String _episodeId)` |
    `void` | `setNPiecesStart​(int _nPiecesStart)` |
    `void` | `setStartTime​(Date _startTime)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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)

    - #### version

          public static final String version

      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).
      Parameters:
        `_in` - The input stream for commands; it will be null in the web app
        `_out` - Will be null in the web app.

  - ### Method Detail

    - #### getEpisodeId

          public String getEpisodeId()

    - #### setEpisodeId

          public void setEpisodeId​(String _episodeId)

    - #### getStartTime

          public Date getStartTime()

    - #### setStartTime

          public void setStartTime​(Date _startTime)

    - #### getNPiecesStart

          public int getNPiecesStart()

    - #### setNPiecesStart

          public void setNPiecesStart​(int _nPiecesStart)

    - #### graphicDisplay

          public String graphicDisplay()

      Graphic display of the board

    - #### graphicDisplay

          public String graphicDisplay​(boolean html)

    - #### graphicDisplayAscii

          public String graphicDisplayAscii​(boolean html)

      Retired from the web game server; still used in Captive Game Server.

    - #### getCurrentBoard

          public Board getCurrentBoard()

      Shows the current board (without removed [dropped] pieces)

    - #### mkDisplay

          public Episode.Display mkDisplay()

      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`

    - #### doMove

          public Episode.Display doMove​(int y,
                                        int x,
                                        int by,
                                        int bx,
                                        int _attemptCnt)
                                 throws IOException

      Evaluate a move attempt
      Throws:
        `IOException`

    - #### playGame

          public boolean playGame​(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)
      Returns:
        true if another game is requested
      Throws:
        `IOException`

    - #### report

          public String report()

      Concise report, handy for debugging