<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: Rule</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Class: Rule</h1> <section> <header> <h2>Rule</h2> </header> <article> <div class="container-overview"> <h4 class="name" id="Rule"><span class="type-signature">(abstract) </span>new Rule<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> Rules define specific characteristics of each variant of the game. All rules should inherit from this base class and define the following properties: - Maximum number of points (usually 26 - 24 on board, one on bar, and one outside) - Maximum number of checkers (usually 15 per player/colour) and methods for: - Rolling dice (and a list of moves the player has to make after drawing a specific dice) - Reset state to initial position of pieces. - Validating a move - Checking if game has ended - Checking which player won - Checking how much points the player won </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line20">line 20</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Members</h3> <h4 class="name" id="country"><span class="type-signature"></span>country<span class="type-signature"> :string</span></h4> <div class="description"> Full name of country where this rule (variant) is played. To list multiple countries use a pipe ('|') character as separator. </div> <h5>Type:</h5> <ul> <li> <span class="param-type">string</span> </li> </ul> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line48">line 48</a> </li></ul></dd> </dl> <h4 class="name" id="countryCode"><span class="type-signature"></span>countryCode<span class="type-signature"> :string</span></h4> <div class="description"> Two character ISO code of country where this rule (variant) is played. To list multiple codes use a pipe ('|') character as separator. List codes in same order as countries in the field above. </div> <h5>Type:</h5> <ul> <li> <span class="param-type">string</span> </li> </ul> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line56">line 56</a> </li></ul></dd> </dl> <h4 class="name" id="description"><span class="type-signature"></span>description<span class="type-signature"> :string</span></h4> <div class="description"> Full description of rule </div> <h5>Type:</h5> <ul> <li> <span class="param-type">string</span> </li> </ul> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line41">line 41</a> </li></ul></dd> </dl> <h4 class="name" id="maxPieces"><span class="type-signature"></span>maxPieces<span class="type-signature"> :number</span></h4> <div class="description"> The number of pieces each player has </div> <h5>Type:</h5> <ul> <li> <span class="param-type">number</span> </li> </ul> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line65">line 65</a> </li></ul></dd> </dl> <h4 class="name" id="name"><span class="type-signature"></span>name<span class="type-signature"> :string</span></h4> <div class="description"> Rule name, matching the class name (eg. 'RuleBgCasual') </div> <h5>Type:</h5> <ul> <li> <span class="param-type">string</span> </li> </ul> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line29">line 29</a> </li></ul></dd> </dl> <h4 class="name" id="title"><span class="type-signature"></span>title<span class="type-signature"> :string</span></h4> <div class="description"> Short title describing rule specifics </div> <h5>Type:</h5> <ul> <li> <span class="param-type">string</span> </li> </ul> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line35">line 35</a> </li></ul></dd> </dl> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="allPiecesAreHome"><span class="type-signature"></span>allPiecesAreHome<span class="signature">(state, type)</span><span class="type-signature"> → {boolean}</span></h4> <div class="description"> Check if all pieces are in the home field. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">State to change</td> </tr> <tr> <td class="name"><code>type</code></td> <td class="type"> <span class="param-type"><a href="global.html#PieceType">PieceType</a></span> </td> <td class="description last">Type of piece (white/black)</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line194">line 194</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - True if all pieces are in home field </div> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="applyMoveActions"><span class="type-signature">(abstract) </span>applyMoveActions<span class="signature">(state, actionList)</span><span class="type-signature"></span></h4> <div class="description"> Call this method to apply a list of actions to a game state. Actions depend on rule and usually are `move`, `hit`, `recover` or `bear`. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">State to change</td> </tr> <tr> <td class="name"><code>actionList</code></td> <td class="type"> <span class="param-type">Array.<<a href="MoveAction.html">MoveAction</a>></span> </td> <td class="description last">List of action to apply.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line625">line 625</a> </li></ul></dd> </dl> <h4 class="name" id="bear"><span class="type-signature"></span>bear<span class="signature">(state, piece)</span><span class="type-signature"></span></h4> <div class="description"> Bear piece - remove from board and place outside </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">Board state</td> </tr> <tr> <td class="name"><code>piece</code></td> <td class="type"> <span class="param-type"><a href="Piece.html">Piece</a></span> </td> <td class="description last">Piece to bear</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line679">line 679</a> </li></ul></dd> </dl> <h5>Throws:</h5> <div class="param-desc"> Throws an error if there is no piece at fromPos or piece is of wrong type </div> <h4 class="name" id="calculateMoveWeights"><span class="type-signature"></span>calculateMoveWeights<span class="signature">(state, movesLeft, pieceType, rootPiece, stopAtMax)</span><span class="type-signature"> → {Object}</span></h4> <div class="description"> Recursively try out all combinations for the specified player (by piece type) and check the "weight" of each combination. Weight is the sum of all piece movements for a particular combination of moves (called "branch") </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">State</td> </tr> <tr> <td class="name"><code>movesLeft</code></td> <td class="type"> <span class="param-type">Array.<number></span> </td> <td class="description last">Move values left</td> </tr> <tr> <td class="name"><code>pieceType</code></td> <td class="type"> <span class="param-type"><a href="global.html#PieceType">PieceType</a></span> </td> <td class="description last">Type of piece (white/black)</td> </tr> <tr> <td class="name"><code>rootPiece</code></td> <td class="type"> <span class="param-type"><a href="Piece.html">Piece</a></span> </td> <td class="description last">Check only branches starting from a specific piece</td> </tr> <tr> <td class="name"><code>stopAtMax</code></td> <td class="type"> <span class="param-type">boolean</span> </td> <td class="description last">Stop calculation if a branch that allows all moves to be played has been found.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line368">line 368</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - Map containing maximum weight for each branch, indexed by piece ID and total maximum weight for all branches, accessed with 'max' index </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Object</span> </dd> </dl> <h4 class="name" id="countAtHigherPos"><span class="type-signature"></span>countAtHigherPos<span class="signature">(state, position, type)</span><span class="type-signature"> → {number}</span></h4> <div class="description"> Count pieces of specified type at higher positions </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">State to check</td> </tr> <tr> <td class="name"><code>position</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Normalized position (inclusive)</td> </tr> <tr> <td class="name"><code>type</code></td> <td class="type"> <span class="param-type"><a href="global.html#PieceType">PieceType</a></span> </td> <td class="description last">Type of piece (white/black)</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line175">line 175</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - Number of pieces at positions higher than position </div> <dl> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="getGameScore"><span class="type-signature">(abstract) </span>getGameScore<span class="signature">(state, player)</span><span class="type-signature"> → {boolean}</span></h4> <div class="description"> Check game state and determine how much points the player should be awared for this state. If opponent player has not borne any pieces, award 2 points. If opponent has not borne any pieces, and still has pieces in home field of player, award 3 points. In all other cases award 1 point. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">Game state</td> </tr> <tr> <td class="name"><code>player</code></td> <td class="type"> <span class="param-type"><a href="Player.html">Player</a></span> </td> <td class="description last">Player</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line788">line 788</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - True if player has won the game </div> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="getMoveActions"><span class="type-signature">(abstract) </span>getMoveActions<span class="signature">(state, piece, steps)</span><span class="type-signature"> → {Array.<<a href="MoveAction.html">MoveAction</a>>}</span></h4> <div class="description"> Call this method after a request for moving a piece has been made. Determines if the move is allowed and what actions will have to be made as a result. Actions can be `move`, `hit`, `recover` or `bear`. If move is allowed or not depends on the current state of the game. For example, if the player has pieces on the bar, they will only be allowed to recover pieces. Multiple actions can be returned, if required. Placing (or moving) a piece over an opponent's blot will result in two actions: `hit` first, then `recover` (or `move`). The list of actions returned would usually be appllied to game state and then sent to client. The client's UI would play the actions (eg. with movement animation) in the same order. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">State to change</td> </tr> <tr> <td class="name"><code>piece</code></td> <td class="type"> <span class="param-type"><a href="Piece.html">Piece</a></span> </td> <td class="description last">Piece to move</td> </tr> <tr> <td class="name"><code>steps</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Number of steps to increment towards first home position</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line612">line 612</a> </li></ul></dd> <dt class="tag-see">See:</dt> <dd class="tag-see"> <ul> <li><a href="RuleBgCasual.getMoveActions.html">RuleBgCasual.getMoveActions</a> for an example on how to implement this method</li> </ul> </dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - List of actions if move is allowed, empty list otherwise. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Array.<<a href="MoveAction.html">MoveAction</a>></span> </dd> </dl> <h4 class="name" id="hasWon"><span class="type-signature">(abstract) </span>hasWon<span class="signature">(state, player)</span><span class="type-signature"> → {boolean}</span></h4> <div class="description"> Check game state and determine if the specified player has won the game. This method assumes that the specified player was on turn and has played and confirmed his move. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">Game state</td> </tr> <tr> <td class="name"><code>player</code></td> <td class="type"> <span class="param-type"><a href="Player.html">Player</a></span> </td> <td class="description last">Player</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line766">line 766</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - True if player has won the game </div> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="havePiecesOnBar"><span class="type-signature"></span>havePiecesOnBar<span class="signature">(state, type)</span><span class="type-signature"> → {boolean}</span></h4> <div class="description"> Check if there are any pieces on the bar. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">State to check</td> </tr> <tr> <td class="name"><code>type</code></td> <td class="type"> <span class="param-type"><a href="global.html#PieceType">PieceType</a></span> </td> <td class="description last">Type of piece (white/black)</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line163">line 163</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - True if there are any pieces on the bar </div> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="hit"><span class="type-signature"></span>hit<span class="signature">(state, piece)</span><span class="type-signature"></span></h4> <div class="description"> Hit piece - send piece to bar </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">Board state</td> </tr> <tr> <td class="name"><code>piece</code></td> <td class="type"> <span class="param-type"><a href="Piece.html">Piece</a></span> </td> <td class="description last">Piece to hit</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line704">line 704</a> </li></ul></dd> </dl> <h5>Throws:</h5> <div class="param-desc"> Throws an error if there is no piece at fromPos or piece is of wrong type </div> <h4 class="name" id="incPos"><span class="type-signature">(abstract) </span>incPos<span class="signature">(position, type, steps)</span><span class="type-signature"> → {number}</span></h4> <div class="description"> Increment position by specified number of steps and return an incremented position </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>position</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Position</td> </tr> <tr> <td class="name"><code>type</code></td> <td class="type"> <span class="param-type"><a href="global.html#PieceType">PieceType</a></span> </td> <td class="description last">Type of piece</td> </tr> <tr> <td class="name"><code>steps</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Number of steps to increment towards first home position</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line152">line 152</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> Incremented position (denormalized) </div> <dl> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="initialize"><span class="type-signature"></span>initialize<span class="signature">(state)</span><span class="type-signature"></span></h4> <div class="description"> Initialize state. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">Board state to initialize</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line73">line 73</a> </li></ul></dd> </dl> <h4 class="name" id="isMoveActionRestricted"><span class="type-signature"></span>isMoveActionRestricted<span class="signature">(state, movesLeft, piece, steps)</span><span class="type-signature"> → {boolean}</span></h4> <div class="description"> Checks if a specific move action is restricted. If there are any move combinations that would allow the player to use all dice values, then the player is obliged to use one of those combination. If playing both dice values are not possible and the player should choose which one of them to play, they must play the higher value (as long as it is possible). </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">State</td> </tr> <tr> <td class="name"><code>movesLeft</code></td> <td class="type"> <span class="param-type">Array.<number></span> </td> <td class="description last">Move values left</td> </tr> <tr> <td class="name"><code>piece</code></td> <td class="type"> <span class="param-type"><a href="Piece.html">Piece</a></span> </td> <td class="description last">Piece to move</td> </tr> <tr> <td class="name"><code>steps</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Number of steps to move</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line570">line 570</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - Returns true if move is restricted (not allowed). </div> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="markAsPlayed"><span class="type-signature">(abstract) </span>markAsPlayed<span class="signature">(game, move)</span><span class="type-signature"></span></h4> <div class="description"> Mark move as played </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>game</code></td> <td class="type"> <span class="param-type"><a href="Game.html">Game</a></span> </td> <td class="description last">Game</td> </tr> <tr> <td class="name"><code>move</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Move (number of steps)</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line751">line 751</a> </li></ul></dd> </dl> <h4 class="name" id="move"><span class="type-signature"></span>move<span class="signature">(state, piece, toPos)</span><span class="type-signature"></span></h4> <div class="description"> Move piece to specified point, without enforcing any rules or performing any validation. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">Board state</td> </tr> <tr> <td class="name"><code>piece</code></td> <td class="type"> <span class="param-type"><a href="Piece.html">Piece</a></span> </td> <td class="description last">Piece to move</td> </tr> <tr> <td class="name"><code>toPos</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Position to which to move the piece to</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line654">line 654</a> </li></ul></dd> </dl> <h5>Throws:</h5> <div class="param-desc"> Throws an error if there is no piece at fromPos or piece is of wrong type </div> <h4 class="name" id="nextTurn"><span class="type-signature">(abstract) </span>nextTurn<span class="signature">(match)</span><span class="type-signature"></span></h4> <div class="description"> Proceed to next turn. Start next turn: 1. Reset turn 2. Change players 3. Roll new dice </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>match</code></td> <td class="type"> <span class="param-type"><a href="Match.html">Match</a></span> </td> <td class="description last">Match</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line823">line 823</a> </li></ul></dd> </dl> <h4 class="name" id="place"><span class="type-signature"></span>place<span class="signature">(state, number, type, position)</span><span class="type-signature"></span></h4> <div class="description"> Place one or more pieces from player set to board point. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">Board state</td> </tr> <tr> <td class="name"><code>number</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Number of pieces to place</td> </tr> <tr> <td class="name"><code>type</code></td> <td class="type"> <span class="param-type"><a href="global.html#PieceType">PieceType</a></span> </td> <td class="description last">Type of pieces to place</td> </tr> <tr> <td class="name"><code>position</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Position at which to place piece(s)</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line637">line 637</a> </li></ul></dd> </dl> <h4 class="name" id="recover"><span class="type-signature"></span>recover<span class="signature">(state, piece, position)</span><span class="type-signature"></span></h4> <div class="description"> Recover piece - place from bar to board </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">Board state</td> </tr> <tr> <td class="name"><code>piece</code></td> <td class="type"> <span class="param-type"><a href="Piece.html">Piece</a></span> </td> <td class="description last">Piece to recover</td> </tr> <tr> <td class="name"><code>position</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Position to which to place the piece</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line730">line 730</a> </li></ul></dd> </dl> <h5>Throws:</h5> <div class="param-desc"> Throws an error if there is no piece at fromPos or piece is of wrong type </div> <h4 class="name" id="resetState"><span class="type-signature">(abstract) </span>resetState<span class="signature">(state)</span><span class="type-signature"></span></h4> <div class="description"> Reset state to initial position of pieces according to current rule. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>state</code></td> <td class="type"> <span class="param-type"><a href="State.html">State</a></span> </td> <td class="description last">Board state</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line139">line 139</a> </li></ul></dd> </dl> <h4 class="name" id="rollDice"><span class="type-signature"></span>rollDice<span class="signature">(game, values<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {<a href="Dice.html">Dice</a>}</span></h4> <div class="description"> Roll dice and generate list of moves the player has to make according to current rules. Descendants rules would normally override this method in order to properly determine the allowed move values that correspond to a specific die combination (eg. doubles). </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>game</code></td> <td class="type"> <span class="param-type"><a href="Game.html">Game</a></span> </td> <td class="attributes"> </td> <td class="description last">Game object. Used to check if it is the first turn of the game.</td> </tr> <tr> <td class="name"><code>values</code></td> <td class="type"> <span class="param-type">Array.<number></span> </td> <td class="attributes"> <optional><br> </td> <td class="description last">Optional parameter containing the dice values to use, instead of generating random values. Used by some rules as RuleBgGulbara.</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line98">line 98</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - Dice object containing random values and allowed moves </div> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="Dice.html">Dice</a></span> </dd> </dl> <h4 class="name" id="validateConfirm"><span class="type-signature"></span>validateConfirm<span class="signature">(game, player)</span><span class="type-signature"> → {boolean}</span></h4> <div class="description"> Validate confirmation of moves. This is the base method for validation of moves that make a few general checks like: - Is the game started and is finished? - Is it player's turn? - Was dice rolled? - Are all moves played? - Not confirmed already? Descendant rules must extend this method and add additional validation checks according to the rule specifics. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>game</code></td> <td class="type"> <span class="param-type"><a href="Game.html">Game</a></span> </td> <td class="description last">Game</td> </tr> <tr> <td class="name"><code>player</code></td> <td class="type"> <span class="param-type"><a href="Player.html">Player</a></span> </td> <td class="description last">Player</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line296">line 296</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> True if confirmation is allowed </div> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="validateMove"><span class="type-signature"></span>validateMove<span class="signature">(game, player, piece, steps)</span><span class="type-signature"> → {boolean}</span></h4> <div class="description"> Validate piece move. This is the base method for validation of moves that make a few general checks like: - Is the game started and is finished? - Is it player's turn? - Was dice rolled? - Are moves with values equal to the steps left? Descendant rules must extend this method and add additional validation checks according to the rule specifics. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>game</code></td> <td class="type"> <span class="param-type"><a href="Game.html">Game</a></span> </td> <td class="description last">Game</td> </tr> <tr> <td class="name"><code>player</code></td> <td class="type"> <span class="param-type"><a href="Player.html">Player</a></span> </td> <td class="description last">Player requesting move</td> </tr> <tr> <td class="name"><code>piece</code></td> <td class="type"> <span class="param-type"><a href="Piece.html">Piece</a></span> </td> <td class="description last">Piece to move</td> </tr> <tr> <td class="name"><code>steps</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">Number of steps to make forward to the first home position</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line250">line 250</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> True if move is valid and should be allowed. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="validateTurn"><span class="type-signature"></span>validateTurn<span class="signature">(game, player)</span><span class="type-signature"> → {boolean}</span></h4> <div class="description"> Validate player's turn. This is the base method for validation of moves that make a few general checks like: - Is the game started and is finished? - Is it player's turn? </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>game</code></td> <td class="type"> <span class="param-type"><a href="Game.html">Game</a></span> </td> <td class="description last">Game</td> </tr> <tr> <td class="name"><code>player</code></td> <td class="type"> <span class="param-type"><a href="Player.html">Player</a></span> </td> <td class="description last">Player</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line211">line 211</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> True if move is valid and should be allowed. </div> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="validateUndo"><span class="type-signature"></span>validateUndo<span class="signature">(game, player)</span><span class="type-signature"> → {boolean}</span></h4> <div class="description"> Validate request for undoing moves. This is the base method for validation of undo that make a few general checks like: - Is the game started and is finished? - Is it player's turn? - Was dice rolled? - Are all moves played? - Not confirmed already? Descendant rules can extend this method and add additional validation checks according to the rule specifics. </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>game</code></td> <td class="type"> <span class="param-type"><a href="Game.html">Game</a></span> </td> <td class="description last">Game</td> </tr> <tr> <td class="name"><code>player</code></td> <td class="type"> <span class="param-type"><a href="Player.html">Player</a></span> </td> <td class="description last">Player</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="rules_rule.js.html">rules/rule.js</a>, <a href="rules_rule.js.html#line338">line 338</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> True if confirmation is allowed </div> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Client.html">Client</a></li><li><a href="Dice.html">Dice</a></li><li><a href="Game.html">Game</a></li><li><a href="Match.html">Match</a></li><li><a href="MoveAction.html">MoveAction</a></li><li><a href="Piece.html">Piece</a></li><li><a href="Player.html">Player</a></li><li><a href="PlayerStats.html">PlayerStats</a></li><li><a href="Random.html">Random</a></li><li><a href="Rule.html">Rule</a></li><li><a href="RuleBgCasual.html">RuleBgCasual</a></li><li><a href="RuleBgGulbara.html">RuleBgGulbara</a></li><li><a href="RuleBgTapa.html">RuleBgTapa</a></li><li><a href="State.html">State</a></li><li><a href="Utils.html">Utils</a></li></ul><h3>Global</h3><ul><li><a href="global.html#Message">Message</a></li><li><a href="global.html#MoveActionType">MoveActionType</a></li><li><a href="global.html#PieceType">PieceType</a></li><li><a href="global.html#Protocol">Protocol</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Sun Dec 18 2016 20:10:05 GMT+0200 (EET) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>