Chess AI | Sololearn: Learn to code for FREE!


Chess AI

I am hoping to make a chess robot, but I need to think small first. If I were to make a chess game in python how could I get the computer to make intelligent moves (depending on previous moves)?

11/11/2018 11:13:37 PM


5 Answers

New Answer


You need a way to generate all possible legal moves in a given position. Then you can simulate them and look whether the position is better/worse than before. Usually you'd do that not one move ahead but as many as possible. To decide whether a position is good, you need to assign a number to a position by a so-called "heuristic". A simple way would be to count up the material on the board (bishop/knight = 3 pawns, rook = 5 pawns, queen = 9 pawns, king = 1000 pawns). Then you take your material minus your opponents and thats what you try to maximize for (higher = better!). You look at all the moves a couple moves deep and choose the one that has the best worst-case outcome (so you are assuming the opponent plays perfect) There are many ways to make it more sophisticated but that's the basic workings of a chess AI.


Sololearn created this chess engine contest few weeks ago, many people participated and came up with their solutions . There are many discussions and codes here in the comments that might be helpful.


If I was courageous enough to even try, I'd probably start with the core issue: checkmate. Empty board, two kings, one queen. And then figure out how to make the computer finish me off, probably with a whole bundle of ifs and elses. ;-)


Before making it,u have to be good at Neural networks.which will serve as neuron to the brain of the robot.Then if statements