background preloader

Chess Programming

Facebook Twitter

A Beginner's Guide to Chess Programming. Welcome to the Beginner's Guide to Chess Programming.

A Beginner's Guide to Chess Programming

This guide was put together to help people who are unfamiliar with AI technology to develop chess programs of their own - because it's so cool to write software that can beat you! This guide should be pretty much language-neutral, and certainly only covers the basics. However, having read and implemented what you will find here, you should have a fair program, and a basis to understand the more specialised terms and discussions you'll find elsewhere on the Net. This guide was developed by Adam Oellermann. While no professional, I enjoy tinkering with this stuff. Enjoy! How to develop a chess program for dummies. > Click here for the second lesson.

how to develop a chess program for dummies

Introduction This lesson will describe the Artificial Intelligence algorithm that one has to implement in order to have the chess program play chess. How to read this lesson In order to understand what is mentioned in this lesson, you must have downloaded the latest version of Huo Chess (currently v0.93). Mayothi. How NagaSkaki plays chess Move generation NagaSkaki has a unique method of generating moves.

Mayothi

Instead of using rotated bitboards (like most programs do), it uses shifted bitboards. Before I go into detail about how this works, let me first explain how NagaSkaki represents the chess board. Board Representation NagaSkaki represents the chessboard as a combination of 64bit integers, called bitboards. Chess and Bitboards. Bitboards are an interesting method of representing a chess board invented in Russia (with the program Kaissa, circa 1977).

Chess and Bitboards

They were made widely popular by Robert Hyatt and his program Crafty, a direct derivatve of "Cray Blitz" written circa 1985, which he had made open source. The basic idea is that we are going to be exploiting the coincidental fact that a chess board has 64 squares and that modern computers can easily manipulate 64-bit integers. So what are the motivations of bitboards? One of them is memory compaction of the state of the board and of possible future boards. Another is that many questions about movement and capturing of pieces can be answered "in parallel" by ORing, ANDing, XORing, and shifting various bitboards instead of building complex data structures in memory to hold views of the board by certain pieces and valid movement spaces and then sets of those data structures for AI exploration of the movement space.

Programmer Stuff. Programmer Corner Articles on computer chess at programmer level, very technical stuff, don't bother to read if you failed the introduction course.

Programmer Stuff

On this page I will try to explain most of the workings of REBEL (and some of its successor Pro Deo). It's my hope that it might serve as an inspiration for starting chess programmers. I would like to present the following issues found in REBEL. Move Ordering (1) Contrary to most chess programs, when going one ply deeper in the chess tree REBEL generates all moves for the given (and new) ply. The advantage of this time consuming process is that it pays off later when move ordering becomes an issue, this provided you have created 12 reasonable organized piece-square tables for the move generator. Static char move_from [5000]; static char move_to [5000]; static char move_value [5000]; So when adding a new generated move to "move_from" and "move_to" REBEL also will fill "move_value" via the corresponding piece-square table using the formula:

Chess program board representations. Note this is a draft, and that changes are likely.

Chess program board representations

Introduction The first decision we make when we undertake writing a chess program is how to represent the chess board and the pieces that occupy squares on this board. Unfortunately, this decision is made before there is enough information available to choose the optimal representation. As a result, this turns out to be the single most often changed data structure in the entire program.

As we work our way through generating moves, evaluating positions, attack detection and other such considerations, we soon discover the shortcomings of our representation, and then re-design this data structure to make the operations more efficient. Engines - How to represent chess state with a bitboard - Chess Stack Exchange. What programming language do you want to use?

engines - How to represent chess state with a bitboard - Chess Stack Exchange

To implement a bitboard in C#, use System.UInt64. This can hold 64 bits, 1 for each square of the chess board. This value type lends itself to many fast bitwise operations. This is a good bitboard tutorial. Here are some examples from my own C# chess engine. Example 1 - Bitboard definition: internal UInt64 WhiteKing; internal UInt64 WhiteQueens; internal UInt64 WhiteRooks; internal UInt64 WhiteBishops; internal UInt64 WhiteKnights; internal UInt64 WhitePawns; internal UInt64 WhitePieces; Example 2 - Bitboard initialisation: Example 3 - Move generation: // We can't capture one of our own pieces. eligibleSquares = ~this.WhitePieces; // Generate moves for white knights. remainingKnights = this.WhiteKnights; // Generate the moves for each knight... while (remainingKnights !

Example 4 - Calculate material score: Example 5 - Calculating piece mobility: Computer Chess Information and Resources. What are some good resources for writing a chess engine. Chess Programming Part I: Getting Started - Artificial Intelligence. This is the first article in a six-part series about programming computers to play chess, and by extension other similar strategy games of perfect information.

Chess Programming Part I: Getting Started - Artificial Intelligence

Chess has been described as the Drosophila Melanogaster of artificial intelligence, in the sense that the game has spawned a great deal of successful research (including a match victory against the current world champion and arguably the best player of all time, Gary Kasparov), much like many of the discoveries in genetics over the years have been made by scientists studying the tiny fruit fly.

This article series will describe some of the state-of-the-art techniques employed by the most successful programs in the world, including Deep Blue. Note that by the time the series is completed (in October), I will have written a simple implementation of the game in Java, and the source code will be freely available for download on my web site. So if you want to see more code samples, be patient; I'll give you plenty in due time!