Both chess and computer programming are two subjects that have been important to me for many years. Why is it that the subject of computer chess is not very popular these days? Have we gotten blasé about the subject since the defeat of the then World Champion Gary Kasparov by Deep Blue in May 1997? Is that the end of the line?
Deep Blue and its programming staff broke new frontiers in analytics and massively parallel processing which became the foundation for the IBM computer Watson that was showcased in 2011. Using natural language cognition, Watson defeated the two best Jeopardy champions in a nationally broadcast show. We learned so much from Deep Blue, I would like to think that we all could benefit from a some understanding chess program logic.
Even though it’s now possible to download chess engines for free that have playing levels as high as International Master, I still think it’s instructive for all programmers to have some basic knowledge about how chess programs work. For instance, I recently challenged a group of seasoned programmers to think about which chess piece would be the hardest to code for, and not one could figure it out. And which is it? It’s the pawn, and by a long way!! Here are the reasons:
- It’s the only piece whose color makes a difference (white moves up the board, black moves down)
- It’s the only piece who can move differently based on its position on the board (if on the 2nd rank it can move 2)
- It’s the only piece that captures in a direction it can’t move and moves in a direction it can’t capture
- It’s the only piece that can change its value (by getting to the 8th rank)
- It’s the only piece that can capture a piece by moving to a square that is empty (en passant).
By comparison, the pieces that move only by simple vectors are mundane to code.
The king is second most complex to code since it has restrictions that say it cannot move to a square that is being attacked by an opponent piece, and once a game it can actually move 2 places by castling. (Note that while castling, it can not move over a square that is being attacked by another piece). The program must also retain a history of previous moves to know if castling is allowed (neither the king or the rook that is used in the castling move can have made any moves since the game started).
When the early IBM computers were created, the idea of programming one to play chess was fascinating. It was many years before chess programs were able to play competitive chess, as the hardware needed to perform the task simply was not fast enough to evaluate millions of positions in a short period of time. Now programs exist that can run on mobile devices that are exceedingly hard to beat!
I wrote my first chess program in Assembly language on an IBM 370/125 in the mid 70s. It played chess with the user by writing console messages using WTOR. It knew how to move the pieces but was probably the worst chess opponent I have ever played due to a fundamental error in the tree analysis that I had written. I had written the tree analysis and determined to play the move that led to the highest material value in the end “leaf.” What I failed to realize was that the leaf with the best value for the computer was the leaf in which the user played the absolute worst it could!!! You live and learn…my second and third generation programs played much better.
I’ll post more insights on chess programming (and how it relates to programming for enterprise software applications) in future entries.
Latest posts by Paul Pendle (see all)
- Understanding Russian dominance in competitive chess - April 21, 2015
- When computer chess programs sulked… - April 3, 2015
- Chess and predictive analytics: what would happen if…? - February 17, 2015