I have written a chess game some time ago.
This is one way - but it needs some work to be commercially competitive.
Develop a function to analyse a given position in chess and give it a score. The score might be a count of the material (pieces on the board) and some other factors... such as..
- A queen is worth +90, A rook worth +50... A Pawn worth +10, A King worth +infinity etc.
- If two pawns are on the same file = -5
- For each potential move from this position +1.
You can do an exhuastive search through a tree of every potential move, every possible response, etc.. and use what is known as a minimax method. That is search the tree of moves and take the minimum potential maximum scoring value - meaning that the human player will force you into the minimum possible scoring board.
Then - the computer picks the first move in the tree for that position.
You will find that you can search approximately 4 computer/player moves ahead. Any more than this and the tree grows exponentially - it will be too processor intensive to search further forward. The computer will make surprisingly good moves - but you will probably beat it if you try hard.
I am certain that commercial chess games are far more sophisticated than this.
This is all explained in a book - "Computer Gamesmanship" by David Levy.
If you cannot imagine how to do any of this - I could provide you with my source code. If you make any money from it though - I want my cut
