Class: CypherPokerGame

CypherPokerGame(cypherpokerRef, tableObj, playerInfoopt, ContractClassopt)

Manages game logic, CypherPokerPlayer, CypherPokerContract, and CypherPokerAnalyzer instances, and other game-specific properties for a single CypherPoker.JS Texas Hold'em game (hand).

Constructor

new CypherPokerGame(cypherpokerRef, tableObj, playerInfoopt, ContractClassopt)

Creates a new game instance.
Parameters:
Name Type Attributes Default Description
cypherpokerRef CypherPoker A reference to the parent or containing CypherPoker instance that created the game instance.
tableObj CypherPoker#TableObject The table associated with the game instance. A copy of this object is available through the table reference.
playerInfo Object <optional>
null Contains additional information about us to share with the table.
ContractClass String <optional>
"CypherPokerContract" The (smart) contract interface to use with this game (available through the contract property). If null, no contract interface is used.
Source:

Extends

Members

analyzer

Properties:
Name Type Description
analyzer CypherPokerAnalyzer The current analyzer instance associated with this game.
Source:

autoBlinds

Properties:
Name Type Default Description
autoBlinds Boolean true If true, the required blind amount for the table are posted automatically if we're playing as a blind, otherwise the blind amount will need to be posted via the placeBet function.
Source:

bettingDone

Properties:
Name Type Description
bettingDone Boolean True if all non-folded players have committed the same bet amount, or if all players but one have folded (new cards may be dealt or the game has completed).
Source:

canBet

Properties:
Name Type Description
canBet Boolean If true, we can place a bet, check/call, or fold via the placeBet function.
Source:

canDeal

Properties:
Name Type Description
canDeal Boolean If true, we can initiate the next round of card dealing (private or public), via the dealCards function.
Source:

(readonly) cardDecks

Properties:
Name Type Description
cardDecks Object Stores card decks for the game.
Properties
Name Type Description
faceup Array Indexed array of CypherPokerCard instances containing the face-up or unencrypted deck. The contents of this array should not change during a game (hand).
facedown Array Indexed array of strings representing the face-down or encrypted deck. As cards are drawn they're moved to the dealt array.
dealt Array Indexed array of strings representing the face-down or encrypted deck that have been dealt from the facedown array.
public Array Indexed array of unencrypted or face-up CypherPokerCard instances that have been dealt as public or community cards.
Source:

(readonly) contract

Properties:
Name Type Description
contract CypherPokerContract A CypherPoker (smart) contract interface associated with this instance, usually created at instantiation.
Source:

(readonly) cypherpoker

Properties:
Name Type Description
cypherpoker CypherPoker Reference to the parent or containing CypherPoker instance used to create this game, as provided at instantiation.
Source:

DOMElement

Properties:
Name Type Default Description
DOMElement HTMLElement null A reference to the DOM element associated with this game instance. Typically this reference is set by an external user interface manager.
Source:

gameDone

Properties:
Name Type Description
gameDone Boolean True if the current game (hand), and all associated betting rounds have completed. Verification and other post-game actions can take place once a game is done.
Source:

(readonly) gameEnding

Properties:
Name Type Default Description
gameEnding Boolean false True if the game is currently ending (game play has completed but verification/validation has not).
Source:

(readonly) gameParams

Properties:
Name Type Description
gameParams Object Game-related parameters.
Properties
Name Type Description
prime String The current prime modulus value for the game. Previous prime values are stored in keypair instances in the CypherPokerPlayer.keychain array.
Source:

(readonly) gameStarted

Properties:
Name Type Default Description
gameStarted Boolean false True if the game has been started (all players have introduced themselves and game parameters have been set).
Source:

largestBet

Properties:
Name Type Description
largestBet BigInteger The largest bet currently placed by a non-folded player at the table.
Source:

messageQueue

Properties:
Name Type Description
messageQueue Array Peer-to-peer message events that have been queued while gameEnding is true. Message events are stored in order of age of receipt with the most recent events appearing last.
Source:

minimumBet

Properties:
Name Type Description
minimumBet BigInteger The minimum bet that must be placed by us during this round of betting in order to continue playing.
Source:

(readonly) ownPID

Properties:
Name Type Description
ownPID String Our own private ID as generated through the parent CypherPoker instance's p2p interface.
Source:

