Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kjirou/rosenkoenig-core
Core engine of the board game Rosenkönig
https://github.com/kjirou/rosenkoenig-core
board-game npm rosenkoenig
Last synced: 14 days ago
JSON representation
Core engine of the board game Rosenkönig
- Host: GitHub
- URL: https://github.com/kjirou/rosenkoenig-core
- Owner: kjirou
- License: mit
- Created: 2023-04-30T05:20:42.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-05-18T01:20:13.000Z (over 1 year ago)
- Last Synced: 2024-12-07T16:37:42.819Z (21 days ago)
- Topics: board-game, npm, rosenkoenig
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/rosenkoenig-core
- Size: 79.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rosenkoenig-core
![run-tests](https://github.com/kjirou/rosenkoenig-core/actions/workflows/run-tests.yml/badge.svg)
Core engine of the board game [Rosenkönig](https://de.wikipedia.org/wiki/Rosenk%C3%B6nig)
## :rocket: Installation
This package is ESModules only.
```bash
npm install rosenkoenig-core
```## :chess_pawn: Usage
This is a set of APIs to implement Rosenkönig.
For example, use the following image.
Or see the [web demo](https://kjirou.github.io/rosenkoenig-core/) and its [pure HTML/JS source code](https://github.com/kjirou/rosenkoenig-core/blob/gh-pages/docs/index.html).```js
import {
computeNextPlayerIndex,
computeSelectablePlayerActions,
initialize,
playTurn,
} from "rosenkoenig-core";const gamePlay = initialize();
// Returns the next player to act as an index of 0 or 1.
const nextPlayerIndex = computeNextPlayerIndex(gamePlay);// Returns a list of actions that the player can select from.
// The list includes the following types of actions.
//
// 1. Move the crown by using power card
// 2. Draw a power card
// 3. Pass the turn
const selectablePlayerActions = computeSelectablePlayerActions({
board: gamePlay.game.board,
player: gamePlay.game.players[nextPlayerIndex],
playerIndex: nextPlayerIndex,
});// Determines the action the player selects to take.
// Usually, the selection would be made through the UI.
const playerAction = selectablePlayerActions[0];// Resolves the player action and generates new game states.
// Wins and losses are also computed at this point.
const newGamePlay = playTurn(gamePlay, playerAction);
```## :cat: API Doc
Look at the [source code](/src/index.ts) :innocent:
## :hammer_and_wrench: Development
### Preparation
- [Node.js](https://nodejs.org/)
- The version is defined in [.nvmrc](/.nvmrc).### Installation
```
git clone [email protected]:kjirou/rosenkoenig-core.git
cd ./rosenkoenig-core
npm install
```