Using these libraries will help us focus only on the most interesting task: creating the algorithm that finds the best move.
We’ll start by creating a function that just returns a random move from all of the possible moves:
Although this algorithm isn’t a very solid chess player, it’s a good starting point, as we can actually play against it:
Now let’s try to understand which side is stronger in a certain position. The simplest way to achieve this is to count the relative strength of the pieces on the board using the following table:
With the evaluation function, we’re able to create an algorithm that chooses the move that gives the highest evaluation:
... read the whole story at medium.freecodecamp.com.