Pins

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

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

Pins

Post by Henk »

[d] r2qkbnr/1pp1pppp/2np4/pB6/3PP1b1/2N2N2/PPP2PPP/R1BQK2R b KQkq - 2 5

In this position Skipper needs almost a second to find a good move against a pin. Isn't there a way to get it quicker without slowing down search. I remember a year ago I implemented pin detection but performance degraded so I removed it.

Code: Select all

Depth  Value   Time
  1    3.07   0.019          33   g4f3 
  2   -0.21   0.006         163   g4f3 d1f3 
  3    0.70   0.004         274   g4f3 g2f3 c6d4 
  4    0.19   0.009        1271   d8c8 b5c6 b7c6 d4d5 
  5   -0.19   0.060        6639   g4f3 g2f3 a5a4 d4d5 g8h6 
  6    0.19   0.773       83412   e7e6 a2a4 d8d7 b5c6 d7c6 f3h4 
  7    0.00   0.907      108089   g4d7 e4e5 c6a7 b5d7 d8d7 e5d6 d7d6 
  8   -0.01   5.181      694164   g4d7 d1d3 c6a7 a2a3 d7b5 c3b5 a7b5 d3b5 
  9   -0.01   3.712      529422   g4d7 f3g5 c6a7 b5d7 d8d7 c1f4 f7f5 e4f5 d7f5 
 10   -0.01   30.997     4822061   g4d7 0-0 c6b8 b5d7 b8d7 d1e2 d7b8 e4e5 d6e5 e2e5 
 11   -0.01   52.624     7793753   g4d7 f3g5 f7f6 g5f3 c6a7 b5d7 d8d7 d1d2 e8f7 c3b1 f7e6 
Uri Blass
Posts: 10108
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Pins

Post by Uri Blass »

I think that it is better if Skipper learn the chess rules
g4f3 g2f3 c6d4 is the line at depth 3.
c6d4 is an illegal move.

If your move generator generates c6d4 then I think that it is better to correct it and your program should memorize information about pinned pieces and not generate moves with a knight that is pinned(You need also to update the information after every move that you make).
Henk
Posts: 7210
Joined: Mon May 27, 2013 10:31 am

Re: Pins

Post by Henk »

Something wrong here. I already don't understand why it does give totally wrong score at depth 1.
User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 10:05 pm
Location: Italy
Full name: Stefano Gemma

Re: Pins

Post by stegemma »

Henk wrote:Something wrong here. I already don't understand why it does give totally wrong score at depth 1.
It looks like if you don't have quiescence search or SEE is wrong. At ply 1, taking the knight would give you +3 only if you don't take care of following recapture.
Author of Drago, Raffaela, Freccia, Satana, Sabrina.
http://www.linformatica.com
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Pins

Post by cdani »

Henk wrote:I remember a year ago I implemented pin detection but performance degraded so I removed it.
With bitboards is a bit elaborated but pretty fast. For example at Discocheck engine:

Code: Select all

