Legal or Pseudo-Legal Move generation

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Legal or Pseudo-Legal Moves in Move Generator

Legal
9
43%
Pseudo-Legal
12
57%
 
Total votes: 21

User avatar
Roman Hartmann
Posts: 295
Joined: Wed Mar 08, 2006 8:29 pm

Re: Legal or Pseudo-Legal Move generation

Post by Roman Hartmann »

My first engine relied on a legal-move generator. Then I used a mixed approach by using pseudo-legal move generation in the quiescent-search only.

Currently I'm using pseudo-legal move generation in all parts of the engine.

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

Re: Legal or Pseudo-Legal Move generation

Post by hgm »

In Joker (and qperft) I use only a partial legal-move generator. It will not generate moves with pinned pieces that leave you in check, by first determining which pieces are pinned, and then temporarily remove them from the piece list, and generate their moves along the pin line. This saves time in two ways: you don't waste time on generating invalid moves for the pinned pieces, and you don't have to test all other moves for King exposure.

The King moves (incl. castlings) and e.p. captures that are generated are still pseudo-legal, though. Their legality was most efficiently checked only after the move was made (to prevent the King from stepping 'into its own shadow', and detecting the famous e.p. double-pin).

This method does not carry over to other variants, though. So im my Xiangqi engine I am back to pseudo-legal move generation.
Mangar
Posts: 65
Joined: Thu Jul 08, 2010 9:16 am

Re: Legal or Pseudo-Legal Move generation

Post by Mangar »

Hi,

In Spike we have a "nearly - legal - move generator". Spike uses Attack-Tables, thus it is easy to find out where a king may move to. In addition it is very easy to test if king is in check after a move.
IMHO there is no advantage in a legal move generator. It´s only for fun!

Greetings Volker
Mangar Spike Chess
kongsian
Posts: 46
Joined: Thu Jun 15, 2006 11:21 am

Re: Legal or Pseudo-Legal Move generation

Post by kongsian »

I recommend doing a legal move generator. It is not as difficult as it sounds especially with bitboards. What you would need is to generate attacks and pins by the opponent. My perft on a 2.8GHz PC 64bit Linux is 132M nodes/sec with bulk counting.

Kong Sian
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Legal or Pseudo-Legal Move generation

Post by sje »

Symbolic (bitboards) and Myopic (piece sets, source available) use legal-only move generators. All cases including the en passant double pin are handled correctly; it's not that difficult in part because the programs keep track of pinned pieces. The cost of maintaining the pinned piece data is paid by having more efficient generation and more informed positional scoring.

ChessLisp is also legal-only generation and has pinned piece data, as its underlying run time support is based on Symbolic's chess code.
User avatar
Bo Persson
Posts: 243
Joined: Sat Mar 11, 2006 8:31 am
Location: Malmö, Sweden
Full name: Bo Persson

Re: Legal or Pseudo-Legal Move generation

Post by Bo Persson »

Will your search or evaluation depend on the number of legal moves?

Otherwise postponing legality checks until you actually consider performing the move, seems like a win.
Gerd Isenberg
Posts: 2250
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: Legal or Pseudo-Legal Move generation

Post by Gerd Isenberg »

The lazy paradigm to do stuff as late as possible, which might be never due to cut-off or standing pat in QS, might be relativated by doing stuff in parallel with higher ipc or while waiting for some memory reads...

Some other aspects pro legal movegen - one is aware of stalemate and mate in advance and may use "tactical" information from legal movegen elsewhere i.e. pins in eval or mate at a glance.
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Legal or Pseudo-Legal Move generation

Post by hgm »

Bo Persson wrote:Otherwise postponing legality checks until you actually consider performing the move, seems like a win.
You assume here that legal move generation is done by first doing pseudo-legal move generation, followed by checking the move for legality. This need not be true.

For instance, when I have identified a pinned piece, I don't even generate moves for it that leave the pin line. So there is nothing to check, and time is saved on generating the 'pseudo-legal' moves along the pin ray. (Which, in fact, are guaranteed to be legal, and thus need not be checked either.
User avatar
nanochess
Posts: 64
Joined: Thu Feb 19, 2009 5:34 pm
Location: Mexico, Mexico

Re: Legal or Pseudo-Legal Move generation

Post by nanochess »

My vote is for pseudolegal movement generation, is the trick to make Toledo Nanochess very small. :)
By the way, my vote was rejected with a message of 'you're not eligible for this poll'. What this means? :shock: I'm too young?, I'm too tall?, Too few posts? :D
All good things are difficult to achieve.
Toledo Nanochess book http://www.amazon.com/Toledo-Nanochess- ... 1304864375
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: Legal or Pseudo-Legal Move generation

Post by AlvaroBegue »

I've only ever used pseudo-legal move generation, but this idea of not trying to move pinned pieces out of their line seems very attractive.
nanochess wrote:By the way, my vote was rejected with a message of 'you're not eligible for this poll'. What this means? :shock: I'm too young?, I'm too tall?, Too few posts? :D
Too handsome. It has to be that. I got the same message.