lihongxun945/gobang

javascript gobang AI,JS五子棋AI,源码+教程,基于Alpha-Beta剪枝算法(不是神经网络)

What it solves

This project provides a browser-based AI opponent for the game of Gobang (Five in a Row), allowing users to play against a computer that calculates the best moves in real-time without requiring a server-side backend.

How it works

Unlike modern neural networks, this AI uses a classical game-theory approach based on the Minimax algorithm. It evaluates potential moves by searching through possible future game states to a certain depth. To improve performance and efficiency, it implements several optimizations:

  • Alpha-Beta Pruning: Reduces the number of nodes evaluated in the search tree.
  • Iterative Deepening: Gradually increases search depth to find the best move within time constraints.
  • Zobrist Hashing: Uses a transposition table to cache previously evaluated positions.
  • Killer Move Ordering: Prioritizes searching moves that have caused cut-offs in other branches.
  • PVS (Principal Variation Search): Further optimizes the search process.

Who it’s for

  • Casual players who want to play Gobang against an AI in their browser.
  • Developers interested in learning how to implement classical game AI, search algorithms, and heuristic evaluation functions.

Highlights

  • Pure Frontend Implementation: The AI runs entirely in JavaScript within the browser, meaning it works offline after the initial page load.
  • Comprehensive Testing Suite: Includes a dedicated AI evaluation tool to measure Elo ratings, win rates, and node throughput using independent processes.
  • Tactical Problem Set: Features a built-in library of tactical puzzles to detect "leaks" or errors in the AI's move selection.
  • Customizable Difficulty: Search depth can be adjusted to change the AI's strength and processing time.

Related

  • Project
  • Dispatch
  • Project
  • Project
  • Project