# Infinity reels

> The board gains reels on the right after the spin lands, as many as the result asks for.

Source: https://pixi-reels.schmooky.dev/mechanics/infinity-reels/

In an infinity reels slot the base spin lands, and while the win keeps going
the board grows sideways, a reel at a time, for as long as the server's
result says. In pixi-reels that is one call per round, `expand()`.

## The server's result

The server decides the base board and every reel the board grows by, in
order. Each reel is one `ColumnTarget`, the same shape `setResult()` takes.

```ts
interface InfinityResult {
  base: ColumnTarget[];  // one per reel the builder made
  extra: ColumnTarget[]; // the reels the board grows by, in order; often none
}
```

## Spin the base, then expand

```ts
const spin = reelSet.spin();
const res = await server.spin();
reelSet.setResult(res.base);
await spin;

await reelSet.expand({
  columns: res.extra,
  step: 1, // reels added and spun per step
  onStepAdded: () => camera.panTo(reelSet.viewport.maskWidth), // the board's new width
  onStepLanded: (step) => showWin(step.result.symbols),        // the whole board so far
});
```

Each step adds its reels, spins only those while every earlier reel is held,
and lands them on their columns. The call awaits your hooks, so a camera pan
or a win readout finishes before the next step. It validates every column
before the first reel is added, so a bad result throws before the board
changes.

## Shrink back next round

```ts
reelSet.removeReels(); // back to the reels the builder made; a no-op when the board did not grow
```

## Growing rows

`addRows(count, { cells })` makes every reel `count` rows taller at its own
cell size, and the viewport and mask grow with it. The `cells` option is what
the new rows show, one array per reel, from the server. Inside an expansion,
grow the rows between steps in `onStepLanded`. The reels after that arrive at
the new height. `removeRows()` goes back to the rows the builder made.

```ts
await reelSet.expand({
  columns: res.extra, // a column may be taller than the board once a row unlocks
  onStepLanded: (step) => {
    const row = res.rows[step.index]; // the server's cells for an unlocked row, or nothing
    if (row) reelSet.addRows(1, { cells: row });
  },
});
// next round
reelSet.removeReels();
reelSet.removeRows();
```

On MultiWays the rows are each reel's shape. The length of a column's
`visible` array is that reel's cell count, inside the fixed reel height.

## Stacked symbols that split

Some infinity slots land a symbol stacked two to four cells tall. When it
wins, the stack splits into more single symbols than it had cells, and its
reel grows past the frame. A stack is a big symbol one reel wide, and the
server says what it splits into.

```ts
// .symbolData({ Q3: { weight: 0, size: { reels: 1, cells: 3 } } })
const { from, count } = reelSet.splitSymbol(reel, cell, res.split); // e.g. six 'Q's
```

The reel grows by the difference. The cells above and below keep their
symbols, and the board re-centres around the taller reel. Keep the other
reels still on screen while your camera eases out, or they jump. Split at
rest, or between steps in `onStepLanded`. Next round, `resetColumns()` puts
every reel back.

Any symbol one reel wide can split, a 1x1 too. To keep the reel's height
instead, with its cells shrinking to share it, pass `{ height: 'keep' }`.
That is the default on MultiWays, where a reel's height is fixed. For any
other change to one reel, `setColumn` shows a column of any length. The
[split symbols page](/mechanics/split-symbols/) compares the two modes and
has a demo where you tap to split and a demo of splits on MultiWays.

## Counting and drawing ways

The library computes no wins (ADR 007). The server does. The library helps
you show them in two ways.

The board's ways is the product of the reels' row counts:

```ts
const ways = reelSet.reels.reduce((ways, reel) => ways * reel.visibleCells, 1);
```

Eight reels of three rows is 6,561 ways. Eight MultiWays reels of seven is
5,764,801.

`WinLines` in `pixi-reels/debug` draws a payway as a lattice: every winning
cell joined to every winning cell on the next reel. A win of millions of ways
is still a few dozen segments. It draws the cells you pass it.

