Forums

scriptable chess engine?

Sort:
Mijin

I'm a programmer, and I was thinking of writing a chess application that would be designed for scripting of chess variations. So if you had an idea for a variation you could script the rules for it, and even an AI, without requiring any additional software.

The first rule of development though is don't reinvent the wheel (or was it: You *don't* talk about development?). So...is there something like this out there already?

And yes, I have googled it. I've found one or two scripted chess games but they weren't designed to be extensible. 

HGMuller

I don't know what kind of scripting language you had in mind, but Zillions of Games sounds to fit your desires. It is commercial, though.

The Fairy-Max engine is freeware and allows the user to implement Chess variants by specifying the moves of the participating pieces. It is more limited than Zillions, though, and can only do variants on boards with 8 ranks with pieces which do not have side effects to their moves or presence. (So only replacement capture, and no things like Checkers.)

 

It would be great if you could build something more general than Fairy-Max. It would be even greater if you could write that as an engine using a standard protocol, (such as WinBoard protocol), so that it could be used to play automatically against Fairy-Max, ChessV or other variant engines for the variants they have in common. I sometimes run such tournaments (We have done Gothic/Capablanca Chess, Knightmate, and recently Spartan Chess. And of course Chinese Chess, which is an industry in itself with dozens of freeware engines available.)

This would allow you to write the engine as a simple console application, using WinBoard as the GUI. There are experimental WinBoard versions now that are extremely flexible in their ability to support variants. See http://hgm.nubati.net/alien.html .

dave_9990

I am a programmer too, although I do not write C/C++ anymore (maybe once every couple of months I try to type ./configure && make) -- my guess is that the best way to script your engine would be to 

a) edit your opening book to include the scripted lines.

b) Set the engine config to use the books as far as possible. There may be a feature in the book that can allow you to set a preferance for the best move, or you could click the analyze button if you wanted to see whether a line looks good to the machine.

c) tweak the performance parameters, i.e. aggression, king safety, pawn chains etc.

dave_9990

It would be good to have meta data in books that signal to the engine to tweak performance parameters Laughing

dave_9990

I think Rybka and Stockfish have the most tweakable engine settings, Houdini doesn't have as many options, although is arguably the strongest available atm.

Mijin

Ok, I think my opening post was a bit vague.

The kind of thing I was imagining was basically a stand-alone chess app that would be open source and use scripting for everything but a small kernel so that users could edit the code without (direct) compilation. Also the scripts would be written with extensibility fundamental to their design.

So all the logic for standard chess would be in a sub-folder of scripts, called Chess. Then, if you wanted to implement Chess960 you would just copy the Chess folder and modify the SetupBoard script (or just create a folder containing only a SetupBoard script; the app will default to Chess defs for anything you don't define).

I hadn't thought about compatibility with things like WinBoard, but I think it's a good idea.

I also wanted all AI -- book moves, tactical algorithms and heuristics -- to be scriptable too. I would not be especially concerned with making a super-duper, rybka-beating AI, just enough to put up a fight and allow the user to evaluate whether a variation has any obvious exploits.
Whether this last feature is feasible however is another matter. I don't want every variation to require a complete AI from scratch, but reusing AI components might be a tricky programming / definition task.

HGMuller

Well, Chess engines can be written with a very small kernel. The AI of Fairy-Max contains only about 100 lines of C-code. It performs the tree search of the possible lines of play, and evaluates each end leave (at the end of a capture search) by piece values and a bit of centralization bonus. The specification of the moves of the various piece types all come from an array, which is read from a text file. (Which you could consider a form of scripting, albeit not a very general one.) This is enough for a computer rating of ~2000 Elo. (Rybka > 3000)

There is not much a user would have to change in this; the search is almost completely variant independent. (Unless it is a drop game, like Crazyhouse. Then you have to be smart in handling the drops.) The evaluation function could be a more variable area, if you want to build a good one.

Mijin

Huh, I didn't think it would be possible for an AI to play to ~2000 just by looking a few moves ahead. I thought it would get stumped by not putting rooks behind passed pawns, say (or not even trying to queen pawns for that matter).

But I guess it is feasible then to make a general-purpose AI that can play new variations just using a "naive" brute force algorithm.

For fairy pieces it can update the pieces' values based on game results (similar to ELO). This would be useful information to feed back to the user.

HGMuller

Who said Fairy-Max just looks a few moves ahead? That it is only 100 lines of code doesn't tell anything about how far it can search ahead. It happens to search 10-11 ply (+ capture search) in middle-game positions, at 1min/move. But the same code could also search 100 or 1000 ply, given sufficient time (which of course grows exponentially with depth). It just continues deepening the search until it runs out of time. Integers can count upto very high values without overflow, nowadays. ;-)

Deriving piece values from how pieces move is very difficult, and considered a company secret by the manufacturers of Zillions of Games. (No one would have thought that the R+N and B+N compounds are equally strong, for instance.) In Fairy-Max the user has to set the piece values through the input 'script'. And indeed I usually determine those by playing asymmetric games with simple piece substitutions, and looking at the result scores.

Mijin

I think you've misunderstood me. I'm not saying "Only 100 lines of code!? That must be, what, 3 ply?"

I'm saying that I'm surprised that just a brute force algorithm is sufficient to play up to ~2000.

I'm only rated ~1500, and yet I regularly play moves that might not give a material advantage within a dozen moves. Trading bad bishop for good. Rooks behind passed pawns. Hell, castling.

Of course, even setting piece values technically takes an algorithm out of the realm of pure brute force. It's knowledge, beyond the rules of chess.

HGMuller
Mijin wrote:

I think you've misunderstood me. I'm not saying "Only 100 lines of code!? That must be, what, 3 ply?"

I'm saying that I'm surprised that just a brute force algorithm is sufficient to play up to ~2000.

I'm only rated ~1500, and yet I regularly play moves that might not give a material advantage within a dozen moves. Trading bad bishop for good. Rooks behind passed pawns. Hell, castling.

Of course, even setting piece values technically takes an algorithm out of the realm of pure brute force. It's knowledge, beyond the rules of chess.


 Well, search can make up for a lot of knowledge. You are correct that piece values are also knowledge, and Fairy-Max doesn't have a whole lot more. Just that for some pieces it is good to centralize them, that it is bad to move your King before total piece material has dropped below a certain level, that Pawns need to be pushed more vigorously when the board gets empty, on the 6th rank are worth nearly 2, and on the 7th nearly 3. That is about it. (And quite generally applicable across Chess variants.)

Computer ratings are not always comparable to human ratings, as they are only determined from computers playing against each other. But if you want to get an idea of its playing strength, it is included in the WinBoard package you can download from http://hgm.nubati.net/WinBoard-4.5.0.exe .