move interpreter vs move generator

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

jhaglund
Posts: 173
Joined: Sun May 11, 2008 7:43 am

move interpreter vs move generator

Post by jhaglund »

Has anyone tried to use a move interpreter?

Example:

You have arrays of all the moves in a certain notation. Making it compatible for different notations should be relatively easy to do...

int pawn_moves[??] = {
"a2a3","a2a4","b2b3","b2b4","b2b3","b2b4","e4e5","e5e6",e7e5","c4c3"..."
};

int pawn_promote_moves[??] =
{
"e7e8q","e7f8r", "d2d1n", h2h1b,...
};

int pawn_ep_moves[??] =
{
"e5f6ep", "a4b5ep", "c4d3ep",...
};

int knight_moves[??] =
{
"b1c3", "g8f6", "d4c6",...
};

int castle_moves[2] =
{
"0-0","0-0-0"
};

//bishop, rook, queen, king moves;
int all_other_piece_moves[??] =
{
"a1h8", "b1c2"...
};

Check board state...
Identify pieces...

Then search arrays for moves that could be played.
If the move isn't in any of the lists it must be illegal... or the game is over.

There wouldn't be anytime wasted in the generation of the moves.

Thoughts?

Joshua D. Haglund
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: move interpreter vs move generator

Post by hgm »

How do you account for blocked slider moves? Or how would you know that a Rook on a1 is not suppsed to do "a1h8"?

Searching arrays is expensive. You tend to access things that in the end you do not want. Normally I generate moves by mostly accessing data that is relevant, skipping the rest without touching it.
jhaglund
Posts: 173
Joined: Sun May 11, 2008 7:43 am

Re: move interpreter vs move generator

Post by jhaglund »

How do you account for blocked slider moves? Or how would you know that a Rook on a1 is not suppsed to do "a1h8"?
When you check the board state after you identify your pieces, you identify open squares, attackable squares, etc... or any other kind of square you want to identify.

1)a1 would be identified as your rook.
a)your rook can have it's own array of moves, which wouldn't have diagonal moves in it.

b)your rook has properties: only moves: up,down, left,right
Searching arrays is expensive
a)Not if they are in memory.
b)Not if the values don't change.
c)There will be little to no comparisons made.
jhaglund
Posts: 173
Joined: Sun May 11, 2008 7:43 am

Re: move interpreter vs move generator

Post by jhaglund »

example:

You identify your piece[sqx][sqy] in the array list for those pieces.

pawn:

a2a3

a2, = sqx;
a3, = sqy;
what is a2?
who is a2?
is a3 open?
is a3 etc...
check pawn_moves array for a2a3.
finds... a2a3.

a2a3 must be legal.
add move list

Help much?
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: move interpreter vs move generator

Post by hgm »

And why don't you call that a move generator? It seems you want to run some complex decision-making algorithm, which does exacly what a move generator does...
jhaglund
Posts: 173
Joined: Sun May 11, 2008 7:43 am

Re: move interpreter vs move generator

Post by jhaglund »

And why don't you call that a move generator? It seems you want to run some complex decision-making algorithm, which does exacly what a move generator does...
The move is not being generated, it's being interpreted and verified as legal or not.

If the goal is to play chess then, yes, it is a move generator...

You'd have all the moves in the game of chess, at your fingertips, every move. :wink:
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: move interpreter vs move generator

Post by hgm »

It seems to me this is just a table-driven move generator. Most move generators work with tables. Of course move representation differs, depending on the engine. Character strings are not a very efficient representation. Bitboards are more popular; then each moves take only a single bit. In magic move generation you have huge tables of such pre-cooked move lists, in bitboard format.

There are also schemes (I think GNU Chess 4 used it) where you have a table of moves that also contain the address of the next move in the list (so you can directly jump there, without having to judge the invalid ones you skip over). Both for the case for when the current square is empty, and when it is occupied.