```ts
import { WinLines } from 'pixi-reels/debug';

const lines = new WinLines(reelSet);
lines.ways(win.perReel); // winning cell indices per reel, from your server: [[0, 2], [1], [0, 1, 2]]
reelSet.events.on('spin:start', () => lines.clear());
```

The demos on this site use `evaluateWays()` and `countWays()` from
`@pixi-reels/kit/ways` in place of a server. Copy them if you want the same
left-to-right ways math in a prototype.

## Skip

The steps count as one round. The first `skipSpin()` lands the step in flight
and speeds up the rest. In standard mode they run on the fastest profile, and
in cascade mode every later step lands at once. A press between steps, while
a hook runs, carries over to the next step. To land everything still to come
at once, abort the expansion's `signal`.

An aborted expansion lands the remaining reels in one step, at the height the
board has at that moment. If your rows grow during the expansion, slam each
step instead of aborting.

## Events

| Event | When |
|---|---|
| `expand:start` | The chain starts: the board grows from `from` reels to `to`. |
| `reels:added` | A step's reels are on the board. Move the camera here or in `onStepAdded`. |
| `expand:stepAdded` / `expand:stepLanded` | A step's reels arrived or landed, before its hooks. |
| `rows:added` / `rows:removed` | `addRows()` or `removeRows()` changed every reel's height. |
| `column:set` | One reel changed its cells: `setColumn()`, `splitSymbol()` or `resetColumns()`. |
| `expand:complete` | Every step landed. Carries the final board. |
| `expand:end` | Always last, with `'complete'` or `'failed'`. Put the UI back here. |

Each step also fires the usual `spin:*` events. `reelSet.isExpanding` tells
them apart from a new round.

## Demos

The base spin lands, and then the board grows. `reelSet.expand({ columns })` adds the reels the server's result has beyond the base board, a step at a time, and spins only the new reels while the earlier ones hold. `addReels()` and `removeReels()` are the calls underneath it, and the next round shrinks the board back with `removeReels()`. The [infinity reels guide](/mechanics/infinity-reels/#concept) has the short version: what the server sends, the calls, and the events.

The first demo is the plain mechanic. The next ones change the board's shape during the expansion, and the last covers skipping.

## Add one reel per step

While the win still reaches the last reel, the server adds another reel to its result. Each step pans the camera to the new reel in `onStepAdded`, spins and lands it, then counts the ways and draws them with `WinLines` in `onStepLanded`.

The steps count as one round for skipping. The first press slams the step in flight and switches the rest to turbo, the same boost `skipSpin()` gives the rest of any round. In cascade mode the later steps land at once instead, the way one press ends a cascade. The second press aborts the expansion's `signal`, which lands every reel still to come in one step.

Live demo (infinity-reels): https://pixi-reels.schmooky.dev/mechanics/infinity-reels/#infinity-reels

## Board shape

### Add rows

A wild on a new reel unlocks a row. `addRows(1, { cells })` in `onStepLanded` makes every reel one cell taller, with the server's cells for the new row, and the reels after it arrive at the new height. The camera zooms out to fit, reading the board's size from `viewport.maskWidth` and `maskHeight`. The next round goes back with `removeReels()` and `removeRows()`.

Rows change only between steps. Inside `onStepAdded` the step's reels are about to spin on columns sized for the board's old height, so `addRows()` throws there. A fast-forward, which aborts the `signal`, lands every remaining reel in one step at the board's height at that moment. That is why this demo's skip slams one step at a time instead.

Live demo (infinity-reels-rows): https://pixi-reels.schmooky.dev/mechanics/infinity-reels/#infinity-reels-rows

### MultiWays

The length of each column's `visible` array is that reel's cell count, applied with `setShape()` for its step, so every reel the expansion adds multiplies the ways. Eight reels of seven cells give 5,764,801 ways, and ten give 282,475,249. Each step here adds two reels (`step: 2`).

Live demo (infinity-reels-multiways): https://pixi-reels.schmooky.dev/mechanics/infinity-reels/#infinity-reels-multiways

### Big symbols

The steps add one reel each, but a 2x2 wild arrives in one of the columns. A step of one reel cannot land half a block, so that step adds two reels and the block lands whole. The step plan is read from the `symbolData` sizes, and every block is validated before the first reel is added.

