Test position that requires KKP evaluation

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Test position that requires KKP evaluation

Post by cdani »

hgm wrote:In practice it is not necessary to solve all positions. You only need to recognize some tedious draws that can be quickly reached. E.g. a lot of positions are draws because the Pawn will be lost. But the search will find those quickly. (OTOH, they also are not difficult to recognize, with the aid of a distance table.) What the search needs help with is 'stand-off' positions, where it is a draw, but you can drag it out almost indefinitely by aimlessly moving around in the draw sector. E.g. in KBPK, where the leading side can keep the material advantage hundreds of moves without repeating by touring the board with its King, and then stepping the Bishop to another square on the diagonal of the Pawn to make another King toer, etc. Those draws the search would never find.
I have done a function for kbpk endgame, solving 894706 of 1182440 different positions. If someone is interested I can post it.
brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

Re: Test position that requires KKP evaluation

Post by brtzsnr »

I would be curios just in case I'll want to add more knowledge. Do you know how much you loose when you disable these functions? Also, what about the remaining 1182440-894706 positions? Is the result wrong or just undecided?
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Test position that requires KKP evaluation

Post by cdani »

brtzsnr wrote:I would be curios just in case I'll want to add more knowledge. Do you know how much you loose when you disable these functions? Also, what about the remaining 1182440-894706 positions? Is the result wrong or just undecided?
If you follow the example in the other link I posted, this one follows the same idea. Is a function that resolves kbpk positions by code comparing the result to a bitbase. So it sholud be transformed to something usable.

I have done it more for fun that to be used. This function can be added to the same solution of the other link.

The remaining positions simply are not worked, because it starts to be very complicated to figure code to resolve them.