Bitboard Board::hidden_checkers(bool find_pins, int color) const
{
	assert(initialized && color_ok(color) && (find_pins == 0 || find_pins == 1));
	const int aside = color ^ find_pins, kside = opp_color(aside);
	Bitboard result = 0ULL, pinners;

	// Pinned pieces protect our king, dicovery checks attack the enemy king.
	const int ksq = king_pos[kside];

	// Pinners are only sliders with X-ray attacks to ksq
	pinners = (get_RQ(aside) & bb::rattacks(ksq)) | (get_BQ(aside) & bb::battacks(ksq));

	while (pinners) {
		int sq = bb::pop_lsb(&pinners);
		Bitboard skewered = &#40;bb&#58;&#58;between&#40;ksq, sq&#41; ^ &#40;1ULL << sq&#41;) & st&#40;).occ;

		if (!bb&#58;&#58;several_bits&#40;skewered&#41; && &#40;skewered & all&#91;color&#93;))
			result |= skewered;
	&#125;
	return result;
&#125;
Basically is counting the pieces between the possible checkers (sliders aligned with the king), and if there is one of the same color of the king, then is pinned.

I use this technique in Andscacs not one but three times in each node, to search for pinned pieces of each player, and to discover pieces tan can make discovered check. This makes easy and fast to find illegal moves also.
Henk
Posts: 7210
Joined: Mon May 27, 2013 10:31 am

Re: Pins

Post by Henk »

stegemma wrote:
Henk wrote:Something wrong here. I already don't understand why it does give totally wrong score at depth 1.
It looks like if you don't have quiescence search or SEE is wrong. At ply 1, taking the knight would give you +3 only if you don't take care of following recapture.
Yes very stupid bug in qSearch. I already repaired it. Forgot to call the move generator. I reintroduced qSearch this morning. But I was not careful. Before this qSearch and normal search were one routine for I wanted to have as less code as possible. Less code less bugs.

But still there is another bug, for PV at depth 4 is idiotic. Perhaps evaluation for I changed king safety too lately.

Code: Select all

Depth  Value   Time
  1    0.01   0.023          91   e7e6 
  2    0.00   0.031        1615   f7f5 h1g1 
  3    0.00   0.061        4942   g4d7 d4d5 c6b4 
  4   -0.01   0.390       18632   e7e6 e1e2 f7f5 d1f1 
  5    0.00   0.525       28789   g4d7 g2g3 g8f6 d4d5 c6b8 
  6   -0.01   1.119       70666   g4d7 d4d5 c6b4 b5d7 d8d7 h2h4 
  7    0.00   2.326      197578   g4d7 a1b1 h7h5 d4d5 c6a7 b5d7 d8d7 
  8    0.00   8.120      741980   g4d7 d4d5 c6a7 b5d7 d8d7 f3d4 c7c5 d4f5 
  9    0.00   23.092     2249717   g4d7 d4d5 c6a7 b5d7 d8d7 c1f4 a7b5 a2a4 b5a7 
 10    0.00   90.007     8978384   g4d7 a2a3 a8c8 d4d5 c6a7 b5d7 d8d7 d1d4 a7b5 c3b5 
matthewlai
Posts: 793
Joined: Sun Aug 03, 2014 4:48 am
Location: London, UK

Re: Pins

Post by matthewlai »

Henk wrote:Before this qSearch and normal search were one routine for I wanted to have as less code as possible. Less code less bugs.
I did that for a very long time as well, but eventually splited it out to a different function. As you add more and more things to search, you'll find that many of them don't really make sense for q-search, so you'd need to add a lot of if statements. At that point the code would be simpler if you just separate out the q-search.

Less code less bugs, but less complicated code also less bugs, and in this case less code means more complicated code.
Disclosure: I work for DeepMind on the AlphaZero project, but everything I say here is personal opinion and does not reflect the views of DeepMind / Alphabet.
Henk
Posts: 7210
Joined: Mon May 27, 2013 10:31 am

Re: Pins

Post by Henk »

[d] 1n2q1k1/rb2n1p1/1p1p2Np/pP3B2/P2P1r2/2N5/2P1Q1PP/2KR3R b - - 3 25

Do you also check other pins ? For instance in position above knight on e7 can not move otherwise it loses it's queen.

So there are minor pieces that shield major pieces or pieces that shield undefended pieces but cannot defend the undefended pieces when chased away.
Joost Buijs
Posts: 1562
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: Pins

Post by Joost Buijs »

Henk wrote:[d] 1n2q1k1/rb2n1p1/1p1p2Np/pP3B2/P2P1r2/2N5/2P1Q1PP/2KR3R b - - 3 25

Do you also check other pins ? For instance in position above knight on e7 can not move otherwise it loses it's queen.

So there are minor pieces that shield major pieces or pieces that shield undefended pieces but cannot defend the undefended pieces when chased away.
This is typically where your (quiescence) search is for, to resolve this kind of tactical stuff.
It is impossible to solve this in a static evaluation function because it is way too complex or too time consuming.
Henk
Posts: 7210
Joined: Mon May 27, 2013 10:31 am

Re: Pins

Post by Henk »

Joost Buijs wrote:
Henk wrote:[d] 1n2q1k1/rb2n1p1/1p1p2Np/pP3B2/P2P1r2/2N5/2P1Q1PP/2KR3R b - - 3 25

Do you also check other pins ? For instance in position above knight on e7 can not move otherwise it loses it's queen.

So there are minor pieces that shield major pieces or pieces that shield undefended pieces but cannot defend the undefended pieces when chased away.
This is typically where your (quiescence) search is for, to resolve this kind of tactical stuff.
It is impossible to solve this in a static evaluation function because it is way too complex or too time consuming.
Maybe give a penalty if a piece is undefended in middle game. But that may also be too costly.