Special cases

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Special cases

Post by Henk »

What is the fastest way to detect if a piece on a1, h1, a8 or h8 is pinned ?
MattieShoes
Posts: 718
Joined: Fri Mar 20, 2009 8:59 pm

Re: Special cases

Post by MattieShoes »

Am I missing something?

return(false); ?
User avatar
hgm
Posts: 27809
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Special cases

Post by hgm »

Depends on the game. :lol:

In (Maka) Dai Dai Shogi there appears a piece called Hook Mover, which moves like a Rook that can turn one corner. So with a black Hook Mover on a8, a white Knight on a1 would be pinned against the white King on e1, there are no pieces between the latter and the rest of the a-file is empty. (And the white King is safely tucked away behind Pawns, so that the othe possible path from a8 to e4 is also blocked.)

[d]r5k1/1ppppppp/8/8/8/1PB5/2PPPPPP/N3K3 w
The Rook represents a Hook Mover, pinning Na1
Last edited by hgm on Fri Dec 18, 2015 10:21 pm, edited 4 times in total.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Special cases

Post by bob »

Henk wrote:What is the fastest way to detect if a piece on a1, h1, a8 or h8 is pinned ?
just use this procedure:

return 0;

a piece on a corner can not possibly be pinned on anything. There is no square behind it along any direction for it to be pinned to anything at all. Are you sure this is what you intended to ask???
MattieShoes
Posts: 718
Joined: Fri Mar 20, 2009 8:59 pm

Re: Special cases

Post by MattieShoes »

> Depends on the game.

Haha very clever. :lol:

In the absence of a variant command, I was assuming chess :-D
Henk
Posts: 7220
Joined: Mon May 27, 2013 10:31 am

Re: Special cases

Post by Henk »

Just a bad joke. And to be sure I was not overlooking something.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Special cases

Post by Evert »

This is actually very tricky, but fortunately you can skip the test in many cases.

First of all, you need to know whether a piece that can do the pinning has been captured. You know this just by inspecting the board. Another precondition is that the king needs to be on a ray with the candidate pinnee (as per usual). Then you need to know where the player placed his captured pieces. If they're beside the board and on the ray with no other obstacles in between (clock, coffee-cup, other pieces), then you can mark the corner piece as "pinned", but if they're not on the ray (or the player placed the captured pieces back in the box), then clearly the piece is not pinned.

As I said though, this is rather difficult to work out for a computer.
User avatar
Desperado
Posts: 879
Joined: Mon Dec 15, 2008 11:45 am

Re: Special cases

Post by Desperado »

Henk wrote:What is the fastest way to detect if a piece on a1, h1, a8 or h8 is pinned ?
First check if the piece in the corner is a pawn, everything else is easy :wink:
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Special cases

Post by Ferdy »

Henk wrote:What is the fastest way to detect if a piece on a1, h1, a8 or h8 is pinned ?
First you need to check if the king is not missing :D . Second check if there are h1, a8 and h8 squares on the board :) .
User avatar
Desperado
Posts: 879
Joined: Mon Dec 15, 2008 11:45 am

Re: Special cases

Post by Desperado »

Ferdy wrote:
Henk wrote:What is the fastest way to detect if a piece on a1, h1, a8 or h8 is pinned ?
First you need to check if the king is not missing :D . Second check if there are h1, a8 and h8 squares on the board :) .
Hi,

i guess your approach is much more safe. I realized that my test has a lack if it is done while promoting.
But don't forget that performance might be an issue too, so maybe we should do a speed check first. Maybe my hack pays off :D .