(readonly) players

Properties:
Name Type Description
players Array An array of CypherPokerPlayer instances associated with the game.
Source:

pot

Properties:
Name Type Description
pot BigInteger The amount currently in the pot for the game.
Source:

(readonly) table

Properties:
Name Type Description
table CypherPoker#TableObject A copy of the table associated with this game provided at instantiation. Note that this is not a reference to the original table object provided to the constructor.
Source:

Methods

addEventListener(type, listener, contextopt)

Registers a new event listener with the extending class instance.
Parameters:
Name Type Attributes Default Description
type String The event type to register.
listener function The listening function to invoke on the event.
context Object <optional>
null Unlike the traditional addEventListener parameter, this is the context or scope in which to invoke the listening function (since we can't use capture phases). If null, the listener is invoked in the context of the EventDispatcher or extending instance.
Inherited From:
Source:

(async) dealCards(numCardsopt) → {Promise}

Deals cards by removing random selections from the cardDecks.facedown array, adding them them the cardDecks.dealt array, sending the resulting arrays to the table, and requesting a decryption for the selections.
Parameters:
Name Type Attributes Default Description
numCards Number <optional>
0 The number of cards to select. If this value is less than 1, the required cards are automatically determined using our CypherPokerPlayer.dealtCards array or the cardDecks.public array, depending on the current game state.
Source:
Fires:
Returns:
The promise resolves with an array of selected face-down or encrypted card values, or rejects with an error if something went wrong.
Type
Promise

destroy()

Prepares the instance to be removed from memory by clearing all references, event listeners, etc.
Source:

(async) endGame() → {Promise}

Ends the current game (hand), and sends keyring to other players for verification.
Source:
Fires:
Returns:
Resolves with a result of true when the game is completely ended and optionally restarted.
Type
Promise

gameExists(tableObj) → {Boolean}

Checks if a game associated with a specific TableObject instance is registered with the parent CypherPoker instance.
Parameters:
Name Type Description
tableObj CypherPoker#TableObject The associated table to check for.
Source:
Returns:
True if the table has been associated with an existing CypherPokerGame instance in the parent CypherPoker.
Type
Boolean

getBigBlind() → {CypherPokerPlayer}

Returns the CypherPokerPlayer that is currently flagged as the big blind in the players array.
Source:
Returns:
The CypherPokerPlayer instance that is flagged as a big blind. null is returned if no big blind is flagged.
Type
CypherPokerPlayer

getCardDecks() → {Object}

Returns a condensed object containing the copied properties of the cardDecks object. Use the object returned by this function with JSON.stringify instead of using cardDecks directly in order to prevent circular reference errors.
Source:
Returns:
The condensed cardDecks object associated with this game instance.
Type
Object

getDealer() → {CypherPokerPlayer}

Returns the CypherPokerPlayer that is currently flagged as the dealer in the players array.
Source:
Returns:
The CypherPokerPlayer instance that is flagged as a dealer. null is returned if no dealer is flagged.
Type
CypherPokerPlayer

getListeners(type) → {Array}

Returns all registered listeners for a specific event type.
Parameters:
Name Type Description
type String The event type to return registered listeners for.
Inherited From:
Source:
Returns:
A list of registered event listener objects for the specific event. Each object contains a listener function reference and an execution context reference.
Type
Array

getMappedCard(mapping) → {CypherPokerCard}

Returns a CypherPokerCard instance from the cardDecks.faceup array based on its mapping.
Parameters:
Name Type Description
mapping String The card mapping (quadratic residue value), of the card to retrieve.
Source:
Returns:
The matching card instance or null if no such card exists.
Type
CypherPokerCard

getNextPlayer(privateID) → {CypherPokerPlayer}

Returns the CypherPokerPlayer that appears after a specified player in the players array.
Parameters:
Name Type Description
privateID String The private ID of the player preceding the player to return.
Source:
Returns:
The CypherPokerPlayer instance that follows the player specified by the parameter. null is returned if no matching player private ID can be found.
Type
CypherPokerPlayer

getPlayer(privateID) → {CypherPokerPlayer}

Returns a CypherPokerPlayer instance associated with this game instance.
Parameters:
Name Type Description
privateID String The private ID of the player.
Source:
Returns:
The CypherPokerPlayer for the private ID associated with this game. null is returned if no matching player private ID can be found.
Type
CypherPokerPlayer

getPlayerInfo(privateID) → {Object}

Returns a player information object for a specific private ID associated with this game.
Parameters:
Name Type Description
privateID String The private ID of the player associated with this game for which to return the information object.
Source:
Returns:
An information object for the specified private ID or null if no such private ID has an information object associated with this game.
Type
Object

getPlayers(includeKeychainsopt, includePasswordsopt) → {Object}

Returns a condensed array containing the copied properties of the players array. Use the object returned by this function with JSON.stringify instead of using players directly in order to prevent circular reference errors.
Parameters:
Name Type Attributes Default Description
includeKeychains Boolean <optional>
false If true, the CypherPokerPlayer.keychain array of each player will be included in the returned object.
includePasswords Boolean <optional>
false If true, the CypherPokerAccount.password property of each CypherPokerPlayer.account reference will be included with the returned object.
Source:
Returns:
The condensed players array associated with this game instance.
Type
Object

getPreviousPlayer(privateID) → {CypherPokerPlayer}

Returns the CypherPokerPlayer that appears before a specified player in the players array.
Parameters:
Name Type Description
privateID String The private ID of the player following the player to return.
Source:
Returns:
The CypherPokerPlayer instance that precedes the player specified by the parameter. null is returned if no matching player private ID can be found.
Type
CypherPokerPlayer

getSmallBlind() → {CypherPokerPlayer}

Returns the CypherPokerPlayer that is currently flagged as the small blind in the players array.
Source:
Returns:
The CypherPokerPlayer instance that is flagged as a small blind. null is returned if no small blind is flagged.
Type
CypherPokerPlayer

getTable() → {Object}

Returns a condensed object containing the copied properties of the table object. Use the object returned by this function with JSON.stringify instead of using table directly in order to prevent circular reference errors.
Source:
Returns:
The condensed table object associated with this game instance.
Type
Object

(async) killGame(reason) → {Promise}

Kills the current game (hand), and stops any further actions. Usually this function is called on a fatal error such as when an associated contract can't be agreed to (e.g. insufficient funds).
After killing a game the instance should be destroyed and removed from memory.
Parameters:
Name Type Description
reason String A human-readable explanation of why the game is being killed.
Source:
Fires:
Returns:
Resolves with a result of true when all game functionality has been successfully stopped and all data cleared.
Type
Promise

placeBet(betAmount) → {Promise}

Places a bet during the current round of betting, if allowed, and sends the action to other players at the table.
Parameters:
Name Type Description
betAmount Number | String The bet amount to place. A 0 bet is a check or call and a bet of less than 0 is a fold.
Source:
Fires:
Returns:
The promise is resolved with a true result if the bet was successfully placed and rejected with an Error if the bet could not be placed.
Type
Promise

removeEventListener(type, listener, contextopt)

Removes an event listener from the extending instance.
Parameters:
Name Type Attributes Default Description
type String The event type to remove the function from.
listener function The listening function to remove.
context Object <optional>
null The context or scope in which the listener exists.
Inherited From:
Source:

resetPlayerStates(resetBetopt, resetHasBetopt, resetHasFoldedopt)

Resets the betting states of all players associated with this game instance.
Parameters:
Name Type Attributes Default Description
resetBet Boolean <optional>
false If true, the CypherPokerPlayer.totalBet amount is set to 0.
resetHasBet Boolean <optional>
false If true, the CypherPokerPlayer.hasBet flag is set to false.
resetHasFolded Boolean <optional>
false If true, the CypherPokerPlayer.hasFolded flag is set to false.
Source:

(async) restartGame(contextopt) → {Promise}

Attempts to restart the game by resetting all cards and player selections, shifting player roles, and finally starting the game (if we're the current dealer). If the game is awaiting analysis, the restart is held until complete.
Parameters:
Name Type Attributes Default Description
context CypherPokerGame <optional>
null The game context in which to execute the restart. If null, this is assumed.
Source:
Fires:
Returns:
Resolves to true when game is immediately restarted, and false if the game is awaiting analysis (is paused).
Type
Promise

sendToPlayers(messageType, payloadopt, privateIDsopt)

Sends a message to player(s) associated with this game. Table information is automatically appended to the message.
Parameters:
Name Type Attributes Default Description
messageType String The CypherPoker.JS message type to send to recipients. This should begin with "game" in order to prevent conflicts with other peer-to-peer message types.
payload Object <optional>
null Additional data to include with the message's payload property.
privateIDs Array <optional>
null The private ID(s) of the target(s) / recipient(s). If null, the list of recipients comes from the associated table.joinedPID array.
Source:

start() → {CypherPokerGame}

Starts the game instance and notifies other players that it's ready. This function should only be called when all game settings have been loaded, references set, etc.
Source:
Returns:
A reference to the current instance.
Type
CypherPokerGame

Events

gameanalyze

The game is about to end and should have its state saved for analysis.
Type:
  • Event
Properties:
Name Type Description
game CypherPokerGame The game instance reporting that it's about to end.
table CypherPoker#TableObject The table associated with the game instance.
Source:

gamebet

A bet has been placed by another player.
Type:
  • Event
Properties:
Name Type Description
amount String The amount of the bet.
player CypherPokerPlayer The player that placed the bet.
game CypherPokerGame The game instance associated with the received bet.
table CypherPoker#TableObject The table associated with the received bet.
Source:

gamebetplaced

A bet has been placed by us.
Type:
  • Event
Properties:
Name Type Description
amount String The amount of the bet, in the smallest denomination of the cryptocurrency.
player CypherPokerPlayer Reference to our own player object.
game CypherPokerGame The game instance associated with the bet.
table CypherPoker#TableObject The table associated with the bet.
Source:

gamecardsencrypt

An encryption operation has been completed by us or another player. Note that the current dealer generates the current faceup deck.
Type:
  • Event
Properties:
Name Type Description
selected Array Array of numeric strings representing the partially encrypted card values.
player CypherPokerPlayer The player that sent the encrypted cards.
game CypherPokerGame The game instance associated with the message.
table CypherPoker#TableObject The table associated with the message.
Source:

gamedeal

New public or private cards have been fully decrypted and dealt into play.
Type:
  • Event
Properties:
Name Type Description
cards Array Indexed array of CypherPokerCard instances representing the newly dealt, face-up cards.
private Boolean If true, the cards array contains private / hole cards otherwise it contains public / community cards.
game CypherPokerGame The game instance associated with the deal.
table CypherPoker#TableObject The table associated with the deal.
Source:

gamedealmsg

A "gamedeal" message was received via the peer-to-peer channel and has not yet been processed.
Type:
  • Event
Properties:
Name Type Description
data Object {Object} data The JSON-RPC 2.0 object containing the message.
player CypherPokerPlayer The player that sent message.
game CypherPokerGame The game instance associated with the message.
table CypherPoker#TableObject The table associated with the message.
Source:

gamedealprivate

We have selected private cards which are about to be sent to other players for decryption. The selected cards have been removed from the CypherPokerGame#cardDecks.facedown array and added to the CypherPokerGame#cardDecks.dealt array.
Type:
  • Event
Properties:
Name Type Description
selected Array Indexed array of strings representing the encrypted private cards we've selected.
player CypherPokerPlayer The player that selected the cards (us).
game CypherPokerGame The game instance associated with the deal.
table CypherPoker#TableObject The table associated with the deal.
Source:

gamedealpublic

We have selected public cards which are about to be sent to other players for decryption. The selected cards have been removed from the CypherPokerGame#cardDecks.facedown array and added to the CypherPokerGame#cardDecks.dealt array.
Type:
  • Event
Properties:
Name Type Description
selected Array Indexed array of strings representing the encrypted public cards we've selected.
player CypherPokerPlayer The player that selected the cards (us).
game CypherPokerGame The game instance associated with the deal.
table CypherPoker#TableObject The table associated with the deal.
Source:

gamedeck

A new card deck (sequential quadratic residues), has been generated for the game. The deck is available as an array of CypherPokerCard instances in CypherPokerGame#cardDecks.faceup.
Type:
  • Event
Properties:
Name Type Description
data Object The JSON-RPC 2.0 object containing the message. If we've created the deck (as dealer), this object is null.
player CypherPokerPlayer The player that sent message.
game CypherPokerGame The game instance reporting as ready.
table CypherPoker#TableObject The table associated with the game instance.
Source:

gamedecrypt

New public or private cards have been partially decrypted and forwarded to the next player for processing.
Type:
  • Event
Properties:
Name Type Description
payload Object The payload property of the data property of the received JSON-RPC 2.0 result object.
selected Array Indexed array of strings representing the partially-encrypted public or private cards.
private Boolean If true, the selected array contains private / hole cards otherwise it contains public / community cards.
game CypherPokerGame The game instance associated with the decryption operation.
table CypherPoker#TableObject The table associated with the decryption operation.
Source:

gameend

The game (hand) has ended because either all but one player have folded or all cards have been dealt and all rounds of betting have completed.
Type:
  • Event
Properties:
Name Type Description
game CypherPokerGame The game instance reporting as ready.
table CypherPoker#TableObject The table associated with the game instance.
Source:

gamehello

A "hello" or introduction message was received from a player at this table.
Type:
  • Event
Properties:
Name Type Description
data Object The JSON-RPC 2.0 object containing the message.
player CypherPokerPlayer The player that sent message. This instance's info object was updated.
game CypherPokerGame The game instance reporting as ready.
table CypherPoker#TableObject The table associated with the game instance.
Source:

gamekeypair

A new keypair has been generated for us by the generateKeypair function.
Type:
  • Event
Properties:
Name Type Description
keypair Object A new keypair derived from the CypherPokerGame#gameParams.prime value.
player CypherPokerPlayer The player for whom the keypair was created. If the generateKeypair function was invoked with the storeKeypair parameter set to false, this property will be null.
game CypherPokerGame The game instance that generated the keypair.
table CypherPoker#TableObject The table associated with the game instance.
Source:

gamekill

The game (hand) has encountered an unexpected fatal error and can't continue. No further game actions will take place and the game instance will no longer listen for external messages or events.
Type:
  • Event
Properties:
Name Type Description
game CypherPokerGame The game instance reporting as ready.
table CypherPoker#TableObject The table associated with the game instance. * @property {CypherPokerContract} contract The contract instance associated with the game instance.
reason String A human-readable explanation of the cause of the fatal game end.
Source:

gameparams

New parameters for the game have been set or received by/from the dealer.
Type:
  • Event
Properties:
Name Type Description
data Object The JSON-RPC 2.0 object containing the message. If we've set the parameters (as dealer), this object is null.
player CypherPokerPlayer The player that sent message.
game CypherPokerGame The game instance reporting as ready.
table CypherPoker#TableObject The table associated with the game instance.
Source:

gameplayerkeychain

A keychain has been received for a specific player, usually at the end of a game as part of the verification process.
Type:
  • Event
Properties:
Name Type Description
keychain Array Array of keypair objects submitted by the player.
player CypherPokerPlayer The player that send their keyring.
game CypherPokerGame The game instance associated with the message.
table CypherPoker#TableObject The table associated with the message.
Source:

gameplayerready

A player is notifying us that their game is ready (i.e. they received a "gameready" event).
Type:
  • Event
Properties:
Name Type Description
data Object The JSON-RPC 2.0 object containing the message.
player CypherPokerPlayer The player sending the notification.
game CypherPokerGame The game to which the player belongs.
table CypherPoker#TableObject The table to which the player and game belong.
Source:

gameready

This game instance is signalling that it is ready to start (all startup data has been loaded, references set, etc.)
Type:
  • Event
Properties:
Name Type Description
game CypherPokerGame The game instance reporting as ready.
table CypherPoker#TableObject The table associated with the game instance.
Source:

gamerestart

The game instance has been reset and is about to restart.
Type:
  • Event
Properties:
Name Type Description
game CypherPokerGame The game instance about to restart.
table CypherPoker#TableObject The table associated with the game instance.
Source:

gamescored

The most recently completed game (hand) has been analyzed and scored.
Type:
  • Event
Properties:
Name Type Description
analyzer CypherPokerAnalyzer The analyzer instance reporting the results.
game CypherPokerGame The game instance from which the results were generated. Note that the game may have been reset (lost most data), prior to the completion of the analysis.
table CypherPoker#TableObject The table associated with the game instance. As with the game property, the table may have changed prior to the completion of the analysis.
Source: