ban-chess-engine
v0.2.0
Published
AI engine for Ban Chess variant using minimax algorithm
Downloads
13
Readme
Ban Chess Engine
An AI engine for the Ban Chess variant, built on top of the ban-chess.ts library.
Overview
This engine uses traditional chess AI techniques (minimax with alpha-beta pruning) adapted for Ban Chess. The key insight is that the ban-chess.ts library's ply-based system allows us to treat bans and moves uniformly - each ply is simply an action in the game tree.
Features
- Standard minimax algorithm with alpha-beta pruning
- Iterative deepening for better time management
- Position evaluation tailored for Ban Chess:
- Material balance
- Mobility (number of legal actions)
- King safety with ban vulnerability assessment
- Center control
- Simple CLI interface to play against the engine
Installation
cd ban-chess-engine
npm install
npm run buildUsage
Playing against the engine
npm run playUsing the engine programmatically
import { BanChess } from 'ban-chess.ts';
import { BanChessEngine } from 'ban-chess-engine';
const game = new BanChess();
const engine = new BanChessEngine({
maxDepth: 6, // Search depth in plies
timeLimit: 5000 // Time limit in milliseconds
});
// Get best action for current position
const result = engine.findBestAction(game);
if (result.action) {
game.play(result.action);
console.log(`Engine played with score: ${result.score}`);
}Architecture
The engine leverages the ply-based system from ban-chess.ts:
- Ply 1: Black bans
- Ply 2: White moves
- Ply 3: White bans
- Ply 4: Black moves
- etc.
This means we can use standard minimax without special handling for the ban/move alternation. Each ply is treated as a single node in the search tree.
Evaluation Function
The position evaluation considers:
- Material: Standard piece values
- Mobility: Number of available actions (bans or moves)
- King Ban Safety: Kings near edges are more vulnerable to ban-induced checkmates
- Center Control: Controlling central squares
Performance
The engine searches approximately 6-8 plies deep in typical middlegame positions within a 3-second time limit. The actual depth depends on:
- Position complexity
- Number of legal actions
- Alpha-beta pruning effectiveness
Future Improvements
- Opening book specifically for Ban Chess patterns
- Endgame tablebases for ban positions
- Transposition tables to avoid re-evaluating positions
- Improved move ordering for better pruning
- Machine learning for evaluation tuning
