Back to Projects
♟️

Chess AI

Game AI

A chess engine implemented in Python using priority queue search and board evaluation. The AI analyzes possible moves, evaluates board positions based on material advantage, and selects optimal moves using tree search algorithms.

Simulated Game

White to move

How It Works

Move Generation

Generates all legal moves for each piece type, including special moves like castling and pawn promotion.

Board Evaluation

Scores positions based on material count, piece captures, and check/checkmate detection.

Priority Queue Search

Uses priority queue to explore move sequences, prioritizing positions with better evaluations.

State Space Search

Explores the game tree by generating successor states and tracking visited positions.

Code Preview

ChessGame.py
def search(b):
    turn = 0
    visited = [b]
    q = Queue.PriorityQueue()
    q.put((b.boardScore(turn), b))

    while q.qsize() > 0:
        turn = -turn + 1
        child = q.get()
        v = child[1]
        h = v.successors(turn)

        for s in range(len(h)):
            if not h[s] in visited:
                newPriority = h[s].boardScore(turn) + child[0]
                q.put((newPriority, h[s]))
                visited.append(h[s])

Technologies

Python Priority Queue Game AI Tree Search Board Evaluation

Links