Legal move generator

Discussion of chess software programming and technical issues.

Moderator: Ras

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

Re: Legal Move Generator

Post by hgm »

grant wrote:Maybe this is stating the obvious but it has only just dawned on me.

If I know that my bishop or rook is pinned and I know the pinner, I need to find out if my piece can move along the pin ray

Code: Select all

rankDiff = (pinner >> 3) ^ (pinned >> 3);
	fileDiff = (pinner & 7) ^ (pinned & 7);
	if (rankDiff == 0 || fileDiff == 0)
		//bishop cannot move
		//rook can move
	else
		//bishop can move
		//rook cannot move
Grant
Indeed. In Joker I first detect pins, ad then for each pinned piece I encounter I generate the moves along the pin ray. (Note this includes a pawn capturing its pinner, something I discovered only late... :oops: ) Then I temporarily mark the pinned piece as captured during the normal move generation.

This was where I went wrong when I converted Joker to play Knightmate, where the Knights move as Kings: A pinned Knight never has any moves, but a pinned King always has two moves along the pin ray. (One ca be blocked by its monarch.) So some moves were never generated... :shock:

In Chinese Chess you can even be pinned by a Knight!