Question

I am considering making a chess game for android apps. The only thing I don't know how to do is write code for the opponent AI or how it even works.

Do I have to write the code for the AI from scratch or are there packages that I can just implement?

Was it helpful?

Solution

There are many ways you can go. Most of the chess engines rely on approved chess theortical investigations and have quiet a large bibliothek of them to evalute to first 12 moves of a game. This is why some of them get pretty confused when doing unusual things, which was a winnig approach in the older generations of chess enginges. Bascially it's the taks of encoding the rules of the game and then, of course, find an algorithm to find the best solutions. For that again there are many different approaches, linear optimization is one but has its impacts as the game is rather complex and solving systems of linear inequations is both a memory and cpu consumig task and cannot be multithreaded properly. Another approach is the use of genetic algorythms, which imho fits best to this kind of problem domain as it's encoding of the rules and possible strategies into the genstructer and rating the individuals of an population in the fitness function. This can be spread of multiple threads pretty well, but this approach also has its own impacts, as the required population size will be high which obviously again is a memory consumption.
There are existing solutions such as the metioned http://stockfishchess.org/download/ stockfishchess engine or http://cinnamonchess.altervista.org/, which provide an android api and many resources on the web about how to do it are also available in the net such as http://chessprogramming.wikispaces.com/Chess+for+Android (a starting point).
Also you could try to port an existing chess engine for linux to android such as
http://cinnamonchess.altervista.org/ which should't be to heavy as android is Linux -based and the android replacement for glibc is mostly compatible.
Or you could try a Java chess engine such as https://github.com/albertoruibal/carballo and port it to android, too.
Just search for open source chess engine and you will find many existing solutions.
"The only thing " is pretty amusing in this case, because the main part of writing a chess game is to write the Ai for it.
Another approach could be to use a http://de.wikipedia.org/wiki/Schachserver chess server and communicate with it so that your player can connect to the net and play agains others.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top