Loading repository data…
Loading repository data…
Nishu219 / repository
NegaKnightV7, a sophisticated chess engine designed to play against a human opponent. It is implemented entirely in pure Python within a single file, and notably, it operates as a single-threaded application. It is recommended to use it with PyPy. Possibly, one of the strongest HCE engine written in single-file python.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
NegaKnightV7 is a chess engine written in Python, leveraging the python-chess library. It implements an enhanced Negamax algorithm with several advanced features to improve its playing strength, including:
Before running NegaKnightV7, you need to have Python 3 and the python-chess library installed.
You can adjust several parameters at the top of the your_engine_file_name.py file to fine-tune the engine's behavior:
MAX_DEPTH: The maximum depth the iterative deepening search will reach.
TIME_LIMIT: The maximum time (in seconds) the engine will spend thinking per move.
ASPIRATION_WINDOW: The window size for aspiration search, affecting how aggressively the engine searches for scores.
NULL_MOVE_R: Reduction factor for null move pruning.
LATE_MOVE_PRUNING_THRESHOLD: The threshold for applying late move pruning.
STATS: Set to True to print detailed search statistics during the engine's turn.
VALUES: Dictionary defining the material values for each piece type.
MOBILITY_BONUS: Bonuses for piece mobility.
ATTACK_WEIGHTS: Weights for king attack evaluation.
KING_ATTACK_SCALE: Scaling factor for king attack based on the number of attacking pieces.
PST: Piece-Square Tables for midgame ('mg') and endgame ('eg') evaluation.
NegaKnightV7 employs a Negamax algorithm with alpha-beta pruning as its core search function. This algorithm efficiently explores possible move sequences to find the best move for the current player.
Key enhancements include:
Iterative Deepening: The engine gradually increases its search depth, allowing it to return a reasonable move even if time runs out, and to leverage results from shallower searches.
Transposition Table: Stores the results of previously evaluated positions (identified by a Zobrist hash) to avoid redundant calculations and to enable faster lookups, especially for positions visited multiple times.
Quiescence Search: After the main Negamax search, a shallow quiescence search is performed to evaluate "noisy" positions (those with immediate captures or promotions) more accurately, preventing the horizon effect.
Move Ordering: Moves are sorted to try the most promising ones first. This significantly improves the effectiveness of alpha-beta pruning. It prioritizes hash moves, captures (using SEE), checks, and then moves from killer moves and history heuristic.
Positional Evaluation: The evaluate function calculates a score for a given board position based on various factors, providing a quantitative measure of who is "winning." This includes material balance, piece-square tables, pawn structure, king safety, and piece activity.