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
jshriver
Posts: 1342
Joined: Wed Mar 08, 2006 9:41 pm
Location: Morgantown, WV, USA

Legal or Pseudo-Legal Move generation

Post by jshriver »

Since I'm redoing my engine pretty much from scratch, I'm redoing things than last time. Trying for bitboard instead of 12x12 or 144char array.

So I'm wondering, what do you all recommend having the move generator be legal or pseudo-legal?

Last time I was doing pseudo-legal and leaving it up to my evaluator to do legality checks but that seemed to bog it down a bit and make my eval a bit more complex.

Leaning toward legal within movegen first. Curious what you all think.
vladstamate
Posts: 161
Joined: Thu Jan 08, 2009 9:06 pm
Location: San Francisco, USA

Re: Legal or Pseudo-Legal Move generation

Post by vladstamate »

Hi,

I went with pseudo-legal move generator in Plisk. That is all moves are legal, except some of them might leave own king in check which obviously is not legal. For that I check, immediately upon move. Seemed to be pretty fast for me.

Perft, with checking for legal moves, gives me about 8.5-9mil nodes/sec on a 64bit PC - single threaded, no hashing, just moves, verify and unmoves.

Regards,
Vlad.
Dann Corbit
Posts: 12540
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Legal or Pseudo-Legal Move generation

Post by Dann Corbit »

jshriver wrote:Since I'm redoing my engine pretty much from scratch, I'm redoing things than last time. Trying for bitboard instead of 12x12 or 144char array.

So I'm wondering, what do you all recommend having the move generator be legal or pseudo-legal?

Last time I was doing pseudo-legal and leaving it up to my evaluator to do legality checks but that seemed to bog it down a bit and make my eval a bit more complex.

Leaning toward legal within movegen first. Curious what you all think.
Uri Blass has a legal move generator that is very fast, so it is possible to make a very fast legal move generator.
Michael Sherwin
Posts: 3196
Joined: Fri May 26, 2006 3:00 am
Location: WY, USA
Full name: Michael Sherwin

Re: Legal or Pseudo-Legal Move generation

Post by Michael Sherwin »

Dann Corbit wrote:
jshriver wrote:Since I'm redoing my engine pretty much from scratch, I'm redoing things than last time. Trying for bitboard instead of 12x12 or 144char array.

So I'm wondering, what do you all recommend having the move generator be legal or pseudo-legal?

Last time I was doing pseudo-legal and leaving it up to my evaluator to do legality checks but that seemed to bog it down a bit and make my eval a bit more complex.

Leaning toward legal within movegen first. Curious what you all think.
Uri Blass has a legal move generator that is very fast, so it is possible to make a very fast legal move generator.
Uri might have one that is fast, but I have never read that. However, H.G.Muller has one that is very fast, but the published one is not bitboard.
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
User avatar
michiguel
Posts: 6401
Joined: Thu Mar 09, 2006 8:30 pm
Location: Chicago, Illinois, USA

Re: Legal or Pseudo-Legal Move generation

Post by michiguel »

Michael Sherwin wrote:
Dann Corbit wrote:
jshriver wrote:Since I'm redoing my engine pretty much from scratch, I'm redoing things than last time. Trying for bitboard instead of 12x12 or 144char array.

So I'm wondering, what do you all recommend having the move generator be legal or pseudo-legal?

Last time I was doing pseudo-legal and leaving it up to my evaluator to do legality checks but that seemed to bog it down a bit and make my eval a bit more complex.

Leaning toward legal within movegen first. Curious what you all think.
Uri Blass has a legal move generator that is very fast, so it is possible to make a very fast legal move generator.
Uri might have one that is fast, but I have never read that. However, H.G.Muller has one that is very fast, but the published one is not bitboard.
Uri's post about that were in ~2002. He did not start programming the actual engine until he got a fast generator.

Miguel
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: 27790
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.