Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
loks0n committed Feb 3, 2023
1 parent c0bf585 commit 08643e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,29 @@ The engine follows the [WCDF ruleset](https://www.wcdf.net/rules.htm).
## How to use

```typescript
import { EnglishDraughts } from 'rapid-draughts';
import { EnglishDraughts, Player, Status } from 'rapid-draughts';

// Start a game
let draughts = new EnglishDraughts();
console.log(draughts.toString());

// Output the current player
console.log(draughts.player() === Player.WHI)
// Initialise the game
const { engine, draughts } = EnglishDraughts.setup();

// Show the moves
// Show the available moves and play one.
const moves = draughts.moves();
console.table(moves);
draughts.move(moves[0]);

// Initialise two AIs
const weakAI = EnglishDraughts.AI.alphaBeta({ maxDepth: 4, quiescence: false });
const strongAI = EnglishDraughts.AI.alphaBeta({ maxDepth: 6 });

// Make a move
draughts = draughts.move(moves[0]);
// Play with the AIs until there is a winner
while (draughts.status() === Status.PLAYING) {
console.log(draughts.toString());
const move =
draughts.player() === Player.LIGHT ? weakAI(engine) : strongAI(engine);
if (move) engine.move(move);
}

// Announce the winner
console.log(draughts.toString());
console.log(`result = ${draughts.status()}`);

```
6 changes: 5 additions & 1 deletion examples/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { EnglishDraughts, Player, Status } from '../src';
// Initialise the game
const { engine, draughts } = EnglishDraughts.setup();

// Show the available moves and play one.
const moves = draughts.moves();
draughts.move(moves[0]);

// Initialise two AIs
const weakAI = EnglishDraughts.AI.alphaBeta({ maxDepth: 4, quiescence: false });
const strongAI = EnglishDraughts.AI.alphaBeta({ maxDepth: 6 });

// Play until there is a winner
// Play with the AIs until there is a winner
while (draughts.status() === Status.PLAYING) {
console.log(draughts.toString());
const move =
Expand Down

0 comments on commit 08643e4

Please sign in to comment.