chess_ai based_report
chess_ai based_report
Name:Soham Gangurde
Roll No:22108B0028
Roll no:22108B0001
Introduction :
This project implements a chess game using Python with a unique AI opponent powered by
a Genetic Algorithm (GA). The user plays as White using a drag-and-drop interface, while
the AI (playing Black) selects its moves by simulating evolution-based strategies. This
combination of gameplay mechanics and AI logic makes the game not only interactive but
also intelligent in its move selection.
Objective:
This project utilizes Python 3.12 for core programming, Pygame for building the graphical
user interface, and the python-chess library to handle all chess rules and move logic.
Randomness required for the Genetic Algorithm’s mutation and selection processes is
implemented using Python's built-in random module. These technologies together allow
for a smooth gameplay experience and dynamic AI behavior.
• Interactive Board: The player uses mouse clicks for drag-and-drop moves.
• Last Move Highlight: The most recent move is highlighted on the board.
• Genetic Algorithm AI: The computer evaluates and evolves the best move using a
simplified GA.
• Game Status Updates: Displays when the game ends via checkmate or draw.
• Dynamic Rendering: All pieces are loaded and scaled from an asset folder.
AI implementation using Genetic Algorithm:The Genetic Algorithm selects the AI's
move by simulating an evolutionary process. It begins by generating a population of
random legal moves. Each move is applied to a copy of the current board and evaluated
based on the resulting material advantage. The top-performing moves are selected, and
new ones are generated by randomly picking from these top moves. This loop continues for
several generations (typically five), after which the move with the highest fitness score is
chosen. Though simplified, this approach mimics natural selection, enabling the AI to
improve its decisions over time.
The fitness function is the evaluation mechanism that scores each possible move based
on the resulting board state. It calculates a numerical value by summing up the material on
the board — using standard piece values (e.g., queen: 9, rook: 5, bishop/knight: 3, pawn: 1)
— and favors positions where the AI has a material advantage. This score determines how
"fit" or strong a move is in the context of the game.
The population function refers to the set of legal moves generated from the current board
position. This population acts as the initial generation in the Genetic Algorithm. From this
group, moves are evaluated, the top half is selected (selection), and new candidate moves
are created through random choices among the best (crossover/mutation) to simulate
evolution. After several generations, the move with the highest fitness score is chosen as
the AI’s move.
• Repetitive Moves: Initially, AI would repeat the same move. Fixed by improving
evaluation and population control.
• Evaluation Errors: Resolved bugs related to copying boards and handling invalid
moves.
• UI Responsiveness: Ensured updates were timely without freezing or skipping turns.
• Add difficulty levels (more generations, larger population).
• Add move history log.
• Online multiplayer support.
• Include audio feedback and animations.
Conclusion: