Skip to main content

Class: PlayerCollection<P>

An Array-like collection of the game's players, mainly used in Game#players. The array is automatically created when the game begins and can be used to determine or alter play order. The order of the array is the order of play, i.e. game.players[1] takes their turn right after game.players[0].

Type parameters​

NameType
Pextends Player

Hierarchy​

  • Array<P>

    ↳ PlayerCollection

Properties​

currentPosition​

• currentPosition: number[] = []

An array of table positions that may currently act.

Defined in​

boardzilla-core/src/player/collection.ts:22


game​

• game: P["game"]

A reference to the Game class

Defined in​

boardzilla-core/src/player/collection.ts:27

Methods​

atPosition​

▸ atPosition(position): undefined | P

Returns the player at a given table position.

Parameters​

NameType
positionnumber

Returns​

undefined | P

Defined in​

boardzilla-core/src/player/collection.ts:41


current​

▸ current(): undefined | P

Returns the player that may currently act. It is an error to call current when multiple players can act

Returns​

undefined | P

Defined in​

boardzilla-core/src/player/collection.ts:49


allCurrent​

▸ allCurrent(): P[]

Returns the array of all players that may currently act.

Returns​

P[]

Defined in​

boardzilla-core/src/player/collection.ts:57


host​

▸ host(): P

Returns the host player

Returns​

P

Defined in​

boardzilla-core/src/player/collection.ts:64


notCurrent​

▸ notCurrent(): P[]

Returns the array of players that may not currently act.

Returns​

P[]

Defined in​

boardzilla-core/src/player/collection.ts:71


inPositionOrder​

▸ inPositionOrder(): PlayerCollection<P>

Returns the array of players in the order of table positions. Does not alter the actual player order.

Returns​

PlayerCollection<P>

Defined in​

boardzilla-core/src/player/collection.ts:79


setCurrent​

▸ setCurrent(players): void

Set the current player(s).

Parameters​

NameTypeDescription
playersnumber | number[] | P | P[]The Player or table position of the player to act, or an array of either.

Returns​

void

Defined in​

boardzilla-core/src/player/collection.ts:89


next​

▸ next(): P

Advance the current player to act to the next player based on player order.

Returns​

P

Defined in​

boardzilla-core/src/player/collection.ts:98


after​

▸ after(player): P

Return the next player to act based on player order.

Parameters​

NameType
playernumber | P

Returns​

P

Defined in​

boardzilla-core/src/player/collection.ts:110


seatedNext​

▸ seatedNext(player, steps?): P

Return the player next to this player at the table.

Parameters​

NameTypeDefault valueDescription
playerPundefined-
stepsnumber11 = one step to the left, -1 = one step to the right, etc

Returns​

P

Defined in​

boardzilla-core/src/player/collection.ts:118


turnOrderOf​

▸ turnOrderOf(player): number

Returns the turn order of the given player, starting with 0. This is distinct from Player#position. Turn order can be altered during a game, whereas table position cannot.

Parameters​

NameType
playernumber | P

Returns​

number

Defined in​

boardzilla-core/src/player/collection.ts:127


sortBy​

▸ sortBy(key, direction?): PlayerCollection<P>

Sorts the players by some means, changing the turn order.

Parameters​

NameTypeDescription
keySorter<P> | Sorter<P>[]A key of function for sorting, or a list of such. See Sorter
direction?"desc" | "asc""asc" to cause players to be sorted from lowest to highest, "desc" for highest to lower

Returns​

PlayerCollection<P>

Defined in​

boardzilla-core/src/player/collection.ts:141


sortedBy​

▸ sortedBy(key, direction?): PlayerCollection<P>

Returns a copy of this collection sorted by some Sorter.

Parameters​

NameTypeDefault value
keySorter<P> | Sorter<P>[]undefined
direction"desc" | "asc""asc"

Returns​

PlayerCollection<P>

Defined in​

boardzilla-core/src/player/collection.ts:159