need suggestion for callable Chess engine

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

mlevin77

need suggestion for callable Chess engine

Post by mlevin77 »

As part of an artificial life experiment, I need to run a tournament
where different computer programs play each other, in games like chess
or checkers (I'm looking for games that rely less on less brute-force and more on interesting AI algorithms). There will be no human players (so no
GUI needed), and I need an API or some source code (preferably in C)
so that my main tournament program can call the chess engines and have
them play a game against each other and see who wins. I'd also like to
be able to modify the "level" of play of each artificial player on the
fly: that is, when choosing among a set of moves, or deciding how far
to look ahead, I'd like to pass it a parameter "Q" (quality of
player), say from 1 to 10, which tells it how good a move to generate.
So, in pseudocode, something like this:

declare common chess board C;
initialize players p1, p2;
while (no winner)
{
Q=decide_quality();
move(p1,C,Q);
Q=decide_quality();
move(p2,C,Q);
}
print who won;

The key is that I be able to control the quality of each player's move on the fly (during a game). This may seem like a weird thing to do, and it doesn't really matter how the Q will be decided each time (the above piece is part of a much larger framework that will handle all this). I need advice: what is the chess engine/source code set that will make it easiest to do something like this (play artificial players against each other in a loop, adjusting the "strength" of each player during a game).
Any suggestions would be greatly appreciated!

Mike
User avatar
hgm
Posts: 27794
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: need suggestion for callable Chess engine

Post by hgm »

It depends a lot on which degree of control you want to have over the move quality. Most existing engines only allow quality adjustment through setting the time or limiting the search depth (where 'search depth' might have a meaning that differs from engine to engine).

If that is enough, you could call any WinBoard or UCI engine as an external process, communicating with it through a pipe.

If you want to control details of how the search or evaluation works, you are almost forced to include the engine as a subroutine in your code, and be intimately familiar with its inner workings. That would be very hard, especially if you want to use several different engines.

My own engine micro-Max could be used for this purpose: it consists of only a single subroutine of about 100 lines of C-code, which you can call after setting the nominal number of nodes to search in a global variable (determining the move quality), and copying the position it has to move from to the global board array. It will then find the move it prefers, and perform it on the board, before returning.

The search time (or nr of nodes) is a rather course way to tune the move quality, though: uMax, like most engines, deepens the search iteratively in steps of 1 ply, and once it decides starting an iteration, it does finish it completely. But even if you would alter it to abort an iteration, it would mean it almost always returns the move of the previous iteration. Chess programs only change the preferred move rarely, as search time progresses. Most of the time even the next iteration produces the same move. A more continuous way to lower the move quality would be to add a random value of adjustable magnitude to the score of each root move, before picking the best.

State-of-the art Chess programs do rely quite heavily on brute force, though...
Aleks Peshkov
Posts: 892
Joined: Sun Nov 19, 2006 9:16 pm
Location: Russia

Re: need suggestion for callable Chess engine

Post by Aleks Peshkov »

Almost any chess program can play against any other (or another self copy) chess program without human assistance.

IMHO game go is better for current state of AI experiments.
rreagan
Posts: 102
Joined: Sun Sep 09, 2007 6:32 am

Re: need suggestion for callable Chess engine

Post by rreagan »

You can write a program to communicate with chess engines using either the UCI or Winboard protocol. The significant majority of free chess engines support one of those two protocols (or both).

UCI protocol:
http://www.horizonchess.com/FAQ/Winboar ... y2005.html

Winboard protocol:
http://www.tim-mann.org/xboard/engine-intf.html

You could adjust the level of play in a few ways. The protocols have options to limit the search depth (ex. "only look 4 moves ahead"), or limit the amount of time to search (ex. "only think for 5 seconds").
mlevin77

Re: need suggestion for callable Chess engine

Post by mlevin77 »

Aleks Peshkov wrote:Almost any chess program can play against any other (or another self copy) chess program without human assistance.
IMHO game go is better for current state of AI experiments.
Thanks for the info everyone!! With respect to "Go", same question: can someone provide a link for an API or callable engine for this game?

Mike
mlevin77

Re: need suggestion for callable Chess engine

Post by mlevin77 »

rreagan wrote:You can write a program to communicate with chess engines using either the UCI or Winboard protocol. The significant majority of free chess engines support one of those two protocols (or both).

