Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I created chess game with python and pygame. Now I'm trying to make Artificial intelligence, but what is actually best way to do it? Some tips, tricks, links?
Thanks

share|improve this question

closed as too broad by bummzack, Jari Komppa, Byte56 Jun 12 '14 at 13:21

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs. If this question can be reworded to fit the rules in the help center, please edit the question.

    
Tip: search google before posting here... Link: gamedev.net/page/resources/_/technical/artificial-intelligence/… it isn't in your choice of language but I'm sure if you put your mind to it, you can utilize the procedures... –  Savlon Jun 12 '14 at 10:00

1 Answer 1

First, you need a rating function. A rating-function analyzes the board, rates which player currently appears to have an advantage, and outputs it as a positive (white has an advantage) or negative (black has an advantage) number.

A trivial way to do this is to just count the material advantage using the relative value system (pawn: 1, bishop: 3, knight: 3, rook: 5, queen: 9). But a more advanced function would also take into account how well the pieces are positioned (for example by increasing value when the piece threatens or protects other pieces or reducing value when it is threatened itself without being adequately protected).

A mate-position would have a rating of +∞ or -∞, depending on which player mates.

Then you use this function to calculate the rating of every currently possible AI move followed by every possible player response to that move. Then pick the AI move where the enemy response with the worst rating (from the PoV of the AI) is still rated higher than the worst-rated response of every other AI move.

A cheap way to make the AI stronger is to not just explore one move into the future but several moves. But keep in mind that the computation time will increase exponential. A much more efficient and elegant way, however, is usually to improve your rating function so the AI can make better strategic decisions.

This method is called the minmax algorithm, and it can be applied to any turn-based game without information hiding. The only thing you have to adapt to each game is the rating function. In a game like chess with a large number of possible moves each turn, the performance can be enhanced through alpha-beta pruning (not following obviously bad tree branches).

Another enhancement which is implemented by most chess engines is an opening library. Chess opening theory is a very well-researched area which is much too complex to model with one simple algorithm. There are whole books which just explore the strategical aspects of one single chess opening. That's why chess engines do the same thing most chess players do: Learn the most common openings and the usual reactions to them and just play them from memory.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.