Repository
Current version released
4 years ago
Usage:
- DENO
import { ... } from 'https://deno.land/x/catur/mod.ts'- NODE
npm i caturimport { ... } from 'catur'Example: Pecel AI vs Lele AI
// import ....
const main = async () => {
const caturGame = CaturGame.newStandardGame();
const pecelAI = new AI.PecelAI(caturGame);
const leleAI = new AI.LeleAI(caturGame);
// if we didn't set the piece type on promote, the piece will turn into a queen
caturGame.onBlackPromote = () =>
caturGame.mover.promoteLastMoveTo(
Utils.randomFromArray([Type.bishop, Type.queen, Type.knight, Type.rook])
);
console.log(caturGame.board.toString());
/**
β β β β β β β β
β β β β β β β β
β β β β β β β β
β β β β β β β β
*/
let mv = 0;
while (!caturGame.gameOver) {
console.clear();
// pecelAI as white, and leleAI as black
const move = mv++ % 2 == 0 ? pecelAI.getMove() : leleAI.getMove();
if (move) {
caturGame.mover.moveStrict(move.from, move.to);
// NEEDED
caturGame.mover.next();
}
console.log(move);
console.log(caturGame.board.toString());
await Utils.sleep(500);
}
console.log(caturGame.gameOverReason + "!");
};
main().catch((err) => console.error(err));