UCI protocol:
http://www.horizonchess.com/FAQ/Winboar ... y2005.html

Winboard protocol:
http://www.tim-mann.org/xboard/engine-intf.html

You could adjust the level of play in a few ways. The protocols have options to limit the search depth (ex. "only look 4 moves ahead"), or limit the amount of time to search (ex. "only think for 5 seconds").
are these deterministic? that is, if two programs play against each other, will they always play the same game or is there an element of pseudorandom choice somewhere in the algorithm?

Mike
mlevin77

Re: need suggestion for callable Chess engine

Post by mlevin77 »

hgm wrote:It depends a lot on which degree of control you want to have over the move quality. Most existing engines only allow quality adjustment through setting the time or limiting the search depth (where 'search depth' might have a meaning that differs from engine to engine).
If that is enough, you could call any WinBoard or UCI engine as an external process, communicating with it through a pipe.
If you want to control details of how the search or evaluation works, you are almost forced to include the engine as a subroutine in your code, and be intimately familiar with its inner workings. That would be very hard, especially if you want to use several different engines.
My own engine micro-Max could be used for this purpose: it consists of only a single subroutine of about 100 lines of C-code, which you can call after setting the nominal number of nodes to search in a global variable (determining the move quality), and copying the position it has to move from to the global board array. It will then find the move it prefers, and perform it on the board, before returning.
The search time (or nr of nodes) is a rather course way to tune the move quality, though: uMax, like most engines, deepens the search iteratively in steps of 1 ply, and once it decides starting an iteration, it does finish it completely. But even if you would alter it to abort an iteration, it would mean it almost always returns the move of the previous iteration. Chess programs only change the preferred move rarely, as search time progresses. Most of the time even the next iteration produces the same move. A more continuous way to lower the move quality would be to add a random value of adjustable magnitude to the score of each root move, before picking the best.
am I wrong in thinking that before picking a move, the program makes a list of several moves and ranks them according to how good they are? If so, isn't this the idea place to control quality - make it sometimes pick a move that isn't at the top of the list?

Mike
rreagan
Posts: 102
Joined: Sun Sep 09, 2007 6:32 am

Re: need suggestion for callable Chess engine

Post by rreagan »

mlevin77 wrote:are these deterministic? that is, if two programs play against each other, will they always play the same game or is there an element of pseudorandom choice somewhere in the algorithm?

Mike
It will be different for each program. Simple programs should produce the same results for the same search depth, but the more complex programs may not. Some programs do some form of learning over time, and programs supporting multiple processors are not guaranteed to produce the same output. Usually, programs will give more or less the same output, but if you are needing to prove that a program is deterministic (ex. for academic research), then you may be stuck with a handful of simpler programs (TSCP, and similar open source programs).

I believe there is a similar protocol for Go (Go Text Protocol, maybe?), but I have never used it.
User avatar
hgm
Posts: 27794
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: need suggestion for callable Chess engine

Post by hgm »

mlevin77 wrote: am I wrong in thinking that before picking a move, the program makes a list of several moves and ranks them according to how good they are? If so, isn't this the idea place to control quality - make it sometimes pick a move that isn't at the top of the list?
Normally a Chess program only worries about findingthe strongest move, and only tries to prove for the other moves thatthey are wrong. In this proces the ordering of theother moves gets lost, i.e. the program has no idea what the second best move is.

But the same effect which you describe can be realized by adding a random value to the score of each move, and then apply the usual procedure for finding the best one including this random value. The one that comes out as best then does not necessarily have to be the best on its own merit, it might just have been lucky to draw a large positive random bonus.

The larger the random values, the larger the difference in score between a move that can still be chosen and the best move (or at least what the program thinks is the best move). So this is a very good way to continuously tune the move quality (as I already mentioned), and it adds randomness at the same time. In the limit of extremely large random values, the true score is no longer significant, and the program simply becomes a random mover.

This is not a standard feature in most engines, though. (Or in fact of any engine I am aware of.) But it is easy to implement.
Gerd Isenberg
Posts: 2250
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: need suggestion for callable Chess engine

Post by Gerd Isenberg »

Welcome back Russell!
Still bitboarding?

Cheers,
Gerd