Code: Select all

	void endgame_kbpk(Position& pos) {
		long long totalpositions = 0;
		long long resolvedpositions = 0;
		long long unresolvedwins = 0;
		long long unresolveddraws = 0;
		int unknown = 999;
		bool first_unresolved_shown = false;
		for &#40;Square bk = SQ_A1; bk <= SQ_H8; bk++) &#123;
			for &#40;Square wk = SQ_A1; wk <= SQ_H8; wk++) &#123;
				if &#40;SquareDistance&#91;bk&#93;&#91;wk&#93; <= 1&#41;
					continue;
				for &#40;Square b = SQ_A1; b <= SQ_H8; b++) &#123;
					if &#40;b == wk || b == bk || &#40;DarkSquares & b&#41;)
						continue;
					for &#40;Square p = SQ_H2; p <= SQ_H7; p += &#40;Square&#41;8&#41; &#123;
						//for &#40;Square p = SQ_H6; p >= SQ_H6; p -= &#40;Square&#41;8&#41; &#123;
						if &#40;p == wk || p == bk || p == b&#41;
							continue;
						for &#40;Color c = WHITE; c <= BLACK; ++c&#41; &#123;	//turn
							pos.clear&#40;);
							pos.thisThread = Threads.main&#40;);
							pos.st->epSquare = SQ_NONE;
							pos.put_piece&#40;WHITE, PAWN, p&#41;;
							pos.put_piece&#40;WHITE, KING, wk&#41;;
							pos.put_piece&#40;BLACK, KING, bk&#41;;
							pos.put_piece&#40;WHITE, BISHOP, b&#41;;
							pos.sideToMove = c;
							pos.set_state&#40;pos.st&#41;;
							if &#40;pos.attackers_to&#40;pos.king_square&#40;~c&#41;) & pos.pieces&#40;c&#41;)
								continue; //illegal position
							int own = unknown, found, v = Tablebases&#58;&#58;probe_wdl&#40;pos, &found&#41;;
							if (!found&#41; &#123;
								sync_cout << "Error not found; pawn&#58; " << UCI&#58;&#58;square&#40;p&#41; << " wk&#58; " << UCI&#58;&#58;square&#40;wk&#41; << " bishop&#58; " << UCI&#58;&#58;square&#40;b&#41; << " bk&#58; " << UCI&#58;&#58;square&#40;bk&#41; << sync_endl;
								return;
							&#125;
							totalpositions++;

							if &#40;rank_of&#40;bk&#41; < rank_of&#40;p&#41; && c == WHITE && &#40;file_of&#40;b&#41; != 7 || rank_of&#40;b&#41; < rank_of&#40;p&#41;)) //pawn scapes
								own = 2; //237166

							//pawn blocked
							//exceptions&#58; 8/8/8/5B2/7k/2K5/7P/8 w - - 0 1
							if &#40;own == unknown && file_of&#40;bk&#41; == 7 && rank_of&#40;bk&#41; > rank_of&#40;p&#41; && rank_of&#40;bk&#41; > 5&#41;
								own = 0; //37299

							//pawn can be captured
							if &#40;own == unknown && SquareDistance&#91;bk&#93;&#91;p&#93; == 1&#41; &#123;
								pos.remove_piece&#40;BLACK, KING, bk&#41;;  //some exceptions when bishop checking and defending indirectly the pawn
								if (!&#40;pos.attackers_to&#40;p&#41; & pos.pieces&#40;WHITE&#41;))
									if &#40;c == BLACK || &#40;b == make_square&#40;&#40;File&#41;7, rank_of&#40;p&#41; + &#40;Rank&#41;1&#41; &&
										&#40;SquareDistance&#91;wk&#93;&#91;p&#93; > 2 || wk == make_square&#40;&#40;File&#41;5, rank_of&#40;p&#41; - &#40;Rank&#41;1&#41;) //second verification implies black king prevents white king to defend the pawn
										)) //black's turn or pawn blocked by bishop and king does not arrives to defend it
										own = 0; //42194
								pos.put_piece&#40;BLACK, KING, bk&#41;;
							&#125;

							//pawn can be captured because is blocked and undefendable
							if &#40;own == unknown && (&#40;SquareDistance&#91;bk&#93;&#91;p&#93; == 2 && c == BLACK&#41; || &#40;SquareDistance&#91;bk&#93;&#91;p&#93; == 1 && c == WHITE&#41;)
								//&& b == make_square&#40;&#40;File&#41;7, rank_of&#40;p&#41; + &#40;Rank&#41;1&#41; && SquareDistance&#91;wk&#93;&#91;p&#93; > 2 && rank_of&#40;bk&#41; <= rank_of&#40;p&#41;)
								&& b == make_square&#40;&#40;File&#41;7, rank_of&#40;p&#41; + &#40;Rank&#41;1&#41; && &#40;SquareDistance&#91;wk&#93;&#91;p&#93; > 2 || &#40;rank_of&#40;wk&#41; <= rank_of&#40;bk&#41; && file_of&#40;wk&#41; < file_of&#40;bk&#41;)) && rank_of&#40;bk&#41; <= rank_of&#40;p&#41;)
								own = 0; //561

							if &#40;own == unknown && SquareDistance&#91;bk&#93;&#91;SQ_H8&#93; == 1&#41;
								own = 0; //21244

							//stalemate
							if &#40;own == unknown && c == BLACK && (
								(&#40;file_of&#40;bk&#41; == 0 || file_of&#40;bk&#41; == 7&#41; && SquareDistance&#91;bk&#93;&#91;b&#93; == 1 && SquareDistance&#91;bk&#93;&#91;wk&#93; == 2 && rank_of&#40;b&#41; == rank_of&#40;bk&#41; && rank_of&#40;wk&#41; == rank_of&#40;bk&#41;)
								||
								(&#40;rank_of&#40;bk&#41; == 0 || rank_of&#40;bk&#41; == 7&#41; && SquareDistance&#91;bk&#93;&#91;b&#93; == 1 && SquareDistance&#91;bk&#93;&#91;wk&#93; == 2 && file_of&#40;b&#41; == file_of&#40;bk&#41; && file_of&#40;wk&#41; == file_of&#40;bk&#41;)
								)
								)
								own = 0; //81

							//stalemate
							if &#40;own == unknown && c == BLACK && (
								&#40;bk == SQ_A1 && &#40;pos.attackers_to&#40;SQ_A2&#41; & pos.pieces&#40;WHITE&#41;) && &#40;pos.attackers_to&#40;SQ_B1&#41; & pos.pieces&#40;WHITE&#41;))
								||
								&#40;bk == SQ_A8 && &#40;pos.attackers_to&#40;SQ_A7&#41; & pos.pieces&#40;WHITE&#41;) && &#40;pos.attackers_to&#40;SQ_B8&#41; & pos.pieces&#40;WHITE&#41;))
								||
								&#40;bk == SQ_H1 && &#40;pos.attackers_to&#40;SQ_H2&#41; & pos.pieces&#40;WHITE&#41;) && &#40;pos.attackers_to&#40;SQ_G1&#41; & pos.pieces&#40;WHITE&#41;))
								||
								&#40;bk == SQ_H8 && &#40;pos.attackers_to&#40;SQ_H7&#41; & pos.pieces&#40;WHITE&#41;) && &#40;pos.attackers_to&#40;SQ_G8&#41; & pos.pieces&#40;WHITE&#41;))
								||
								&#40;bk == SQ_F8 && &#40;pos.attackers_to&#40;SQ_F7&#41; & pos.pieces&#40;WHITE&#41;) && &#40;pos.attackers_to&#40;SQ_G8&#41; & pos.pieces&#40;WHITE&#41;) && &#40;wk == SQ_D8 || wk == SQ_D7&#41;)
								||
								&#40;bk == SQ_F8 && b == SQ_F7 && p == SQ_H6 && wk == SQ_E6&#41;
								)
								)
								own = 0; //223

							//stalemate
							if &#40;own == unknown && c == BLACK && wk == SQ_F6 && p == SQ_H7 && bk == SQ_F8 && &#40;pos.attacks_from<BISHOP>&#40;b&#41; & SQ_E8&#41;)
								own = 0; //6

							if &#40;own == unknown && rank_of&#40;bk&#41; < rank_of&#40;p&#41; - 1 && c == BLACK && &#40;file_of&#40;b&#41; != 7 || rank_of&#40;b&#41; < rank_of&#40;p&#41;)) //pawn scapes
								own = 2; //197207

							if &#40;own == unknown && rank_of&#40;p&#41; == 1 && rank_of&#40;bk&#41; <= 1 && &#40;file_of&#40;b&#41; != 7 || rank_of&#40;b&#41; < rank_of&#40;p&#41;)) &#123;//pawn scapes advancing 2 squares
								if &#40;c == WHITE || &#40;rank_of&#40;bk&#41; == 0 && &#40;SquareDistance&#91;wk&#93;&#91;p&#93; == 1 || SquareDistance&#91;bk&#93;&#91;p&#93; > 1&#41;))  //white's turn or pawn defended and black cannot block it or black cannot take pawn
									own = 2; //18758
							&#125;

							if &#40;own == unknown && rank_of&#40;bk&#41; + &#40;Rank&#41;2 <= rank_of&#40;p&#41; && c == WHITE&#41; //pawn scapes
								own = 2; //5050

							//black takes bishop and stalemates white
							if &#40;own == unknown && wk == SQ_H8 && p == SQ_H7 && c == BLACK && b == SQ_F7 && SquareDistance&#91;bk&#93;&#91;b&#93; == 1&#41;
								own = 0; //6

							if &#40;own == unknown && file_of&#40;bk&#41; + &#40;c == BLACK&#41; < rank_of&#40;p&#41; && file_of&#40;b&#41; != 7&#41;//pawn scapes
								own = 2; //196445

							//white king prevents black king to reach the pawn or h file
							if &#40;own == unknown && c == WHITE && file_of&#40;wk&#41; > file_of&#40;bk&#41; && abs&#40;rank_of&#40;wk&#41; - rank_of&#40;bk&#41;) < 2 && file_of&#40;wk&#41; < 7&#41;
								own = 2; //11227

							//white king prevents black king to reach the pawn or h file
							if &#40;own == unknown && c == WHITE && file_of&#40;wk&#41; > file_of&#40;bk&#41; && rank_of&#40;bk&#41; <= rank_of&#40;wk&#41; && file_of&#40;wk&#41; < 7&#41;
								own = 2; //9710

							//white king prevents black king to reach the pawn 
							if &#40;own == unknown && &#40;rank_of&#40;bk&#41; < rank_of&#40;p&#41; || &#40;rank_of&#40;bk&#41; == rank_of&#40;p&#41; && c == WHITE&#41;) &&
								&#40;rank_of&#40;wk&#41; > rank_of&#40;bk&#41; || &#40;rank_of&#40;wk&#41; == rank_of&#40;bk&#41; && &#40;file_of&#40;wk&#41; < 7 || file_of&#40;bk&#41; < 4&#41;))
								//&& file_of&#40;wk&#41; >= file_of&#40;bk&#41; &&
								&& &#40;file_of&#40;wk&#41; >= file_of&#40;bk&#41; || bk == SQ_B1 || &#40;bk == SQ_C1 && c == WHITE&#41;) &&
								(
								SquareDistance&#91;bk&#93;&#91;p&#93; - &#40;c == BLACK&#41; > SquareDistance&#91;wk&#93;&#91;p&#93; ||
								&#40;SquareDistance&#91;bk&#93;&#91;p&#93; - &#40;c == BLACK&#41; == SquareDistance&#91;wk&#93;&#91;p&#93; && &#40;file_of&#40;wk&#41; == file_of&#40;bk&#41; || &#40;file_of&#40;wk&#41; >= file_of&#40;bk&#41; && SquareDistance&#91;wk&#93;&#91;bk&#93; < 5&#41;)) ||
								&#40;SquareDistance&#91;bk&#93;&#91;p&#93; - &#40;c == BLACK&#41; + 1 == SquareDistance&#91;wk&#93;&#91;p&#93; && file_of&#40;wk&#41; >= file_of&#40;bk&#41; && &#40;rank_of&#40;p&#41; == 1 || rank_of&#40;p&#41; - rank_of&#40;bk&#41; > 1&#41;) ||
								&#40;bk == SQ_B1 || &#40;bk == SQ_C1 && c == WHITE&#41;)
								)
								)
								own = 2; //11342

							//black king far of pawn
							if &#40;own == unknown && &#40;bk == SQ_A1 ||
								SquareDistance&#91;bk&#93;&#91;SQ_G7&#93; > 8 - rank_of&#40;p&#41; - &#40;c == WHITE&#41;
								))
								own = 2; //14983

							//black king can't stop pawn even near of it
							if &#40;own == unknown && c == BLACK && p == SQ_H6 && (
								&#40;pos.attackers_to&#40;SQ_F7&#41; & pos.pieces&#40;WHITE&#41;) &&
								(&#40;bk == SQ_F6 && &#40;pos.attackers_to&#40;SQ_G6&#41; & pos.pieces&#40;WHITE&#41;)) ||
								&#40;bk == SQ_F8 && &#40;pos.attackers_to&#40;SQ_G8&#41; & pos.pieces&#40;WHITE&#41;))
								))
								)
								own = 2; //412

							//black king stops pawn
							if &#40;own == unknown && file_of&#40;bk&#41; > file_of&#40;wk&#41; && rank_of&#40;bk&#41; - 1 > rank_of&#40;p&#41; && file_of&#40;bk&#41; >/*=*/rank_of&#40;p&#41; && c == BLACK && SquareDistance&#91;wk&#93;&#91;SQ_F6&#93; > 2&#41;
								own = 0; //52286

							//pawn scapes
							if &#40;own == unknown && SquareDistance&#91;bk&#93;&#91;SQ_H8&#93; - &#40;c == BLACK&#41; > SquareDistance&#91;p&#93;&#91;SQ_H8&#93; && &#40;file_of&#40;b&#41; != 7 || rank_of&#40;b&#41; < rank_of&#40;p&#41;))
								own = 2; //4013

							//pawn no reachable because bishop prevents pass
							if &#40;own == unknown && b == SQ_H5 && &#40;p == SQ_H4 || &#40;p < SQ_H4 && c == WHITE&#41;) && SquareDistance&#91;bk&#93;&#91;SQ_H8&#93; - &#40;c == BLACK&#41;> 4 &&
								SquareDistance&#91;bk&#93;&#91;SQ_H4&#93; >= SquareDistance&#91;bk&#93;&#91;SQ_H8&#93; &&
								SquareDistance&#91;bk&#93;&#91;SQ_H4&#93; <= SquareDistance&#91;bk&#93;&#91;SQ_F8&#93;
								)
								own = 2; //94  <<---------------

							//black king stops the pawn thanks to bishop blocking it
							if &#40;own == unknown && SquareDistance&#91;bk&#93;&#91;SQ_H8&#93; - &#40;c == BLACK&#41; </*=*/ SquareDistance&#91;p&#93;&#91;SQ_H8&#93; - &#40;p == SQ_H2&#41; && file_of&#40;b&#41; == 7 && rank_of&#40;b&#41; > rank_of&#40;p&#41; &&
								file_of&#40;wk&#41; < file_of&#40;bk&#41; &&
								!&#40;SquareDistance&#91;wk&#93;&#91;SQ_F7&#93; - &#40;c == WHITE&#41; <= SquareDistance&#91;bk&#93;&#91;SQ_H6&#93;) &&
								!&#40;wk == SQ_G8 || wk == SQ_H8&#41; &&
								!&#40;b == SQ_H7 && &#40;p == SQ_H6 || &#40;p == SQ_H5 && c == WHITE&#41;))
								)
								own = 0; //3594

							if &#40;own == unknown && bk == SQ_F6 && p == SQ_H6&#41; &#123;
								//pawn no reachable because bishop prevents pass
								if &#40;b == SQ_E8 || b == SQ_H5&#41;
									own = 2; //98
								else &#123;
									if &#40;c == BLACK && SquareDistance&#91;p&#93;&#91;wk&#93; > 3&#41; //black takes or captures the pawn
										own = 0; //1137
									else
										if &#40;c == WHITE && (&#40;pos.attacks_from<BISHOP>&#40;b&#41; & SQ_H5&#41; || &#40;pos.attacks_from<BISHOP>&#40;b&#41; & SQ_E8&#41;))  //bishop can block king to reach the pawn
											own = 2; //480  
								&#125;
							&#125;

							if &#40;own == unknown && bk == SQ_E5 && p == SQ_H5&#41; &#123;
								//pawn no reachable because bishop prevents pass
								if &#40;c == WHITE && (&#40;pos.attacks_from<BISHOP>&#40;b&#41; & SQ_H5&#41; || &#40;pos.attacks_from<BISHOP>&#40;b&#41; & SQ_E8&#41;))  //bishop can block king to reach the pawn
									own = 2;  //446
							&#125;

							// black king does not have time to attack the undefended h6 pawn
							//5k2/7B/7P/8/8/8/3K4/8 w - - 0 1
							if &#40;own == unknown && b == SQ_H7 && p == SQ_H6 && file_of&#40;bk&#41; < 6 && rank_of&#40;bk&#41; > 5 && rank_of&#40;wk&#41; < rank_of&#40;bk&#41; && SquareDistance&#91;wk&#93;&#91;p&#93; - &#40;c == WHITE&#41; < 4&#41;
								own = 2; //174

							//black king stops the pawn
							if &#40;own == unknown && &#40;p == SQ_H2 || p == SQ_H3&#41; && &#40;b == SQ_H3 || b == SQ_H5 || b == SQ_H7&#41; &&
								&#40;file_of&#40;bk&#41; > 2 || &#40;file_of&#40;bk&#41; == 2 && c == BLACK && rank_of&#40;wk&#41; <= rank_of&#40;bk&#41;)) && file_of&#40;wk&#41; < 2 && &#40;rank_of&#40;bk&#41; > 0 || &#40;rank_of&#40;bk&#41; == 0 && c == BLACK && file_of&#40;wk&#41; == 0&#41;) &&
								&#40;c == BLACK || &#40;c == WHITE &&
								&#40;file_of&#40;bk&#41; - file_of&#40;wk&#41; > 3 || rank_of&#40;wk&#41; <= rank_of&#40;bk&#41;)
								)
								))
								own = 0; //1244

							//black king stops pawn
							if &#40;own == unknown && p == SQ_H7 && c == BLACK && SquareDistance&#91;bk&#93;&#91;SQ_G7&#93; == 1 && SquareDistance&#91;wk&#93;&#91;SQ_G7&#93; > 1&#41;
								own = 0; //5629

							//black king stops pawn
							if &#40;own == unknown && p == SQ_H6 && c == BLACK && SquareDistance&#91;bk&#93;&#91;SQ_G7&#93; <= 2 && SquareDistance&#91;wk&#93;&#91;SQ_G7&#93; > 1 && SquareDistance&#91;wk&#93;&#91;SQ_E7&#93; > 1 && SquareDistance&#91;wk&#93;&#91;SQ_F4&#93; > 2 &&
								!(&#40;pos.attacks_from<BISHOP>&#40;b&#41; & SQ_H5&#41; || &#40;pos.attacks_from<BISHOP>&#40;b&#41; & SQ_E8&#41; || &#40;pos.attacks_from<BISHOP>&#40;b&#41; & SQ_H7&#41;)
								&& !(&#40;bk == SQ_F8 || bk == SQ_E8&#41; && &#40;pos.attacks_from<BISHOP>&#40;b&#41; & SQ_G8&#41;)
								)
								own = 0; //2611

							if &#40;own == unknown && p == SQ_H7 && SquareDistance&#91;wk&#93;&#91;SQ_G7&#93; == 1&#41;
								own = 2; //382

							//black king takes the bishop and kpk endgame is draw
							if &#40;own == unknown && c == BLACK && SquareDistance&#91;bk&#93;&#91;b&#93; == 1 && !&#40;pos.attackers_to&#40;b&#41; & pos.pieces&#40;WHITE&#41;)) &#123;
								//pos.remove_piece&#40;BLACK, KING, bk&#41;;  //some exceptions when bishop checking and defending indirectly the pawn
								pos.remove_piece&#40;WHITE, BISHOP, b&#41;;  //some exceptions when bishop checking and defending indirectly the pawn
								pos.move_piece&#40;BLACK, KING, bk, b&#41;;
								pos.sideToMove = ~pos.sideToMove;
								pos.set_state&#40;pos.st&#41;;
								int vv = Tablebases&#58;&#58;probe_wdl&#40;pos, &found&#41;;
								if &#40;vv == 0&#41;
									own = 0;
								pos.put_piece&#40;BLACK, KING, bk&#41;;
								pos.put_piece&#40;WHITE, BISHOP, b&#41;;
								pos.sideToMove = ~pos.sideToMove;
								pos.set_state&#40;pos.st&#41;;
							&#125; //7977

							//bishop stops black king to reach the pawn
							if &#40;own == unknown && p == SQ_H6 && &#40;wk == SQ_G7 ||
								&#40;b == SQ_H5 || b == SQ_G6&#41; && &#40;bk == SQ_E6 || &#40;bk != SQ_F7 && SquareDistance&#91;bk&#93;&#91;SQ_F8&#93; - &#40;c == BLACK&#41; > 1&#41;)))
								own = 2; //410

							//wk helps pawn advance from front of it
							if &#40;own == unknown && rank_of&#40;wk&#41; > rank_of&#40;p&#41; && file_of&#40;wk&#41; == 7 && SquareDistance&#91;wk&#93;&#91;p&#93; <= SquareDistance&#91;bk&#93;&#91;p&#93; && rank_of&#40;bk&#41; < rank_of&#40;wk&#41; + &#40;c == WHITE&#41;)
								own = 2; //9687

							if &#40;own == unknown &&  p == SQ_H6&#41; &#123;
								if &#40;b == SQ_H7&#41; &#123;
									if &#40;bk == SQ_H4&#41; &#123;
										if &#40;SquareDistance&#91;wk&#93;&#91;SQ_G7&#93; - &#40;c == WHITE&#41; < 2&#41;
											own = 2;
										else
											own = 0;
									&#125; //9
									if &#40;own == unknown&#41; &#123;
										if (&#40;SquareDistance&#91;wk&#93;&#91;p&#93; < 3 && bk != SQ_H4&#41;/* || SquareDistance&#91;bk&#93;&#91;SQ_F6&#93; - &#40;c==BLACK&#41;>=1*/)
											own = 2; //45
										if &#40;own == unknown&#41; &#123;
											if &#40;SquareDistance&#91;wk&#93;&#91;SQ_G5&#93; < SquareDistance&#91;bk&#93;&#91;SQ_G5&#93; - &#40;c == BLACK&#41;)
												own = 2; //13
											else &#123;
												if &#40;bk == SQ_F7&#41; //42
													own = 0;
												if &#40;bk == SQ_F6 && SquareDistance&#91;wk&#93;&#91;SQ_G5&#93; - &#40;c == WHITE&#41; > 1 && SquareDistance&#91;wk&#93;&#91;SQ_G7&#93; - &#40;c == WHITE&#41; > 1&#41; //894247
													own = 0;  //40
												if &#40;bk == SQ_E7&#41;
													own = 0; //37
												if &#40;bk == SQ_F8 && SquareDistance&#91;wk&#93;&#91;SQ_F4&#93; > SquareDistance&#91;bk&#93;&#91;SQ_G5&#93; - &#40;c == BLACK&#41;)
													own = 0; //49
												if &#40;own == unknown && c == WHITE&#41;
													own = 2; //130
											&#125;
										&#125;
									&#125;
								&#125;
							&#125;

							if &#40;own == unknown && p == SQ_H6 && b == SQ_H7 && &#40;SquareDistance&#91;bk&#93;&#91;SQ_G6&#93; > 2 || bk == SQ_E4 || wk == SQ_H4 || SquareDistance&#91;wk&#93;&#91;p&#93; <= SquareDistance&#91;bk&#93;&#91;SQ_G6&#93; - &#40;c == BLACK&#41;) && SquareDistance&#91;bk&#93;&#91;SQ_F8&#93; > 2&#41;
								own = 2;  //124

							if &#40;own != 999 && abs&#40;own&#41; != abs&#40;v&#41;) &#123;
								sync_cout << "Error result&#58; pawn&#58; " << UCI&#58;&#58;square&#40;p&#41; << " wk&#58; " << UCI&#58;&#58;square&#40;wk&#41; << " bishop&#58; " << UCI&#58;&#58;square&#40;b&#41; << " bk&#58; " << UCI&#58;&#58;square&#40;bk&#41; << " color&#58; " << c << " own&#58; " << own << " good&#58; " << v << sync_endl;
								return;
							&#125;


							if &#40;own != unknown&#41;
								resolvedpositions++;
							else &#123;
								if (!first_unresolved_shown&#41; &#123;
									sync_cout << "1st unresolved&#58; pawn&#58; " << UCI&#58;&#58;square&#40;p&#41; << " wk&#58; " << UCI&#58;&#58;square&#40;wk&#41; << " bishop&#58; " << UCI&#58;&#58;square&#40;b&#41; << " bk&#58; " << UCI&#58;&#58;square&#40;bk&#41; << " color&#58; " << c << " good&#58; " << v << sync_endl;
									first_unresolved_shown = true;
								&#125;
								if &#40;v == 0&#41;
									unresolveddraws++;
								else
									unresolvedwins++;
							&#125;
						&#125;
					&#125;
				&#125;
			&#125;
		&#125;

		sync_cout << "Total positions&#58; " << totalpositions << " resolved positions&#58; " << resolvedpositions << sync_endl;
		sync_cout << " unresolved draws&#58; " << unresolveddraws << " unresolved wins&#58; " << unresolvedwins << sync_endl;
	&#125;
Stan Arts
Posts: 179
Joined: Fri Feb 14, 2014 10:53 pm
Location: the Netherlands

Re: Test position that requires KKP evaluation

Post by Stan Arts »

hgm wrote: The code I finally arrived at was
That looks very detailed and pretty..

Instead my spaghetticode for the computerside having the pawn is this:

Code: Select all

0&#58;if pawns and 63<>0 then begin if &#40;pbitcount&#91;pawnc&#91;0&#93;&#93;<>pawns and 63&#41;and
  &#40;pbitcount&#91;pawnc&#91;7&#93;&#93;<>pawns and 63&#41; then begin if pawns=1 then begin
   for ev2&#58;=1 to 6 do if pawnc&#91;ev2&#93;<>0 then ev1&#58;=pbitlast&#91;pawnc&#91;ev2&#93;&#93;;
   if &#40;tboard&#91;3&#93; shr 4<ev1+5&#41;and&#40;tboard&#91;3&#93; shr 4>ev1+2&#41;and
    &#40;tboard&#91;2&#93; shr 4<ev1+3&#41; then                           &#123;kpk opposition&#125;
   dec&#40;evalval,&#40;evalval-32768&#41;-&#40;evalval-32768&#41; shr 3&#41;;end;end else
  if (&#40;pawnc&#91;0&#93;<>0&#41;and&#40;kinginreacho&#40;&#40;pbitlast&#91;pawnc&#91;0&#93;&#93;+2&#41; shl 4&#41;=1&#41;and
   &#40;tboard&#91;3&#93; and 15-&#40;1-tdepth and 1&#41;<=tboard&#91;2&#93; and 15&#41;&#41;or
   (&#40;pawnc&#91;7&#93;<>0&#41;and&#40;kinginreacho&#40;7+&#40;pbitlast&#91;pawnc&#91;7&#93;&#93;+2&#41; shl 4&#41;=1&#41;and
   &#40;tboard&#91;3&#93; and 15+&#40;1-tdepth and 1&#41;>=tboard&#91;2&#93; and 15&#41;) then
   if tboard&#91;3&#93; shr 4+&#40;1-tdepth and 1&#41;>=tboard&#91;2&#93; shr 4 then
    dec&#40;evalval,&#40;evalval-32768&#41;-&#40;evalval-32768&#41; shr 3&#41;;end;    &#123;edge pawns&#125; 
Which translates to..:

No pieces. If there are pawns, are there pawns that are not on the edge?
Yes. Is there one pawn? Where is it?
If opponent king is at row 2 or 1 infront of the pawn,
and own king is at the pawn's row or behind, return drawish score.
No. Are the remaining pawns all on the left (for edge pawns it does not matter for opposition if there are 1 or 6 pawns on the file) , opponent king in reach and opponent king as left or further left as the own king, or the same story for pawns on the right, drawish score.

Simple and probably not very correct but it seems to do it's job in practise combined with search where as you say, search converts quickly and the defending side can not be forced out of these simple drawing positions at the tips.
Joerg Oster
Posts: 937
Joined: Fri Mar 10, 2006 4:29 pm
Location: Germany

Re: Test position that requires KKP evaluation

Post by Joerg Oster »

brtzsnr wrote:I would be curios just in case I'll want to add more knowledge. Do you know how much you loose when you disable these functions? Also, what about the remaining 1182440-894706 positions? Is the result wrong or just undecided?
Here a little piece of code which I wrote as an exercise, to be added to the already existing KBPsK endgame in Stockfish. It only covers the fortress position with the pawn on b6 and the bishop on a7, and the defending king on b7 or a8.
[d]8/Bk6/1P6/4K3/8/8/8/8 b - - 0 70

Code: Select all

  // Check for the fortress draw in KBPK
  if (    pos.count<PAWN>&#40;strongSide&#41; == 1
      && !more_than_one&#40;pos.pieces&#40;weakSide&#41;)
      && &#40;pawnsFile == FILE_B || pawnsFile == FILE_G&#41;)
  &#123;
      // Assume strongSide is white and the pawn is on files A-D
      Square pawnSq     = normalize&#40;pos, strongSide, pos.square<PAWN>&#40;strongSide&#41;);
      Square weakKingSq = normalize&#40;pos, strongSide, pos.square<KING>&#40;weakSide&#41;);
      Square bishopSq   = normalize&#40;pos, strongSide, pos.square<BISHOP>&#40;strongSide&#41;);

      if &#40;pawnSq == SQ_B6 && bishopSq == SQ_A7 && &#40;weakKingSq == SQ_B7 || weakKingSq == SQ_A8&#41;)
          return SCALE_FACTOR_DRAW;
  &#125;
It's worth mentioning that

Code: Select all

distance&#40;weakKingSq, SQ_B7&#41; <= 1
instead of

Code: Select all

&#40;weakKingSq == SQ_B7 || weakKingSq == SQ_A8&#41;
didn't work because as soon as the defending king goes to c8 and the stronger side's king can reach the sqaure c6, it's a win for the stronger side.
Jörg Oster
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Test position that requires KKP evaluation

Post by bob »

zd3nik wrote:[d] 8/3k1r1p/4RP1K/7P/8/8/8/8 w - - 2 58 am Re7+

Was watching a game that resulted in this position and my engine played Re7+? Obviously if it had specific knowledge about KKP endgames (or endgame tablebase support) it would have seen this leads to a draw.

I'm curious if anyone has an engine that sees the folly of Re7 very quickly *without* endgame tablebase or special KKP handling. And if so what technique do you use? I have logic to see runaway passers in K vs P endgames, but no logic to recognize blocked passers in K vs P endgames.

My engine takes about 40 seconds and 19 plies to see a correc solution. :(

Code: Select all

info depth 19 seldepth 35 nodes 49992180 time 22710 nps 2201328 score cp 180 pv e6e7 f7e7 f6e7 d7e7 h6h7 e7f6 h7h6 f6f7 h6g5 f7g7 g5f4 g7h6 f4g4 h6h7 g4h3 h7g8 h3h4 g8h7 h4g3 h7g7
info depth 19 seldepth 35 nodes 57647437 time 26325 nps 2189836 currmovenumber 2 currmove e6a6 score cp 181 lowerbound
info depth 19 seldepth 35 nodes 64267463 time 29570 nps 2173400 currmovenumber 2 currmove e6a6 score cp 197 lowerbound
info depth 19 seldepth 35 nodes 72557269 time 33399 nps 2172438 currmovenumber 2 currmove e6a6 score cp 229 lowerbound
info depth 19 seldepth 35 nodes 86953526 time 39888 nps 2179941 score cp 254 pv e6a6 d7e8 a6a8 e8d7 h6g5 d7e6 a8e8 e6d7 e8e5 d7d6 g5f5 f7f8 e5e7 f8h8 h5h6 d6c5 e7g7 c5d6 f6f7 d6e7 g7g8
I suppose Crafty qualifies. There are straightforward rules about KP vs K that can be coded simply and accurately. Here's my output:

Code: Select all

        depth     time       score   variation &#40;1&#41;
          1     0.00/30.00    1.86   1. Re7+ Rxe7 2. fxe7 Kxe7 3. Kxh7
          1->   0.00/27.00    1.86   1. Re7+ Rxe7 2. fxe7 Kxe7 3. Kxh7
          2     0.00/27.00    1.86   1. Re7+ Rxe7 2. fxe7 Kxe7 3. Kxh7
          2     0.00/36.00    2.14   1. Rb6 Ke8 2. Re6+ Kf8        
          2     0.00/42.00    2.14   1. Ra6 Kd8 2. Rd6+ Ke8        
          2->   0.00/42.00    2.14   1. Ra6 Kd8 2. Rd6+ Ke8        
          3     0.00/42.00    1.99   1. Ra6 Ke8 2. Rd6             
          3     0.00/48.00    2.05   1. Rb6 Ke8 2. Kg5             
          3->   0.00/48.00    2.05   1. Rb6 Ke8 2. Kg5             
          4     0.00/48.00    1.86   1. Rb6 Ke8 2. Rd6 Rc7         
          4->   0.00/43.20    1.86   1. Rb6 Ke8 2. Rd6 Rc7         
          5     0.00/43.20    1.76   1. Rb6 Ke8 2. Rd6 Rc7 3. Kg5 Rc5+ 4. Kg4
          5     0.00/49.20    1.86   1. Re7+ Rxe7 2. fxe7 Kxe7 3. Kxh7
          5->   0.00/49.20    1.86   1. Re7+ Rxe7 2. fxe7 Kxe7 3. Kxh7
          6     0.00/49.20    1.60   1. Re7+ Rxe7 2. fxe7 Kxe7 3. Kxh7 Kf6
          6     0.01/55.20    1.86   1. Rb6 Ke8 2. Rc6 Rb7 3. Rd6 Rc7
          6->   0.01/55.20    1.86   1. Rb6 Ke8 2. Rc6 Rb7 3. Rd6 Rc7
          7     0.01/55.20    2.07   1. Rb6 Ke8 2. Rb8+ Kd7 3. Kg5 Kc7 4. Re8
                                     Kd6
          7     0.01/1&#58;00     2.23   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4
          7->   0.01/1&#58;00     2.23   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4
          8     0.01/1&#58;00     2.07   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd6
          8->   0.01/54.00    2.07   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd6
          9     0.01/54.00    2.36   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd6 5. Kf5 Rd7 6. Re4
          9->   0.02/48.60    2.36   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd6 5. Kf5 Rd7 6. Re4
         10     0.02/48.60    2.93   1. Ra6 Kc8 2. Kg5 Rc7 3. Rb6 Rf7 4. Kf5
                                     Kc7 5. Ra6 Kd8 6. Rd6+ Ke8
         10->   0.02/43.50    2.93   1. Ra6 Kc8 2. Kg5 Rc7 3. Rb6 Rf7 4. Kf5
                                     Kc7 5. Ra6 Kd8 6. Rd6+ Ke8
         11     0.03/43.50    2.48   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd6 6. Kf5 Rb7 7. Rd4+ Kc5
         11->   0.03/39.00    2.48   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd6 6. Kf5 Rb7 7. Rd4+ Kc5
         12     0.04/39.00    2.35   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd6 6. Kf5 Rb7 7. Re5 Rc7
         12     0.04/45.00    2.86   1. Re7+ Rxe7 2. fxe7 Kxe7 3. Kxh7 Kf8
                                     4. h6 Kf7 5. Kh8 Kg6 6. h7 Kf6
         12->   0.04/45.00    2.86   1. Re7+ Rxe7 2. fxe7 Kxe7 3. Kxh7 Kf8
                                     4. h6 Kf7 5. Kh8 Kg6 6. h7 Kf6
         13     0.04/45.00    0.00   1. Re7+ Rxe7 2. fxe7 Kxe7 3. Kxh7 Kf8
                                     4. h6 Kf7 5. Kh8 Kg6 6. h7 Kf6 7. Kg8
         13     0.05/51.00    2.55   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd6 6. Kf5 Ra7 7. Re8 h6
                                     8. Rd8+ Kc5
         13->   0.05/51.00    2.55   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd6 6. Kf5 Ra7 7. Re8 h6
                                     8. Rd8+ Kc5
         14     0.07/51.00    2.92   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd6 6. Kf5 Kd7 7. Re6 h6 8. Ke5
                                     Rh7
         14->   0.07/45.90    2.92   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd6 6. Kf5 Kd7 7. Re6 h6 8. Ke5
                                     Rh7
         15     0.07/45.90    2.89   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd6 6. Kf5 Kd7 7. Re6 Kd8
                                     8. Ra6 h6 9. Ke6
         15->   0.07/41.10    2.89   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd6 6. Kf5 Kd7 7. Re6 Kd8
                                     8. Ra6 h6 9. Ke6
         16     0.08/41.10    2.90   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd6 6. Kf5 Kd7 7. Re6 h6 8. Ke5
                                     Kd8 9. Rd6+ Ke8 10. Ke6
         16->   0.08/36.90    2.90   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd6 6. Kf5 Kd7 7. Re6 h6 8. Ke5
                                     Kd8 9. Rd6+ Ke8 10. Ke6
         17     0.11/36.90    2.97   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Kf5 Ra7 7. Re6 Rc7
                                     8. Rb6 Ke8 9. Ke6 Rc8 10. f7+ Kf8
         17->   0.11/33.00    2.97   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Kf5 Ra7 7. Re6 Rc7
                                     8. Rb6 Ke8 9. Ke6 Rc8 10. f7+ Kf8
         18     0.15/33.00    2.93   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd7 10. Ra7+ Ke8
                                     11. Ra8+ Kd7 12. Ra6 Kd8 13. Rd6+ Ke8
         18->   0.16/29.70    2.93   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd7 10. Ra7+ Ke8
                                     11. Ra8+ Kd7 12. Ra6 Kd8 13. Rd6+ Ke8
         19     0.21/29.70    2.93   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd7 10. Ra7+ Ke8
                                     11. Ra8+ Kd7 12. Ra6 Kd8 13. Rd6+ Ke8
         19->   0.22/26.70    2.93   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd7 10. Ra7+ Ke8
                                     11. Ra8+ Kd7 12. Ra6 Kd8 13. Rd6+ Ke8
         20     0.29/26.70    3.09   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd7 10. Ra7+ Ke8
                                     11. Ra8+ Kd7 12. Ra6 Kd8 13. Ke6 Rd7
                                     14. Ra8+ Kc7
         20->   0.29/24.00    3.09   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd7 10. Ra7+ Ke8
                                     11. Ra8+ Kd7 12. Ra6 Kd8 13. Ke6 Rd7
                                     14. Ra8+ Kc7
         21     0.42/24.00    3.39   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd7 10. Ra7+ Ke8
                                     11. Ra8+ Kd7 12. Ra6 h6 13. Kg6 Rf8
                                     14. Kxh6
         21->   0.42/21.60    3.39   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd7 10. Ra7+ Ke8
                                     11. Ra8+ Kd7 12. Ra6 h6 13. Kg6 Rf8
                                     14. Kxh6
         22     0.51/21.60    3.42   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 h6 11. Re7
                                     Rf8 12. f7 Kc5 13. Ke6 Rc8
         22->   0.51/19.20    3.42   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 h6 11. Re7
                                     Rf8 12. f7 Kc5 13. Ke6 Rc8
         23     0.67/19.20    3.47   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 h6 11. Re5+
                                     Kd4 12. Re7 Rf8 13. Ke6 Rc8 14. Rd7+ Kc5
                                     15. f7
         23->   0.67/18.00    3.47   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 h6 11. Re5+
                                     Kd4 12. Re7 Rf8 13. Ke6 Rc8 14. Rd7+ Kc5
                                     15. f7
         24     0.95/18.00    3.68   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 h6 11. Re5+
                                     Kd4 12. Re7 Rf8 13. Ke6 Rh8 14. Rd7+ Ke4
                                     15. f7 Rc8
         24->   0.95/18.00    3.68   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 h6 11. Re5+
                                     Kd4 12. Re7 Rf8 13. Ke6 Rh8 14. Rd7+ Ke4
                                     15. f7 Rc8
         25     1.15/18.00    3.72   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 h6 11. Re5+
                                     Kd4 12. Re7 Rf8 13. Ke6 Rh8 14. Rd7+ Ke4
                                     15. f7 Rc8 16. Ke7
         25->   1.15/18.00    3.72   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 h6 11. Re5+
                                     Kd4 12. Re7 Rf8 13. Ke6 Rh8 14. Rd7+ Ke4
                                     15. f7 Rc8 16. Ke7
         26     1.65/18.00    3.95   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rf8 11. h6
                                     Rh8 12. Re7 Kc5 13. Rc7+ Kd5 14. Rd7+ Kc5
                                     15. f7 Rf8 16. Ke6 Rc8
         26->   1.65/18.00    3.95   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rf8 11. h6
                                     Rh8 12. Re7 Kc5 13. Rc7+ Kd5 14. Rd7+ Kc5
                                     15. f7 Rf8 16. Ke6 Rc8
         27     1.95/18.00    3.99   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rf8 11. h6
                                     Rh8 12. Re7 Kc5 13. Rc7+ Kd5 14. Rd7+ Kc5
                                     15. f7 Rf8 16. Ke6 Rc8 17. Ke7
         27->   1.96/18.00    3.99   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rf8 11. h6
                                     Rh8 12. Re7 Kc5 13. Rc7+ Kd5 14. Rd7+ Kc5
                                     15. f7 Rf8 16. Ke6 Rc8 17. Ke7
         28     2.42/18.00    4.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rf8 11. h6
                                     Rh8 12. Re7 Kc5 13. Rc7+ Kd5 14. Rd7+ Kc5
                                     15. Ke6 Re8+ 16. Re7 Rh8 17. f7 Rb8
                                     18. Rc7+ Kd4 19. Ke7
         28->   2.43/18.00    4.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rf8 11. h6
                                     Rh8 12. Re7 Kc5 13. Rc7+ Kd5 14. Rd7+ Kc5
                                     15. Ke6 Re8+ 16. Re7 Rh8 17. f7 Rb8
                                     18. Rc7+ Kd4 19. Ke7
         29     2.68/18.00    4.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rf8 11. h6
                                     Rh8 12. Re7 Kc5 13. Rc7+ Kd5 14. Rd7+ Kc5
                                     15. Ke6 Re8+ 16. Re7 Rh8 17. f7 Rb8
                                     18. Rc7+ Kd4 19. Ke7
         29->   2.68/18.00    4.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rf8 11. h6
                                     Rh8 12. Re7 Kc5 13. Rc7+ Kd5 14. Rd7+ Kc5
                                     15. Ke6 Re8+ 16. Re7 Rh8 17. f7 Rb8
                                     18. Rc7+ Kd4 19. Ke7
         30     5.09/18.00    4.42   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 h6 11. Re7
                                     Rf8 12. Kg6 Kd6 13. Kg7 Rb8 14. Kxh6 Rg8
                                     15. Rg7 Rf8 16. Kg6 Ke5 17. f7 Rd8
         30->   5.09/18.00    4.42   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 h6 11. Re7
                                     Rf8 12. Kg6 Kd6 13. Kg7 Rb8 14. Kxh6 Rg8
                                     15. Rg7 Rf8 16. Kg6 Ke5 17. f7 Rd8
         31     9.42/18.00    5.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rb7 11. Re7
                                     Rb2 12. Rd7+ Kc5 13. Rxh7 Kd6 14. Ra7 Rf2+
                                     15. Kg6 Ke6 16. Re7+ Kd6 17. h6 Rh2
                                     18. Rg7 Rh1 19. Rg8 Rg1+ 20. Kf7
         31->   9.42/18.00    5.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rb7 11. Re7
                                     Rb2 12. Rd7+ Kc5 13. Rxh7 Kd6 14. Ra7 Rf2+
                                     15. Kg6 Ke6 16. Re7+ Kd6 17. h6 Rh2
                                     18. Rg7 Rh1 19. Rg8 Rg1+ 20. Kf7
         32    10.16/18.00    5.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rb7 11. Re7
                                     Rb2 12. Rd7+ Kc5 13. Rxh7 Kd6 14. h6 Rf2+
                                     15. Kg6 Rg2+ 16. Kf7 Rb2 17. Rg7 Ke5
                                     18. Kg6 Rb1 19. Re7+ Kd6 20. Re8 Rb7
         32->  10.17/18.00    5.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rb7 11. Re7
                                     Rb2 12. Rd7+ Kc5 13. Rxh7 Kd6 14. h6 Rf2+
                                     15. Kg6 Rg2+ 16. Kf7 Rb2 17. Rg7 Ke5
                                     18. Kg6 Rb1 19. Re7+ Kd6 20. Re8 Rb7
         33    11.78/18.00    5.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rb7 11. Re7
                                     Rb2 12. Rd7+ Kc6 13. Rxh7 Rf2+ 14. Kg6
                                     Rg2+ 15. Kf7 Kb6 16. Ke6 Rg3 17. h6 Re3+
                                     18. Kd7 Rf3 19. Ke7 Re3+ 20. Kf8 Rc3
                                     21. Rh8 Rc7
         33->  11.79/18.00    5.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rb7 11. Re7
                                     Rb2 12. Rd7+ Kc6 13. Rxh7 Rf2+ 14. Kg6
                                     Rg2+ 15. Kf7 Kb6 16. Ke6 Rg3 17. h6 Re3+
                                     18. Kd7 Rf3 19. Ke7 Re3+ 20. Kf8 Rc3
                                     21. Rh8 Rc7
         34    13.69/18.00    5.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rb7 11. Re7
                                     Rb2 12. Rd7+ Kc6 13. Rxh7 Rf2+ 14. Kg6
                                     Rg2+ 15. Kf7 Kb6 16. Ke6 Rg3 17. h6 Re3+
                                     18. Kd7 Rf3 19. Ke7 Re3+ 20. Kf8 Rc3
                                     21. Rh8 Rc7 22. Kg8
         34->  13.69/18.00    5.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rb7 11. Re7
                                     Rb2 12. Rd7+ Kc6 13. Rxh7 Rf2+ 14. Kg6
                                     Rg2+ 15. Kf7 Kb6 16. Ke6 Rg3 17. h6 Re3+
                                     18. Kd7 Rf3 19. Ke7 Re3+ 20. Kf8 Rc3
                                     21. Rh8 Rc7 22. Kg8
         35    15.12/18.00    5.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rb7 11. Re7
                                     Rb2 12. Rd7+ Kc6 13. Rxh7 Rf2+ 14. Kg6
                                     Rg2+ 15. Kf7 Kb6 16. Ke6 Re2+ 17. Kd7 Rd2+
                                     18. Ke8 Rc2 19. Re7 Rc8+ 20. Kd7 Rf8
                                     21. f7 Kc5 22. Kc7 Rh8 23. Re8
         35->  15.13/18.00    5.06   1. Ra6 Ke8 2. Ra8+ Kd7 3. Kg5 Ke6 4. Re8+
                                     Kd7 5. Re4 Kd8 6. Ra4 Ke8 7. Ra8+ Kd7
                                     8. Kf5 Kd6 9. Ra6+ Kd5 10. Re6 Rb7 11. Re7
                                     Rb2 12. Rd7+ Kc6 13. Rxh7 Rf2+ 14. Kg6
                                     Rg2+ 15. Kf7 Kb6 16. Ke6 Re2+ 17. Kd7 Rd2+
                                     18. Ke8 Rc2 19. Re7 Rc8+ 20. Kd7 Rf8
                                     21. f7 Kc5 22. Kc7 Rh8 23. Re8
        time=18.08&#40;100%)  nodes=100467554&#40;100.5M&#41;  fh1=90%  pred=0  nps=5.6M
        chk=4.2M  qchk=3.9M  fp=28.3M  mcp=8.9M  50move=1
        LMReductions&#58;  1/3.7M  2/2.4M  3/1.4M  4/225.7K  5/5.5K
        null-move &#40;R&#41;&#58;  3/1.4M  4/655.7K  5/54.4K  6/6.1K  7/749  8/54
White&#40;1&#41;&#58; Ra6
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Test position that requires KKP evaluation

Post by hgm »

bob wrote:

Code: Select all

          6     0.00/49.20    1.60   1. Re7+ Rxe7 2. fxe7 Kxe7 3. Kxh7 Kf6
Still remarkable then that it has a +1.60 score here. Because the position at the end of the PV is already in KPK.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Test position that requires KKP evaluation

Post by bob »

hgm wrote:
bob wrote:

Code: Select all

          6     0.00/49.20    1.60   1. Re7+ Rxe7 2. fxe7 Kxe7 3. Kxh7 Kf6
Still remarkable then that it has a +1.60 score here. Because the position at the end of the PV is already in KPK.
I chose to recognize the straightforward positions. Excepting rook pawns, if winning king is 2 squares in front of pawn, it is winning. If winning king is 1 square in front of pawn with opposition, it is winning. If losing king is in front of a passed rook pawn, it is drawn. In this position, winning king is in front of pawn but can't escape and keep other side out. I didn't try to recognize that since the search can handle it easy enough. I am not even sure this kind of evaluation is needed today, this was something done 20+ years ago when a few plies in endgames was all we could see..
User avatar
cdani
Posts: 2204
Joined: Sat Jan 18, 2014 10:24 am
Location: Andorra

Re: Test position that requires KKP evaluation

Post by cdani »

I forgot to mention that the code I put is only for A/H pawn case of KBPK.
brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 4:02 pm

Re: Test position that requires KKP evaluation

Post by brtzsnr »

Do you know how much ELO KPK and KBKP give? My current Elo density is about 0.5 Elo / line (CCRL, only engine, no uci, no tests) and it's something I consider everytime I add significant chunks of code.