Standard library
Every function and method rules expressions may call, with its signature, generated from the standard library manifest. The page is rebuilt from the platform's contracts each time the site is built, so it always matches what the checker accepts.
This is version 1.0 of the standard library. A function is called by name, as inallSeats(); a method is called on a value, as in hand[self].count(). A parameter marked ? may be left out, and one marked named is passed by name, as inscoreSum(asOwner: s). Single capital letters, such as T, stand for any type.
The checker accepts every entry here. A few, used only by games that don't play on the engine yet, aren't run by the engine yet either: rules that call one fail when play reaches the call.
Collections
all
list<T>.all(predicate?: (T) -> bool) -> boolTrue if every item satisfies the predicate (every item is true, without one); true for an empty list.
any
list<T>.any(predicate?: (T) -> bool) -> boolTrue if some item satisfies the predicate (the list isn't empty, without one).
concat
concat(first: list<T>, second: list<T>) -> list<T>The first list followed by the second.
list<T>.concat(other: list<T>) -> list<T>The list followed by the other list.
contains
list<T>.contains(item: T) -> boolTrue if the list holds the item.
count
list<T>.count(predicate?: (T) -> bool) -> intThe number of items, or of items that satisfy the predicate.
distinct
list<T>.distinct() -> list<T>The items without repeats, keeping each first occurrence in order.
distinctBy
list<T>.distinctBy(key: (T) -> U) -> list<T>The items without repeated keys, keeping each key's first item in order.
first
list<T>.first(predicate?: (T) -> bool) -> TThe first item, or the first that satisfies the predicate; an error if there is none.
firstOrNull
list<T>.firstOrNull(predicate?: (T) -> bool) -> T?The first item, or the first that satisfies the predicate; null if there is none.
groupCount
list<T>.groupCount() -> map<T,int>How many times each item occurs, keyed in first-occurrence order.
indexOf
list<T>.indexOf(item: T) -> intThe item's zero-based position, or -1 if absent.
isEmpty
list<T> | zone | map<K,V>.isEmpty() -> boolTrue if the list, zone or map has no items.
last
list<T>.last() -> TThe last item; an error for an empty list.
max
list<T>.max(selector?: (T) -> int) -> int?The largest item, or the largest selector value; null for an empty list.
min
list<T>.min(selector?: (T) -> int) -> int?The smallest item, or the smallest selector value; null for an empty list.
ofType
list<T>.ofType(type: componentType<U>) -> list<U>The items of a component type, in order.
orderBy
list<T>.orderBy(key: (T) -> U) -> list<T>The items sorted by the key, ascending.
Stable: keeps the input order for equal keys.
orderByDescending
list<T>.orderByDescending(key: (T) -> U) -> list<T>The items sorted by the key, descending.
Stable: keeps the input order for equal keys.
select
list<T>.select(selector: (T) -> U) -> list<U>Each item mapped by the selector, in order.
selectMany
list<T>.selectMany(selector: (T) -> list<U>) -> list<U>Each item's list from the selector, concatenated in order.
shuffled
list<T>.shuffled() -> list<T>The items in a random order.
Draws from the match's random stream: allowed only in effect arguments.
sum
list<T>.sum(selector?: (T) -> int) -> intThe sum of the items, or of the selector's values; 0 for an empty list. Overflow is an error.
thenBy
list<T>.thenBy(key: (T) -> U) -> list<T>A further ascending key for items equal under the previous ordering.
Stable: keeps the input order for equal keys.
thenByDescending
list<T>.thenByDescending(key: (T) -> U) -> list<T>A further descending key for items equal under the previous ordering.
Stable: keeps the input order for equal keys.
where
list<T>.where(predicate: (T) -> bool) -> list<T>The items that satisfy the predicate, in order.
whereNotNull
list<T?>.whereNotNull() -> list<T>The items that aren't null, in order.
Maps
at
map<K,T> | zone.at(key: K) -> T?The value or component at a key or position; null if there is none.
containsKey
map<K,V>.containsKey(key: K) -> boolTrue if the map has the key.
items
zone | map<K,T>.items() -> list<T>A zone's components in order, or a map's values in insertion order.
keys
map<K,V>.keys() -> list<K>The map's keys in insertion order.
plus
map<K,int>.plus(other: map<K,int>) -> map<K,int>A copy of the counts with the other counts added key by key.
with
map<K,V>.with(key: K, value: V) -> map<K,V>A copy of the map with the key set to the value.
Numbers
abs
abs(value: int) -> intThe absolute value. abs of the smallest int is an overflow error.
ceil
ceil(dividend: int, divisor: int) -> intThe quotient rounded toward positive infinity.
See floor.
die
die(faces: int) -> intA die roll from 1 to faces.
Draws from the match's random stream: allowed only in effect arguments.
floor
floor(dividend: int, divisor: int) -> intThe quotient rounded toward negative infinity: floor(a, b) for a / b.
`/` truncates toward zero; floor, ceil and round make other rounding explicit.
max
max(a: int, b: int, c?: int) -> intThe largest of the values.
max(values: list<int>) -> int?The largest item of a list; null for an empty list.
min
min(a: int, b: int, c?: int) -> intThe smallest of the values.
random
random(items: list<T>) -> TA random item of a non-empty list.
Draws from the match's random stream: allowed only in effect arguments.
range
range(start: int, end?: int) -> list<int>The integers from start (inclusive) to end (exclusive); range(n) is 0 to n.
round
round(dividend: int, divisor: int) -> intThe quotient rounded to the nearest integer, halves away from zero.
See floor.
sign
sign(value: int) -> int-1, 0 or 1 by the value's sign.
Seats
allSeats
allSeats() -> list<seat>Every seat, including neutral ones, in seat order.
andNeighbors
seat.andNeighbors() -> list<seat>The seat and its two neighbors.
currentSeat
currentSeat() -> seatThe seat whose turn it is.
leftOf
leftOf(of: seat) -> seatThe seat to the left.
seat.leftOf(of: seat) -> seatThe seat to the left of the given seat.
neighbors
seat.neighbors(distance?: int) -> list<seat>The seats to the left and right (or within distance on the given side).
opponent
opponent(of: seat) -> seatThe other seat in a two-seat game.
seat.opponent() -> seatThe other seat in a two-seat game.
playingSeats
playingSeats() -> list<seat>The seats of players still in the game, in seat order.
rightOf
rightOf(of: seat) -> seatThe seat to the right.
seat.rightOf(of: seat) -> seatThe seat to the right of the given seat.
seat
seat(key: string | int) -> seatA seat by name (white) or by zero-based index.
seatsOfRole
seatsOfRole(role: role) -> list<seat>The seats holding a role (v0.2).
sideOf
sideOf(of: any) -> sideThe side a seat or a controlled node belongs to (team games, v0.2).
turnOrder
turnOrder() -> list<seat>The playing seats in the current turn order.
Flow
arrivalOrder
arrivalOrder() -> list<seat>Seats in the order their simultaneous moves arrived (v0.3).
isLegal
isLegal(action: string, seat: seat, argument?: any) -> boolTrue if the seat could take the action now, with the given arguments.
modified
modified(key: string, seat: seat, value: T, subject?: any) -> TThe value after every active modifier matching the key applies to it (v0.2). The value may be any type: an int, a bool or a cost.
pendingOffer
pendingOffer(action: action) -> boolTrue if an offer of this action is waiting for an answer.
phase
phase() -> stringThe current phase's name.
step
step() -> stringThe current step's name within the phase.
timeLeft
timeLeft(timer: string) -> intMilliseconds left on the named timer (v0.3).
timerExpired
timerExpired(timer: string) -> boolTrue if the named timer has run out (v0.3).
variant
variant(id: string) -> boolTrue if the match was created with the variant.
variantOption
variantOption(id: string) -> stringThe option chosen for a variant that has options, such as 'randomShared'.
nextTurnStart
nextTurnStart(seat: seat) -> timeThe start of a seat's next turn, for schedule's at.
eventLog
eventLog(name: string, seat: seat, when: string) -> list<event>The events with a name a seat raised this turn ('this') or in its last turn ('last'), in the order raised.
Components
abilities
seat.abilities(kind: string) -> list<ability>The seat's abilities of a kind, in the order gained.
data
data(component: component) -> rowA component's data-table row.
hasAbility
seat.hasAbility(kind: string) -> boolTrue if the seat has an ability of this kind.
holderOf
holderOf(component: component) -> seat?The seat holding the component; null if none.
holds
holds(seat: seat, component: component) -> boolTrue if the seat holds the component.
holdsFor
expr<bool>.holdsFor(subject: any, seat?: seat) -> boolEvaluates a requirement stored as data for a component and seat.
valueFor
expr<int>.valueFor(subject: any, seat: seat) -> intEvaluates a value stored as data for a component and seat.
Zones
bottom
zone.bottom() -> component?The bottom component of a stack zone; null if it's empty.
top
zone.top() -> component?The top component of a stack zone; null if it's empty.
Grids
allPieces
allPieces() -> list<piece>Every piece on the board, in board order.
cells
board | shape.cells(level?: int) -> list<square>A board's or shape's cells in board order, optionally of one level.
connectedComponents
connectedComponents(items: list<T>, connected: (T, T) -> bool) -> list<list<T>>The groups of items connected by the relation, in first-item order (v0.3).
fits
board.fits(shape: shape, covered: list<square>, size: int) -> list<placement>Every placement of a shape that fits the covered cells on the board.
floodFill
floodFill(start: T, connected: (T, T) -> bool) -> list<T>The items reachable from the start through the relation (v0.3).
hexDistance
hexDistance(a: hex, b: hex) -> intThe number of hex steps between two hexes.
offset
offset(from: square, files: int, ranks: int) -> square?The square at a file and rank offset; null if off the board.
pieceAt
pieceAt(at: square) -> piece?The piece on a square; null if empty.
pieces
pieces(seat: seat) -> list<piece>A seat's pieces on the board, in board order.
ray
ray(from: square, files: int, ranks: int, named stopAtOccupied?: bool) -> list<square>The squares in a direction until the edge (or the first occupied square, included).
regions
board.regions() -> list<list<node>>The board's regions, each a list of nodes, in board order.
rotations
rotations(cells: list<square>, named mirror?: bool) -> list<shape>A shape's distinct rotations, and mirror images when asked.
square
square(file: any, rank: int) -> squareThe square at a file and rank.
squareWindows
squareWindows(boardSize: int, windowSize: int) -> list<list<square>>Every square window of the given size on the board (v0.3).
step
board.step(from: square, direction: direction) -> square?The neighboring cell in a direction; null if off the board.
Graphs
adjacent
board.adjacent(a: any, b: any) -> boolTrue if two nodes or cells are next to each other.
board.adjacent(of: node, named noGap?: bool) -> list<node>The nodes next to a node; with noGap, skipping empty spaces to the next occupied one in each direction.
connected
board.connected(a: node, b: node, named via?: (link) -> bool) -> boolTrue if two nodes are joined by links the filter accepts.
distance
board.distance(a: node, b: node, named via?: (link) -> bool) -> int?The fewest links between two nodes through links the filter accepts; null if unreachable.
ends
link.ends() -> list<node>A link's two endpoints.
links
board.links(node?: node) -> list<link>The links touching a node, or every link when none is given, in board order.
other
link.other(node: node) -> nodeA link's endpoint that isn't the given node.
paths
board.paths(named from?: node, named minSteps?: int, named maxSteps?: int, named via?: (link) -> bool, named countIf?: (node) -> bool, named stopAt?: (node) -> bool, named exclude?: list<node>) -> list<path>The paths from a node within the step limits, in a defined order.
reachable
board.reachable(named from?: node, named min?: int, named max?: int, named backward?: bool, named skip?: (node) -> bool, named via?: (link) -> bool) -> list<node>The nodes reachable from a node within the limits.
touches
link.touches(node: node) -> boolTrue if the link has the node as an endpoint.
Scoring
scoreSum
list<component>.scoreSum(named asOwner?: seat) -> intThe sum of the components' scoring abilities.
totalScore
totalScore(seat: seat) -> intA seat's total score so far.
choices
seat.choices(ability: string) -> list<any>A seat's choices for an ability's scoring choice, one per instance of the ability; empty before scoring.
Solvers
paymentPlans
paymentPlans(cost: cost, named payer?: seat, named own?: list<production>, named buyFromBank?: (resource) -> int, named sellers?: list<any>, named rebate?: int, named price?: (side, resource) -> int, named substitutes?: list<(amount: int, value: int)>, named overpayRefund?: bool, named budget?: int) -> list<plan>Every way the payer can cover a cost from own production, purchases and rebates, cheapest first.
On a tie, the first match in collection order.
production
seat.production(kind?: string, named tradableOnly?: bool) -> list<production>What the seat produces, for payment plans.