A table can be seen as a dedicated program, with each table entry an instruction in some dedicated programming language for move generation. The interpreter for that language is the move generator. Fairy-Max has a table-driven move generator. That is why it is so easy for it to switch variants. Just reload the tables, and the pieces move differently.
jhaglund
Posts: 173
Joined: Sun May 11, 2008 7:43 am

Re: move interpreter vs move generator

Post by jhaglund »

It seems to me this is just a table-driven move generator.

Not exactly, it's array driven, with tables for evaluation(s) and verification.

Most move generators work with tables. Of course move representation differs, depending on the engine. Character strings are not a very efficient representation....
Yes, comparing strings can be slow, but that isn't what it does. It looks at the input, says if it's legal and whatnot, because it interprets what the string means.
There are also schemes (I think GNU Chess 4 used it) where you have a table of moves that also contain the address of the next move in the list (so you can directly jump there, without having to judge the invalid ones you skip over). Both for the case for when the current square is empty, and when it is occupied.
However you want to store the move list(s), open squares, etc, is upto the usage. I'd prefer to flag the array move with a 1 or 0 and not have to revisit checking if moves are possible, for that particular ply.
A table can be seen as a dedicated program, with each table entry an instruction in some dedicated programming language for move generation. The interpreter for that language is the move generator.
The interpreter would also be the notation recognizer & sanity check...

It would be like having an engine think with fen strings, but with a chess notation instead.
Fairy-Max has a table-driven move generator
Speaking of Fairy-Max, how come it's the default engine under winboard? It doesn't seem to want to change, even when editing winboard.ini. I'd prefer Crafty as it's default, and included because of it's strength, etc... for the winboard package. :D
That is why it is so easy for it to switch variants. Just reload the tables, and the pieces move differently.
Sounds doable.
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: move interpreter vs move generator

Post by hgm »

jhaglund wrote:Speaking of Fairy-Max, how come it's the default engine under winboard? It doesn't seem to want to change, even when editing winboard.ini. I'd prefer Crafty as it's default, and included because of it's strength, etc... for the winboard package. :D
That is weird. WinBoard should always never by itself use a default engine (unlike XBoard). When you start it without /fcp or /scp it should always pop up the startup dialog to chose the engine. And what is in the combo boxes there should be what was in the winboard.ini, unless that did not exist, or you overruled it with an /fcp or /scp on the command line.

How do you start WinBoard?

Crafty is not made standard engine, because it only plays variant normal. It is not included in the package because it is quite big. Fairy-Max adds only some 30KB to the package.

For playing strength in Chess, Fruit is included. It is smaller and stronger than Crafty, and also open source. In future release I might switch to Stockfish. But the WinBoard install is not intended as a distribution vehicle for engines. It provides them as an example for how the various type of engines must be installed. If you give people the strongest engine that is around, they will get lazy, and will never have motivation to learn how to install another one.

This is actually quite funny: when I released WinBoard for the blind, they were very excited, and the first thing they did was figuring out how to install Crafty, of which they had all heard. Fruit did not mean anything to them. They all thought: "wow, this is not just a speaking Chess GUI, but ist is WinBoard, which can run the famous Crafty program, so we can have the strongest computer Chess in the World". When they finally succeded, they had Crafty play against the pre-installed Fruit, and they were completely taken aback that it was crushed... :lol:
jhaglund
Posts: 173
Joined: Sun May 11, 2008 7:43 am

Re: move interpreter vs move generator

Post by jhaglund »

How do you start WinBoard?
With the shortcut...
Crafty is not made standard engine, because it only plays variant normal
That's all I play is normal chess.
It is smaller and stronger than Crafty
Disagrees. A couple years ago, yes. Not anymore. It's been awhile since you've used Crafty? It's better than any version I've had, even without position.lrn..... just think if he'd reimplement that... and now... working on singular extentions...Whoa! Lookout! :D

Winboard isn't winboard without Crafty.

Winboard -> winboard engine -> Crafty, about 205kb zipped. Less than 1 second to download.

I only use UCI engines in Chessbase.

Food for thought...