belote
v0.0.12
Published
A TypeScript library for playing Belote card game with bot support.
Maintainers
Readme
Belote API
A TypeScript library for playing Belote card game with bot support. Works in Node.js and browsers.
Installation
# Using pnpm
pnpm add belote
# Using npm
npm install belote
# Using yarn
yarn add beloteUsage
Node.js (CommonJS)
const { Belote, GamePhase } = require('belote');
const game = new Belote({
endValue: 501,
moveTime: 30,
botDelayMs: 1000
});
// Add players
game.addBot('Bot 1', 1);
game.addBot('Bot 2', 2);
game.addBot('Bot 3', 1);
game.addBot('Bot 4', 2);
// Start game
game.startGame();Node.js (ES Modules)
import { Belote, GamePhase } from 'belote';
const game = new Belote({
endValue: 501,
moveTime: 30,
botDelayMs: 1000
});
// Add players
game.addBot('Bot 1', 1);
game.addBot('Bot 2', 2);
game.addBot('Bot 3', 1);
game.addBot('Bot 4', 2);
// Start game
game.startGame();Browser (via CDN)
<!DOCTYPE html>
<html>
<head>
<title>Belote Game</title>
</head>
<body>
<!-- Load from unpkg -->
<script src="https://unpkg.com/belote@latest/dist/browser/belote-api.min.js"></script>
<script>
// Available as global BeloteAPI
const { Belote } = BeloteAPI;
const game = new Belote({
endValue: 501,
moveTime: 30,
botDelayMs: 1000
});
// ...
</script>
</body>
</html>Browser (ES Modules)
<!DOCTYPE html>
<html>
<head>
<title>Belote Game</title>
</head>
<body>
<script type="module">
import { Belote, GamePhase } from 'https://unpkg.com/belote@latest/dist/browser/belote-api.esm.js';
const game = new Belote({
endValue: 501,
moveTime: 30,
botDelayMs: 1000
});
// ...
</script>
</body>
</html>API
Belote Class
Constructor
new Belote(options?: Partial<GameOptions>)Methods
playerJoin(playerName?: string, teamId?: number, playerId?: string): PlayeraddBot(botName?: string, teamId?: number): PlayerstartGame(): voidbid(playerId: string, call: CardColor | 'pass'): voidmakeCall(playerId: string, cards: Card[]): voidplayCard(playerId: string, card: Card): void
Events
gameStartedplayerJoinedroundStartedbiddingStartedadutChosengameEnded- And many more...
Development
# Install dependencies
pnpm install
# Build all formats
pnpm run build
# Watch for changes
pnpm run watch
# Lint code
pnpm run lintBuild Outputs
dist/cjs/- CommonJS build for Node.jsdist/esm/- ES Modules build for modern environmentsdist/browser/- UMD build for browsersdist/types/- TypeScript type definitions
License
This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.