A block has to end on a reel the expansion adds. A block that would run past the last of them, or past the bottom of a strip, throws before any reel is added.

Live demo (infinity-reels-big-symbol): https://pixi-reels.schmooky.dev/mechanics/infinity-reels/#infinity-reels-big-symbol

### Split stacked symbols

Q lands either one cell tall or stacked two to four cells tall. When Q wins on every reel, each stack splits into more single Qs than it had cells, and its reel grows past the frame in both directions. `reelSet.splitSymbol(reel, cell, ids)` places the server's split: the stack covering `(reel, cell)` becomes `ids`, one per cell, the cells above and below keep their symbols, and the board re-centres around the taller reel. While the win reaches the last reel, `expand()` adds another reel and the multiplier goes up by one. The next round goes back with `removeReels()` and `resetColumns()`. The [Split symbols](/mechanics/split-symbols/) page has a reel that keeps its height, splits on MultiWays and a playground where you tap to split.

Because the board re-centres around the taller reel, hold the other reels still on screen and let the camera ease out, or they jump. This demo moves its camera by the amount they shift.

Live demo (infinity-reels-split): https://pixi-reels.schmooky.dev/mechanics/infinity-reels/#infinity-reels-split

## Skipping steps

Press as often as you like and read the log. The base board is grouped, shown by the dashed boxes, so a press lands one group. Each step's reel teases "will the win continue?" with `anticipation: { protect: 'once' }`, so the first press during a tease is spent and the next one lands the reel. A press while the camera pans is queued for the next step. The button calls `skipSpin()` and nothing else.

Live demo (infinity-reels-skip): https://pixi-reels.schmooky.dev/mechanics/infinity-reels/#infinity-reels-skip

### Skip policies

- Turbo for the rest, the default. The first `skipSpin()` frees the step in flight and moves every later step to the fastest profile. The next round starts at normal speed again.
- Slam each step. Every press frees the step in flight. Presses made during `onStepAdded` or `onStepLanded`, for example while the camera pans or a win readout shows, are kept and free the next step as soon as it has its result.
- Fast-forward. Abort the expansion's `signal` and every reel still to come lands in one step. A quick-spin or autoplay mode can pass a signal that is already aborted, so the whole expansion lands at once, with the same events and hooks.
- Quicken. With `.skipMode('quicken')`, or `requestSkip({ mode: 'quicken', speed: 'turbo' })`, a press shortens the step's spin but keeps its spin-out and bounce, so a long chain never looks cut.
- One reel per press on wide steps. A step's reels arrive as one group. Call `setReelGroups()` in `onStepAdded` to split them so each press frees one, or use `slamStop({ reels: [...] })` to land part of a step and let the rest play.
- Keep the deciding tease. `anticipation: (step) => stillWinning ? { protect: 'once', duration: 900 } : false` keeps the "will it continue?" tease through the first press, only on the steps where it matters.

`slamStop()` between steps has nothing to land, and a press after the last step has no step left, so both do nothing. A named `setDropOrder('ltr' | 'rtl' | 'all')` follows the reels that spin, so it covers the added reels and orders a step by position. A sticky `setStopDelays()` array covers only the reels it was given, and reels past its end stop with no delay.

## What carries across steps

- Events. Each step fires the usual `spin:*` events for its own reels, plus `reels:added`, `expand:stepAdded` and `expand:stepLanded`, and `rows:added` when a hook adds rows. The chain opens with `expand:start` and closes with `expand:complete` and then `expand:end`, which carries `'complete'`, or `'failed'` when the chain threw. `reelSet.isExpanding` is `true` in between, so a `spin:start` listener can tell a step from a new round.
- Stagger. Start and stop delays count a reel's position in its step, not its index, so reel 40 does not wait forty delays.
- Pins. A sticky pin's turns and an `'eval'` pin belong to the round, so a step does not use them up.
- Memory. Added reels are real reels while they are on the board. `removeReels()` destroys them and shrinks the viewport, mask and symbol pool back.
