Current version: 4.1.1.
A TypeScript library that provides AI capabilities for backgammon games using the native @nodots-llc/gnubg-hints addon to access GNU Backgammon's evaluation engine. This package is part of the Nodots Backgammon ecosystem and focuses on structured hints rather than spawning external binaries.
- π Revolutionary Plugin System - Open, extensible architecture for AI development
- π§ Nodots AI Engine - New intelligent analyzer with strategic heuristics
- π Five Built-in Analyzers - From random to world-class GNU Backgammon AI
- π Dynamic Plugin Loading - Hot-swappable AI engines with automatic discovery
- π‘ Context-Aware Analysis - Analyzers receive board state and position data
- π Open Development Platform - Community-driven, plugin-friendly architecture
- π Enhanced API Surface - New exports for plugin development and integration
- π― Template-Based Development - Easy plugin creation with standardized interfaces
- Open Architecture: Plugin system enables community-contributed analyzers
- Five Built-in Analyzers: Random, strategic, defensive, template, and world-class AI
- Hot-Swappable Intelligence: Switch between AI engines seamlessly
- Context-Aware Analysis: Analyzers receive board state and position information
- Dynamic Loading: Automatic discovery and loading of custom plugins
- Template-Based Development: Standardized interfaces for easy plugin creation
- Nodots AI Engine: Strategic heuristics with safety, offense, and racing priorities
- GNU Backgammon Integration: World-class AI with 2000+ FIBS rating equivalent
- Multiple Strategies: From random testing to tournament-grade analysis
- Extensible Framework: Build custom analyzers for specialized strategies
- Native Hints: Powered by the
@nodots-llc/gnubg-hintsaddon β no external binaries to ship or manage - TypeScript First: Full type definitions and intelligent integration
- Cross-Platform: Supports macOS, Linux with automated build scripts
- Comprehensive Analysis: Equity calculations, move rankings, and probability analysis
- Minimal Dependencies: CLI-only build without GUI components
npm install @nodots-llc/backgammon-aiHere are tested position IDs that work with the integrated gnubg engine:
import { buildHintContextFromGame, gnubgHints } from '@nodots-llc/backgammon-ai'
import type { BackgammonGame } from '@nodots-llc/backgammon-types'
const game: BackgammonGame = /* obtain current game state */
const { request } = buildHintContextFromGame(game)
const [bestHint] = await gnubgHints.getMoveHints(request)
console.log('Top-ranked move sequence:', bestHint?.moves)
console.log('Equity:', bestHint?.equity)As of v4.1, this package relies on the @nodots-llc/gnubg-hints native addon instead of bundling the entire GNU Backgammon source tree. The addon wraps GNU Backgammon's evaluation engine through N-API and ships with TypeScript definitions.
- Node.js 18+
- A working node-gyp toolchain (Python 3, make, and a C/C++ compiler)
- Platform-specific build tools (e.g.,
xcode-select --installon macOS,build-essentialon Debian/Ubuntu)
npm install @nodots-llc/backgammon-aiThe native addon is compiled during installation; no additional scripts are required.
import {
configureGnubgHints,
initializeGnubgHints,
} from '@nodots-llc/backgammon-ai'
await initializeGnubgHints({ weightsPath: '/path/to/gnubg.weights' })
configureGnubgHints({ evalPlies: 2, moveFilter: 3 })weightsPathlets you supply custom neural-network weights.configureGnubgHintsmirrors the tuning options provided by the addon (plies, move filters, pruning, etc.).
- Review
gnubgHints.getBuildInstructions()for platform-specific guidance. - Rebuild manually with
npx node-gyp rebuild --ansi. - Consult the
@nodots-llc/gnubg-hintsREADME for detailed setup notes.
Version 3.5.0 introduces a groundbreaking plugin system that transforms ai into an open, extensible platform for backgammon AI development. The plugin system enables developers to create, share, and integrate diverse AI strategies seamlessly.
| Analyzer | Strategy | Use Case |
|---|---|---|
| RandomMoveAnalyzer | Random selection | Testing, baseline comparison |
| FurthestFromOffMoveAnalyzer | Maximize distance from bearing off | Defensive/blocking strategies |
| ExamplePluginAnalyzer | Template for developers | Plugin development starting point |
| GnubgMoveAnalyzer | GNU Backgammon integration | World-class AI analysis |
| NodotsAIMoveAnalyzer | Strategic heuristics engine | Intelligent gameplay with safety/offense/racing |
import {
NodotsAIMoveAnalyzer,
GnubgMoveAnalyzer,
RandomMoveAnalyzer,
selectMoveFromList,
} from '@nodots-llc/backgammon-ai'
// Choose analyzer based on game context
const analyzer =
difficulty === 'expert' ? new GnubgMoveAnalyzer() : new NodotsAIMoveAnalyzer()
const bestMove = await selectMoveFromList(moves, analyzer)import { MoveAnalyzer, MoveAnalyzerContext } from '@nodots-llc/backgammon-ai'
import { BackgammonMoveBase } from '@nodots-llc/backgammon-types'
export class MyCustomAnalyzer implements MoveAnalyzer {
async selectMove(
moves: BackgammonMoveBase[],
context?: MoveAnalyzerContext
): Promise<BackgammonMoveBase | null> {
// Your custom AI logic here
// Access board state: context?.board
// Access position ID: context?.positionId
// Example: Prefer moves with higher die values
return moves.reduce((best, current) =>
current.dieValue > best.dieValue ? current : best
)
}
}
export default MyCustomAnalyzerimport { loadAnalyzersFromPluginsDir } from '@nodots-llc/backgammon-ai'
// Load all analyzers from a directory
const analyzers = loadAnalyzersFromPluginsDir('./my-plugins')
// Use any loaded analyzer
const move = await analyzers['myCustomAnalyzer'].selectMove(moves, {
positionId: 'gJ/4AFjgc3AEO',
board: currentBoard,
})The new NodotsAIMoveAnalyzer implements intelligent move selection with a three-tier strategy system:
import { NodotsAIMoveAnalyzer } from '@nodots-llc/backgammon-ai'
const nodotsAI = new NodotsAIMoveAnalyzer()
// The AI prioritizes:
// 1. Safety: Creating points, escaping blots
// 2. Offense: Attacking opponent blots, blocking
// 3. Racing: Advancing checkers efficiently
const bestMove = await nodotsAI.selectMove(moves, context)- Create your analyzer class:
// plugins/myAnalyzer.ts
import { MoveAnalyzer, MoveAnalyzerContext } from '@nodots-llc/backgammon-ai'
export class MyAnalyzer implements MoveAnalyzer {
async selectMove(moves, context) {
// Your logic here
return moves[0] || null
}
}
export default MyAnalyzer- Load and use it:
import { loadAnalyzersFromPluginsDir } from '@nodots-llc/backgammon-ai'
const analyzers = loadAnalyzersFromPluginsDir('./plugins')
const move = await analyzers['myAnalyzer'].selectMove(moves, context)The plugin system embodies our commitment to open development:
- π Open Architecture: No vendor lock-in, switch AI engines seamlessly
- π Community-Driven: Easy contribution of new analyzers
- π§ͺ Experimentation-Friendly: Test strategies without code changes
- π Template-Based: Standardized interfaces for easy development
- π Innovation Platform: Framework for AI research and development
import {
buildHintContextFromGame,
gnubgHints,
} from '@nodots-llc/backgammon-ai'
const { request } = buildHintContextFromGame(gameState)
const [topHint] = await gnubgHints.getMoveHints(request, 5)
console.log('Top candidate moves:', topHint?.moves)
console.log('Equity:', topHint?.equity)import { selectBestMove } from '@nodots-llc/backgammon-ai'
import type { BackgammonPlayMoving } from '@nodots-llc/backgammon-types'
const bestMove = await selectBestMove(play as BackgammonPlayMoving, 'gbg-bot')-
24/20 16/13 Eq: +0.466 β BEST MOVE Win: 59.5%, Gammon: 22.5%, Backgammon: 2.4%
-
24/21 24/20 Eq: +0.434 (-0.032) Win: 58.7%, Gammon: 22.8%, Backgammon: 2.5%
-
24/20 13/10 Eq: +0.414 (-0.052) Win: 58.2%, Gammon: 22.9%, Backgammon: 2.9%
## Development
### Setup
1. Clone the repository:
```bash
git clone https://github.com/nodots/ai.git
cd ai
- Install dependencies:
npm install- Verify functionality:
npm test
npm run buildnpm run build- Build the TypeScript projectnpm run test- Run testsnpm run test:watch- Run tests in watch modenpm run test:coverage- Run tests with coverage reportnpm run lint- Run ESLintnpm run lint:fix- Fix ESLint issuesnpm run clean- Clean build artifacts
- β macOS 14.5.0 (Apple Silicon)
- β GNU Backgammon 1.08.003
- β Node.js 18+
- β TypeScript 5.7+
- Build fails with GTK errors: Use minimal configuration (already set in npm scripts)
- readline errors on macOS: Fixed in v3.1.0 with compatibility patches
- Native build fails: Ensure a working node-gyp toolchain (
python3,make, and a C/C++ compiler)
- Test integration:
npm test
This project is licensed under the MIT License.
Ken Riley [email protected]
- GNU Backgammon Team: For the excellent gnubg engine and analysis capabilities
- GNU Project: For maintaining and developing gnubg as free software
- Backgammon Community: For continued development and testing of gnubg
Minor README refresh.
- New MIT core: @nodots-llc/backgammon-ai-core
- Optional GNU adapter (GPL): @nodots-llc/backgammon-ai-gnubg
Migration:
- Install ai-core and (optionally) ai-gnubg & gnubg-hints