# rainet

> A JavaScript implementation of 5pb.'s game RaiNet Access Battlers.

Latest version **1.1.1** (published 2016-06-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install rainet
pnpm add rainet
yarn add rainet
bun add rainet
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2016-06-21 |
| First published | 2016-06-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sean Genabe |
| Maintainers | s4g6 |

## Links

- npm: https://www.npmjs.com/package/rainet
- npm.io page: https://npm.io/package/rainet

## Dependencies (3)

- [make-error](https://npm.io/package/make-error.md) ^0.3.0
- [symbol-enum](https://npm.io/package/symbol-enum.md) ^4.0.2
- [lodash.assign](https://npm.io/package/lodash.assign.md) ^3.2.0

## Recent versions

- 1.1.1 (latest) — 2016-06-21
- 1.1.0 — 2016-06-19
- 1.0.1-1 — 2016-06-18

## README

# rainet

RaiNet Access Battlers Javascript implementation

[![npm](https://img.shields.io/npm/v/rainet.svg?style=flat-square)]
[![Dependency Status](https://img.shields.io/david/seangenabe/rainet.svg?style=flat-square)](https://david-dm.org/seangenabe/rainet)
[![devDependency Status](https://img.shields.io/david/dev/seangenabe/rainet.svg?style=flat-square)](https://david-dm.org/seangenabe/rainet#info=devDependencies)
[![node](https://img.shields.io/node/v/rainet.svg?style=flat-square)](https://nodejs.org/en/download/)

## Example usage

### Creating game instances

```javascript
// Create a game.
let game = new Game()
```

The game will be created with some initial state, provided at `game.state`. This object can be read to query the state of the game at any time.

### Starting a game

Terminology: Here "team" is used to indicate the playing sides of the game, even if there is only one player in each.

Enums are provided by the `rainet` module.

To start the game, pass an object to `game.start()`:
* `startingTeam`: Starting team. Can be unspecified, in which case any player can make the first move.
* `arrangement`: Map. Arrangement for each team.

#### Arrangement array format

The arrangement array is an array of numbers which is simply the number of link cards to put before each virus card.

Examples:
* LVLVLVLV = [1, 1, 1, 1]
* VLVLVLVL = [0, 1, 1, 1] : the remaining card is inferred
* LLLLVVVV = [4, 0, 0, 0] = [4] : remaining cards are inferred
* LLVVVVLL = [2, 0, 0, 0] = [2]
* VVVVLLLL = [0, 0, 0, 0] = [] : there are no link cards before any virus card

#### Example

```javascript
game.start({
  startingTeam: Team.bottom,
  arrangement: new Map([
    [Team.top, [1, 2, 0, 1]],
    [Team.bottom, [4]]
  ])
})
```

### Querying game state

#### Terminal card state

Example:
```javascript
game.state.terminalCardState.get(Team.bottom).get(TerminalCardType.virusCheck) // boolean
{
  let sq = game.state.terminalCardState.get(Team.bottom)
    .get(TerminalCardType.lineBoost) // Square if installed
  sq.location // Location
  sq.card // Card if there's a card here
  sq.firewall // Team if there's a firewall here
}
```

#### Winner

Example:
```javascript
game.state.winner // undefined or Team
```

#### Grid

The grid is the main playing area consisting of 8 rows and 8 columns. These are indexed from 0 to 7 from top to bottom and left to right. That is, lower-indexed rows are closer to the team labeled "top".

```javascript
let grid = game.state.board.grid
grid.rows // array of rows, each row is an array of squares
grid.columns // array of columns, each column is an array of squares
grid.squares // all squares
grid.lookup(new Location(6, 3)) // Square
grid.columns[6][3] // Square
grid.rows[3][6] // Square
```

### Making a move

Players take turns to submit moves to the game via `game.submitMove`. An `InvalidMoveError` will be thrown if the move submitted is invalid.

**Move an online card**

```javascript
game.submitMove(new OnlineCardMove({
  team: Team.bottom,
  square: game.state.board.grid.lookup(new Location(4, 6)),
  direction: Direction.up
}))
```

**Move an online card with line boost / to the server area**

```javascript
game.submitMove(new OnlineCardMove({
  team: Team.bottom,
  square: game.state.board.grid.lookup(new Location(6, 0)),
  direction: Direction.left,
  direction2: Direction.up,
  revealCard: true
}))
game.state.board.stackArea.get(Team.top)[0].cause // 'infiltrated'
game.state.board.stackArea.get(Team.top)[0].card.revealed // true
```

**Install / uninstall a line boost / firewall card**

```javascript
game.submitMove(new InstallableTerminalCardMove({
  team: Team.bottom,
  square: game.state.board.grid.lookup(new Location(4, 6)),
  cardType: TerminalCardType.lineBoost
}))

game.submitMove(new InstallableTerminalCardMove({
  team: Team.bottom,
  cardType: TerminalCardType.lineBoost,
  uninstall: true
}))
```
**Use a virus check card**

```javascript
game.submitMove(new TerminalCardMove({
  team: Team.top,
  square: game.state.board.grid.lookup(new Location(5, 6)),
  cardType: TerminalCardType.virusCheck
}))
game.state.board.grid.columns[5][6].card.revealed // true
```

**Use a 404 Not Found card**

```javascript
game.submitMove(new NotFoundTerminalCardMove({
  team: Team.bottom,
  square: game.state.board.grid.lookup(new Location(4, 6)),
  other: game.state.board.grid.lookup(new Location(5, 6)),
  swap: true
}))
game.state.board.grid.columns[4][6].card.revealed // false
game.state.board.grid.columns[5][6].card.revealed // false
```

**Surrender**

```javascript
game.submitMove(new SurrenderMove({ team: Team.bottom }))
```

### Wrap-up

This is pretty much what's needed to interact with the module. Feel free to consult the full documentation / source code.

## Docs

Simply run `npm run jsdoc` to generate documentation.

## License

MIT

---
_Source: https://npm.io/package/rainet · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
