In most chess engines, a searching algorithm along with a heuristic function gives the chess AI the main insight into the best moves to play. The bulk of the programming and most of the “brains” behind this is the heuristic function.

What do I mean by heuristic function? Heuristic function refers to a function that takes certain measurements of the chessboard, gives each measurement a certain weightage, and finally calculate a numerical value of the advantage of each player. The heuristic function in chess usually considers basic things such as pawn structure, center control, and King safety, but it can also include more complex calculations such as tempo and opportunities to employ different tactics.

A well-seasoned chess player with a decent proficiency in programming would be able to construct a good heuristic function. Unfortunately, I am not that well-seasoned chess player. I have decided to use a neural network to create a heuristic function for me.


The concept of the program uses a neural network to evaluate the board, which is then fitted with the search algorithm, which checks all future position and finds the highest value, sort of like a min-max tree.


Step 1- Accessing the Data:

from pandas import read_csv
import numpy as np
import chess
import os
df = read_csv('C:\\Users\\v_sim\\Desktop\\Files\\Data\\chess.csv')
df = df[df['winner']!='draw']
moves = df['moves'].values[:100]
winner = df['winner'].values
X = []
y = []

This script extracts the csv file from my computer, and imports the necessary imports for the program to function. Pandas is for csv data extraction, numpy for the manipulation of arrays, chess for a ready-made chess board and empty lists to represent the X and y values for the network.

#machine-learning #data-science #ai #programming #editors-pick

Creating a Chess Engine with Deep Learning
1.50 GEEK