I'm looking for a program or library that I could use for experimenting with board games (chess mostly, but not necessarily -- other similarly complex board games
are OK too). I'll test different game-playing algorithms.

This is what I need:

* I'd like, if possible, to make my program play against
players like gnuchess and crafty, but also against itself
and against a human player;
* It's OK if my player-program can communicate with the 
"server" via TCP, but it would be even nicer if it had 
a C interface (not C++, because then I'd have to write
a wrapper);
* I may want to change the game rules (initial position of
pieces, number of pieces, and even movement rules);
* Flexible (it's OK if the library/server validates
chess moves, for example, but I'd like such feature to be
optional because I will want to turn it off for some
experiments);
* Free (I may want to get into the source code and maybe
change a few bits).

I'd be grateful if anyone could point me to such a library/server...

Thanks a lot!

P.S.: I wanted to include a "board-games" tag, but it seems that I'd need more reputation for that...

P.S. 2: I'd like to accept two answers (they're complementary). It's a pity StackOverflow doesn't allow that.