gomokuai
v1.0.2
Published
Simple gomoku game ai
Downloads
16
Readme
Simple gompku ai
Calculates next move for a gomoku game.
Install
npm install gomokuai
.
Usage
Gomokuai has a simple API with just two funktions:
// bestMove :: ([Mark], Size) -> Position
// Mark = 0 | 1 | 2
// Size = Integer
// Position = { x: Integer, y: Integer }
const bestMove = (board, boardSize) => {
/*...*/
};
// randomMove :: ([Mark], Size) -> Position
// Mark = 0 | 1 | 2
// Size = Integer
// Position = { x: Integer, y: Integer }
const randomMove = (board, boardSize) => {
/*...*/
};
You put in a flat array representing your gomoku game board, the size of the game board (quadratic, eg 10x10 gives Size = 10) and you get back a position object.
bestMove
calculates the best move to make on the current game board and randomMove
just gives you a random placement on any free space.
Example
const ai = require("gomokuai");
/* ... */
const { x, y } = ai.bestMove(gameBoard.getBoard(), gameBoard.getSize());
gameBoard.play(x, y);
Tests
Clone the repo, cd in, npm install
, npm test
.
TODO
- Write a new best-move calculator.
- Increase code quality.
Shoutout
The best-move calculator is a ripped from a jQuery plugin by Stefan Gabos
Licens LGPL-3.0