advanced krkp function

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
User avatar
cdani
Posts: 2095
Joined: Sat Jan 18, 2014 9:24 am
Location: Andorra
Contact:

advanced krkp function

Post by cdani » Sat May 06, 2017 12:03 pm

I want to share the krkp function I have done. It solves a big part (if I remember well + than 50%) of the positions with tablebase like resolution.

It returns:
* 4 - rook side wins
* 2 - draw
* 0 - pawn side wins
* 999 unknown

I have translated it to english, but the comments.

If anyone wants to use it, change this:
int rook_color = color_of_the_rook;
wk = position_of_the_king_that_has_rook;
bk = position_of_the_other_king;
t = position_of_the_rook;
p = position_of_the_pawn;

and provide some arrays/functions: king_attacks, pawn_attacks, rook_attacks, knight_attacks that return a bitboard.

The function generalizes as if white was the one with the rook, and also that the pawn is in the queenside.

I have not validated it after the translation from catalan, so maybe there is some minor syntax error.

Code: Select all


int eval_KRKP_llarg(...) {
	int bk, wk, t, p, c, x;
	int rook_color = color_of_the_rook;
	wk = position_of_the_king_that_has_rook;
	bk = position_of_the_other_king;
	t = position_of_the_rook;
	p = position_of_the_pawn;

	c = who_moves;
	if (rook_color == black) {
		//passar a com si fossin white
		wk = (7 - ROW(wk)) * 8 + COL(wk);
		bk = (7 - ROW(bk)) * 8 + COL(bk);
		t = (7 - ROW(t)) * 8 + COL(t);
		p = (7 - ROW(p)) * 8 + COL(p);
		c = opponent(c);
	}

	if (COL(p) > 3) {
		wk = wk ^ 7; // Mirror a1 -> h1
		bk = bk ^ 7;
		t = t ^ 7;
		p = p ^ 7;
	}

	Bitboard atwk = king_attacks[wk];
	Bitboard atbk = king_attacks[bk];
	Bitboard atp = pawn_attacks[black][p];
	Bitboard btw = Bit(t);
	Bitboard bbk = Bit(bk);
	Bitboard bwk = Bit(wk);
	Bitboard bbp = Bit(p);
	Bitboard whitepieces = btw | bwk;
	Bitboard rattacks = rook_attacks(t, (Bitboard)(bwk | bbk | bbp));
	Bitboard atwhite = rattacks | atwk;
	Bitboard atblack = atbk | atp;
	Bitboard allpieces = whitepieces | bbk | bbp;

	bool bkingincheck = (atwhite & bbk);

	if (c == black && (atbk & atwhite) == atbk && !(atp & btw)) {
		//mat
		if ((atwhite & bbk)
			&& !(ROW(bk) == ROW(t) && ROW(p) == ROW(bk) + 1) //que no es pugui tapar de l'escac amb el peó
			)
			return 4;
		else //rei negre ofegat, i peó bloquejat
			if (!(atwhite & bbk) && (whitepieces & Bit(p - 8)))
				return 2;
	}

	//cas concret d'ofegat
	if (bk == 0 && wk == 2 && t == 9 && p == 11)
		return 2;

	//torre captura peó negre no defensat
	if ((c == white || (Distance(bk, p) - (ROW(p) == 6) > 3 && !(atbk & btw) && !(ROW(p) == 1)))
		&& (rattacks & bbp) && !(atbk & bbp)) {
		return 999;
	}

	//rei captura peó negre no defensat
	if (c == white && (atwk & bbp) && !(atbk & bbp)) {
		return 999;
	}

	//rei negre pot capturar torre
	if ((atbk & btw) && !(atwk & btw)) {
		if (c == black)
			//mirar resultat final kpk
			return 999;
		//peo fa escac i rei no pot defensar torre ni torre pot menjar peó
		if ((atp & bwk) && Distance(wk, t) > 1 && !(rattacks & bbp))
			//mirar resultat final kpk
			return 999;
	}

	//peo negre pot capturar torre
	if (c == black && (atp & btw)) {
		//mirar resultat final kpk
		return 999;
	}

	//per fila: torre clava peó o fa escac amenaçant peó i el menjarà
	if (ROW(p) != 1 && ROW(p) == ROW(t) && ROW(t) == ROW(bk) && Distance(bk, p) - (c == black) > 1 && ROW(wk) != ROW(bk)) {
		return 4;
	}

	//peo clavat i se'l menjaran
	if (ROW(t) == ROW(bk) && ROW(p) == ROW(bk)){
		if (Distance(bk, p) - (c == black) > 1) {
			if ((bk == 8 && wk == 2) || (bk == 15 && wk == 5)) {
				if (bk == 8 && t == 9)
					return 4;
				else {
					if (bk == 15 && t == 14)
						return 4;
				}
				if (bk == 15 && p == 11 && t != 12)
					return 4;
				if (Distance(t, p) > 1 && COL(t) != COL(wk))
					return 4; //podrà parar el peó anant a 1a amb la torre
				//if (own == 999)
				return 2; //taules perquè s'autoofegarà
			}
			else {
				//si rei entre mig de torre i rei negre, no se sap
				if (ROW(wk) != ROW(bk)) //mirar excepcions quan rei entre mig però guanya
					return 4;
			}
		}
		else {
			if (Distance(wk, p) == 1 && ROW(t) != ROW(wk)) {
				if (Distance(bk, 0) == 1 && p == 9 && c == black)
					return 2; //rei s'ofega a a1
				else
					return 4;
			}
		}
	}


	//casos especials rei negre en un extrem i rei blanc a c3
	if (p == 9 && (bk == 8 || bk == 0 || bk == 1) && wk == 18 && ROW(t) > 1 && !(atwhite & bbk)
		&& (c == black || COL(t) != 1)
		) {
		if (ROW(t) == 2 && t != 17 && c == black) {
			if (t == 16 || bk == 1)
				return 2;
			else
				return 0;
		}
		else {
			if (t == 17 && bk == 1)
				return 4;
			else {
				if ((ROW(t) > 2 || COL(t) == 0) && c == white)
					return 4;
				else {
					if (bk == 1) {
						if (c == white)
							return 4;
						else {
							if (COL(t) == 0 || COL(t) == 3)
								return 2;
							else
								return 4;
						}
					}
					else
						return 2;
				}
			}
		}
	}

	//peó parat i sel menjarà
	if ((atwhite & Bit(p - 8)) && Distance(bk, p) - (c == black) > 2 && ROW(p) != 6) {
		if (bk == 0 && c == black && wk == 2 && t == 9 && p == 19)
			return 2; //cas especial ofegat
		else {
			if (bk == 0 && wk == 16 && t == 9 && (p == 25 || (p == 33 && c == black)))
				return 2; //cas especial ofegat
			else {
				if &#40;bk == 7 && c == black && wk == 5 && ROW&#40;t&#41; == 1 && ROW&#40;p&#41; == 2 && COL&#40;t&#41; == COL&#40;wk&#41; && COL&#40;p&#41; < 3&#41;
					return 2; //cas especial ofegat
				else &#123;
					if &#40;bk == 56 && wk == 40 && p == 9 && c == black&#41;
						return 2; //cas especial ofegat
					else
						return 4;
				&#125;
			&#125;
		&#125;
	&#125;


	//cas especial
	if &#40;bk == 0 && wk == 2 && p == 9&#41; &#123;
		if &#40;ROW&#40;t&#41; == 0 || COL&#40;t&#41; == 1&#41;
			return 4;
		else &#123;
			if &#40;ROW&#40;t&#41; == 1 || COL&#40;t&#41; == 2 || COL&#40;t&#41; == 4 || ROW&#40;t&#41; > 2&#41;
				return 2; //ofegat o ha de donar torre per dama
			else
				return 0;
		&#125;
	&#125;

	//cas especial
	if &#40;bk == 0 && wk == 2 && p == 9 + 8 && (&#40;c == black && ROW&#40;t&#41; == 1&#41; || &#40;c == white && t == 10&#41;)) &#123;
		return 2;
	&#125;

	//ofegat o mat
	if &#40;c == black && bk + 8 == p && !&#40;atbk & ~&#40;atwhite | Bit&#40;p&#41;))) &#123;
		if &#40;atwhite & Bit&#40;bk&#41;)
			return 4; //mat
		else
			return 2;
	&#125;

	//tisores rei i torre
	if (&#40;atp & bwk&#41; && &#40;atp & Bit&#40;t&#41;) && &#40;atbk & Bit&#40;p&#41;))
		return 2;

	//tisores rei i torre
	if &#40;c == black && &#40;pawn_attacks&#91;black&#93;&#91;p - 8&#93; & bwk&#41; && &#40;pawn_attacks&#91;black&#93;&#91;p - 8&#93; & Bit&#40;t&#41;) && &#40;atbk & Bit&#40;p - 8&#41;) &&
		!&#40;atwhite & bbk&#41;)
		return 2;

	//tisores rei i torre
	if &#40;c == black && ROW&#40;p&#41; == 6 && &#40;pawn_attacks&#91;black&#93;&#91;p - 16&#93; & bwk&#41; && &#40;pawn_attacks&#91;black&#93;&#91;p - 16&#93; & Bit&#40;t&#41;) && &#40;atbk & Bit&#40;p - 16&#41;) &&
		!&#40;atwhite & bbk&#41;) &#123;
		if &#40;bk + 8 == p&#41;
			return 4; //rein bloqueja peó
		else
			return 2;
	&#125;


	//rei ha parat peó
	if &#40;ROW&#40;p&#41; > ROW&#40;wk&#41;) &#123;
		if &#40;COL&#40;wk&#41; == COL&#40;p&#41; ||
			(&#40;COL&#40;wk&#41; - &#40;c == white&#41; == COL&#40;p&#41; || COL&#40;wk&#41; + &#40;c == white&#41; == COL&#40;p&#41;)
			&& (&#40;atwk & Columnes&#91;COL&#40;p&#41;&#93;) & ~atblack&#41;) //hi ha alguna casella no atacada pel negre davant del peo on pugui anar el rei blanc
			) &#123;
			if &#40;c == black && COL&#40;bk&#41; == 0 && wk + 16 == bk && bk + 8 == p && COL&#40;t&#41; == 1&#41;
				return 2; //ofegat
			else
				return 4;
		&#125;
		else &#123;
			//rei pararà peó
			if &#40;ROW&#40;bk&#41; - &#40;c == black&#41; > ROW&#40;wk&#41;
				&& (&#40;atwk & Columnes&#91;COL&#40;p&#41;&#93;) & ~atblack&#41; //hi ha alguna casella no atacada pel negre davant del peo on pugui anar el rei blanc
				&& ROW&#40;bk&#41; != 2
				)
				return 4;
		&#125;
	&#125;

	//ofegat o coronarà
	if (&#40;p == 8 || &#40;p == 16 && c == black&#41; || &#40;p == 19 && c == black&#41;) && bk == 0 && wk == 2 && COL&#40;t&#41; < 2&#41; &#123;
		if &#40;p == 19&#41; &#123;
			if &#40;t == 9&#41;
				return 2;
			else
				return 4;
		&#125;
		else &#123;
			if &#40;p == 16 && t == 1&#41;
				return 4; //fent escac 
			else
				return 2;
		&#125;
	&#125;

	//cas especial taules ofegat
	if (&#40;p == 17 || p == 25&#41; && &#40;bk == 0 || bk == 1&#41; && wk == 16 && t == 9&#41;
		return 2;

	//peo coronant i rein no en escac
	bool coronaambescac = (!!(&#40;PrecalculTorre&#91;p - 8&#93; | PrecalculAlfil&#91;p - 8&#93;) & bwk&#41;) && bk != p - 8 && t != p - 8;

	if &#40;c == black && ROW&#40;p&#41; == 1 && !bkingincheck&#41;  &#123;
		if &#40;wk == p - 8&#41;
			return 4; //reib bloquejant peo
		else &#123;
			if &#40;atwk & &#40;Bit&#40;p - 8&#41;)) &#123; //reib atacant avanç p
				if (!&#40;atbk & &#40;Bit&#40;p - 8&#41;))) &#123;
					if &#40;atbk & btw&#41; &#123;
						if &#40;rattacks & Bit&#40;bk&#41;)
							return 4;
						else &#123;
							if (&#40;rattacks & Bit&#40;p - 8&#41;) || &#40;COL&#40;t&#41; == COL&#40;p&#41; && COL&#40;t&#41; != COL&#40;wk&#41;))
								return 4;  //torre para coronació
							else
								return 2; //rei negre menjarà torre doncs quedarà sense defensar en desviar el reib amb coronació
						&#125;
					&#125;
					else &#123;
						if &#40;bk == 0 && p == 10 && ROW&#40;t&#41; == 1&#41;
							return 2; //reib a c1 ofegarà amb torre a 2a
						else
							return 4;
					&#125;
				&#125;
				else &#123;
					if &#40;COL&#40;t&#41; == COL&#40;p&#41;)
						return 4; //rei i torre evitant coronació
				&#125;
			&#125;
		&#125;

		if &#40;coronaambescac&#41; &#123;
			if &#40;Distance&#40;wk, p - 8&#41; == 1 && !&#40;rattacks & Bit&#40;p - 8&#41;))
				return 0;
			else &#123;
				if (&#40;COL&#40;t&#41; < COL&#40;p&#41; && COL&#40;wk&#41; > COL&#40;p&#41;) || &#40;COL&#40;t&#41; > COL&#40;p&#41; && COL&#40;wk&#41; < COL&#40;p&#41;)) &#123;
					//no pot tapar de torre
					if (&#40;ROW&#40;t&#41; == 1 || ROW&#40;t&#41; == 0&#41; && ROW&#40;bk&#41; == 1&#41; &#123;
						//peo clavat o torre controlant coronació
						if &#40;Distance&#40;wk, p - 8&#41; == 1&#41;
							return 4; //controla coronació amb torre i rei
						else &#123;
							if (&#40;rattacks & Bit&#40;p - 8&#41;) && Distance&#40;wk, p - 8&#41; == 2&#41; &#123;
								if &#40;Distance&#40;bk, p - 8&#41; == 1&#41;
									return 2;
								else
									return 4; //arriba a controlar coronació amb rei i ja la controla amb torre
							&#125;
							else
								return 2;
						&#125;
					&#125;
					else &#123;
						if &#40;t == 0 && c == black && p == 10 && &#40;Distance&#40;bk, p&#41; < Distance&#40;wk, p&#41; || &#40;ROW&#40;wk&#41; == 0 && ROW&#40;bk&#41; == 3 && COL&#40;bk&#41; == COL&#40;p&#41; + 1&#41;))
							return 2; //cas especial torre no pot guanyar un temps
						else &#123;
							if (&#40;rattacks & Bit&#40;p - 8&#41;)) &#123;
								if &#40;Distance&#40;bk, p - 8&#41; - &#40;c == black&#41; == 1&#41; &#123;
									if &#40;atbk & (~atwk&#41; & &#40;FILA2 ^ Bit&#40;p&#41;)) &#123;
										if (&#40;COL&#40;wk&#41; < COL&#40;p&#41; && COL&#40;bk&#41; < COL&#40;p&#41;) || &#40;COL&#40;wk&#41; > COL&#40;p&#41; && COL&#40;bk&#41; > COL&#40;p&#41;))
											return 2; //rein pot anar a 2a
										else &#123;
											if &#40;Distance&#40;t, p - 8&#41; == 2&#41;
												return 2; //al baixa amb el rei toca la torre guanyant un temps
											else &#123;
												if &#40;Distance&#40;wk, p - 8&#41; > 2&#41;
													return 2; //reib no arriba a temps d'ajudar la torre a parar el peó
												else
													return 4; //si que arriba a temps
											&#125;
										&#125;
									&#125;
									else &#123;
										return 4;
									&#125;
								&#125;
								else &#123;
									if (&#40;t == 0 || t == 1&#41; && c == black && &#40;p == 10 || p == 11&#41; && &#40;bk == 21 || bk == 22&#41; && COL&#40;wk&#41; > COL&#40;bk&#41;)
										return 2; //reib massa lluny
									else &#123;
										if &#40;t == 0 && c == black && p == 10 && &#40;bk == 25 || bk == 26&#41; && COL&#40;wk&#41; >= 4 && wk != 20&#41;
											return 2; //cas especial
										else &#123;
											if &#40;COL&#40;wk&#41; == 7 && COL&#40;t&#41; < COL&#40;bk&#41; && ROW&#40;bk&#41; < 4&#41;
												return 2; //rein arriba a suportar peo
											else &#123;
												if &#40;c == black && Distance&#40;bk, p + 8&#41; == 1 && Distance&#40;wk, p - 8&#41; > 2 && Distance&#40;t, p - 8&#41; == 2&#41;
													return 2; //rein arriba pq guanya un temps sobre torre
												else &#123;
													if &#40;ROW&#40;wk&#41; >= ROW&#40;bk&#41; && Distance&#40;bk, p&#41; < Distance&#40;t, p&#41;
														&& (&#40;COL&#40;wk&#41; > COL&#40;bk&#41; && COL&#40;bk&#41; >= COL&#40;p&#41;) || &#40;COL&#40;wk&#41; < COL&#40;bk&#41; && COL&#40;bk&#41; <= COL&#40;p&#41;)))
														return 2;
													/*else
													return 4;*/
												&#125;
											&#125;
										&#125;
									&#125;
								&#125;
							&#125;
						&#125;
						//return 0;
					&#125;
				&#125;
				else &#123;
					if &#40;ROW&#40;bk&#41; == 0&#41; &#123;
						if &#40;ROW&#40;wk&#41; == 0 && Distance&#40;wk, t&#41; < 3 && ROW&#40;t&#41; == 0&#41;
							return 2;
						else &#123;
							if &#40;ROW&#40;wk&#41; == 0 && COL&#40;t&#41; == COL&#40;wk&#41; - 1&#41; &#123;
								if &#40;Distance&#40;p, bk&#41; > 2&#41; &#123;
									if &#40;COL&#40;bk&#41; < COL&#40;p&#41;)
										return 2; //bo
									/*else
									return 4; //rein no pot defensar coronació*/
								&#125;
								/*else
								return 2;*/
							&#125;
						&#125;
					&#125;
				&#125;
			&#125;
		&#125;
	&#125;

	//cas especial
	if &#40;bk == 0 && p == 9 && wk == 16&#41; &#123;
		if &#40;bkingincheck&#41; &#123;
			if &#40;ROW&#40;t&#41; == 0&#41;
				return 2;
			else
				return 4;
		&#125;
		else &#123;
			if &#40;c == black&#41; &#123;
				if &#40;COL&#40;t&#41; == 1&#41;
					return 2;
				else
					return 0;
			&#125;
			else &#123;
				if &#40;c == white && COL&#40;t&#41; == 0&#41;
					return 4;
				else
					return 2;
			&#125;
		&#125;
	&#125;

	//torre parant peó per columna davant peo
	if &#40;COL&#40;t&#41; == COL&#40;p&#41; && ROW&#40;t&#41; < ROW&#40;p&#41;) &#123;
		//cas especial taules
		if &#40;ROW&#40;p&#41; == 1 && t == p - 8 && &#40;bk == p + 8 || bk == p + 9&#41; && wk == t + 2&#41; &#123;
			if &#40;COL&#40;p&#41; < 3 && (&#40;bk == p + 9 && c == white&#41; || &#40;bk == p + 8 && c == black&#41;))
				return 2;
			else
				return 4;
		&#125;
		else &#123;
			if &#40;Distance&#40;wk, t&#41; < 2&#41;
				return 4;
			else &#123;
				if &#40;Distance&#40;wk, t&#41; - &#40;c == white&#41; < Distance&#40;bk, t&#41; - &#40;c == black&#41;)
					return 4;
				else &#123;
					if &#40;Distance&#40;bk, p&#41; - &#40;c == black&#41; > 1 || Distance&#40;t, p&#41; < Distance&#40;bk, p&#41; - &#40;c == black&#41;) &#123;
						if (!&#40;c == black && ROW&#40;p&#41; == 6 && ROW&#40;bk&#41; == 3&#41;)
							return 4;
					&#125;
				&#125;
			&#125;
		&#125;
	&#125;


	//rei ajudarà coronació peo amb torre parant peó per columna
	if &#40;ROW&#40;p&#41; == 1 && COL&#40;t&#41; == COL&#40;p&#41;) &#123;
		//if &#40;c == white && Distance&#40;wk, p - 8&#41; < 2&#41;
		if &#40;c == white && &#40;atwk & Bit&#40;p + 1&#41;) && !&#40;atbk & Bit&#40;p + 1&#41;) && !&#40;atbk & Bit&#40;t&#41;))
			return 4;
		else &#123;
			if &#40;c == white && COL&#40;p&#41; != 0 && &#40;atwk & Bit&#40;p - 1&#41;) && !&#40;atbk & Bit&#40;p - 1&#41;) && !&#40;atbk & Bit&#40;t&#41;))
				return 4;
			else
				/*if &#40;Distance&#40;bk, p - 8&#41; - &#40;c == black&#41; < 2&#41;
				own = 2*/;
		&#125;
	&#125;

	//torre tallant accés del rein al peó
	if &#40;ROW&#40;p&#41; > 2 && ROW&#40;bk&#41; > 4 && ROW&#40;t&#41; > ROW&#40;p&#41; && ROW&#40;t&#41; < ROW&#40;bk&#41;
		&& !&#40;ROW&#40;wk&#41; == ROW&#40;t&#41; && &#40;COL&#40;t&#41; > COL&#40;wk&#41; && COL&#40;wk&#41; > COL&#40;p&#41;)) //que reib no estigui tallant "tall" de torre
		)
		return 4;

	//torre tallant accés del rein al peó per sota
	if &#40;ROW&#40;p&#41; > 2 && ROW&#40;bk&#41; + &#40;c == black&#41; < ROW&#40;t&#41; - 1 && ROW&#40;t&#41; < ROW&#40;p&#41; && ROW&#40;t&#41; > ROW&#40;bk&#41; + 1 && ROW&#40;p&#41; != 6
		&& !&#40;ROW&#40;wk&#41; == ROW&#40;t&#41; && &#40;COL&#40;t&#41; > COL&#40;wk&#41; && COL&#40;wk&#41; > COL&#40;p&#41;)) //que reib no estigui tallant "tall" de torre
		)
		return 4;

	//torre tallant accés del rein al peó per sota
	if &#40;COL&#40;bk&#41; < COL&#40;t&#41; && COL&#40;t&#41; <= COL&#40;p&#41; && ROW&#40;t&#41; < ROW&#40;p&#41;) &#123;
		if &#40;Distance&#40;bk, t&#41; > 2 && Distance&#40;bk, p&#41; - &#40;c == black&#41; > 2 - &#40;c == black && COL&#40;t&#41; == COL&#40;bk&#41; + 1 && COL&#40;t&#41; < COL&#40;p&#41; - 1&#41;) &#123;
			return 4;
		&#125;
		else &#123;
			if &#40;Distance&#40;wk, t&#41; == 1&#41;
				return 4;
			else &#123;
				if &#40;Distance&#40;bk, p&#41; - &#40;c == black&#41; > 2&#41; &#123;
					if &#40;c == black && &#40;wk == 48 || wk == 56&#41; && bk == 17&#41; &#123;
						if &#40;t == 34 && p == 51&#41;
							return 4;
						else
							return 2;
					&#125;
					else
						return 4;
				&#125;
				else &#123;
					if &#40;ROW&#40;p&#41; > ROW&#40;wk&#41; && bk == wk - 16&#41; &#123;
						if &#40;p == 50 && wk == 40&#41;
							; // own == 2;
						else &#123;
							if &#40;p == 51 && wk == 41&#41;
								; //own == 2;
							else
								return 4;
						&#125;
					&#125;
				&#125;
			&#125;
		&#125;
	&#125;

	//reib impedeix rein a arribar al peo
	if &#40;wk == bk + 16 && ROW&#40;p&#41; > ROW&#40;wk&#41;) &#123;
		if &#40;bk == 24 && p == 50 && &#40;t == 9 || &#40;c == black && t == 19&#41;))
			return 2;
		else &#123;
			if &#40;bk == 25 && p == 51 && &#40;t == 10 || &#40;c == black && t == 20&#41;))
				return 2;
			else &#123;
				if &#40;bk == 27 && p == 49 && &#40;t == 10 || t == 16&#41; && c == black&#41;
					return 2;
				else &#123;
					if &#40;bk == 28 && p == 50 && &#40;t == 11 || t == 17&#41; && c == black&#41;
						return 2;
					else &#123;
						if &#40;bk == 29 && p == 51 && &#40;t == 12 || t == 18&#41; && c == black&#41;
							return 2;
						else
							return 4;
					&#125;
				&#125;
			&#125;
		&#125;
	&#125;

	//reib impedeix rein a arribar al peo
	if &#40;ROW&#40;bk&#41; < ROW&#40;wk&#41; - 2 && ROW&#40;p&#41; > ROW&#40;wk&#41; &&
		(&#40;COL&#40;p&#41; > COL&#40;wk&#41; && COL&#40;bk&#41; <= COL&#40;wk&#41;) || &#40;COL&#40;p&#41; < COL&#40;wk&#41; && COL&#40;bk&#41; >= COL&#40;wk&#41;))
		) &#123;
		return 4;
	&#125;

	//torre tallant accés del rein al peó per sota
	if &#40;COL&#40;bk&#41; > COL&#40;t&#41; && COL&#40;t&#41; >= COL&#40;p&#41; && ROW&#40;t&#41; < ROW&#40;p&#41; && ROW&#40;p&#41; > 1 && !&#40;ROW&#40;p&#41; == 6 && Distance&#40;bk, p - 16&#41; - &#40;c == black&#41; < 2&#41;) &#123;
		if &#40;Distance&#40;bk, t&#41; > 2 && Distance&#40;bk, p&#41; - &#40;c == black&#41; > 2 - &#40;c == black && COL&#40;t&#41; == COL&#40;bk&#41; - 1 && COL&#40;t&#41; > COL&#40;p&#41; - 1&#41;) &#123;
			return 4;
		&#125;
		else &#123;
			if &#40;Distance&#40;wk, t&#41; == 1 && &#40;ROW&#40;p&#41; > 2 || Distance&#40;wk, p&#41; < Distance&#40;t, p&#41;))
				return 4;
		&#125;
	&#125;

	//torre podrà tallar accés rei a peo o guanyar peo
	if &#40;c == white && &#40;rattacks & Bit&#40;ROW&#40;t&#41; * 8 + COL&#40;p&#41;))
		&& !&#40;atbk & Bit&#40;ROW&#40;t&#41; * 8 + COL&#40;p&#41;))
		&& ROW&#40;t&#41; < ROW&#40;p&#41; && ROW&#40;p&#41; > 1 && !&#40;ROW&#40;p&#41; == 6 && Distance&#40;bk, p - 16&#41; - &#40;c == black&#41; < 2&#41;) &#123;
		if &#40;Distance&#40;bk, t&#41; > 2 && Distance&#40;bk, p&#41; > 2&#41; &#123;
			return 4;
		&#125;
	&#125;

	//torre pot menjar peó
	if &#40;abs&#40;COL&#40;p&#41; - COL&#40;bk&#41;) > 3 - &#40;c == white && COL&#40;wk&#41; != COL&#40;p&#41;) && ROW&#40;p&#41; - &#40;c == black&#41; > 1
		&& !&#40;ROW&#40;wk&#41; == ROW&#40;t&#41; && &#40;COL&#40;t&#41; > COL&#40;wk&#41; && COL&#40;wk&#41; > COL&#40;p&#41;))) //que reib no estigui tallant "tall" de torre
		return 4;

	//cas especial ofegat
	if &#40;wk == 40 && &#40;bk == 57 || bk == 56&#41; && t == 49 && &#40;p == 9 || &#40;p == 17 && c == black && bk == 56&#41;))
		return 2;

	//cas especial ofegat
	if &#40;wk == 5 && bk == 7 && ROW&#40;t&#41; == 1 && ROW&#40;p&#41; == 1&#41; &#123;
		if &#40;c == black&#41;
			return 0;
		else &#123;
			if &#40;abs&#40;COL&#40;t&#41; - COL&#40;p&#41;) == 1&#41; &#123;
				if &#40;p == 11&#41; &#123;
					if &#40;t == 12&#41;
						return 2;
					else
						return 4;
				&#125;
				else
					return 2;
			&#125;
			else &#123;
				if &#40;COL&#40;t&#41; == COL&#40;wk&#41;) &#123;
					if &#40;p == 11&#41;
						return 4;
					else
						return 2;
				&#125;
				else
					return 4;
			&#125;
		&#125;
	&#125;

	//torre fent escac i guanya peó
	if &#40;bkingincheck && &#40;rattacks & Bit&#40;p&#41;) &&
		&#40;Distance&#40;bk, p&#41; > 2 || &#40;Distance&#40;wk, t&#41; < 3&#41; && Distance&#40;wk, p&#41; < 3 && ROW&#40;wk&#41; <= ROW&#40;p&#41;)) &#123;
		//excepcio taules
		if &#40;wk == 0 && t == 8 && &#40;bk == 16 || bk == 24&#41; && p == 10&#41;
			return 2;
		else &#123;
			if (&#40;wk == 0 || wk == 8&#41; && t == 9 && &#40;bk == 17 || bk == 25&#41; && p == 10&#41;
				return 2; //excepcio taules
			else &#123;
				if &#40;wk < 2 && t == 9 && &#40;bk == 17 || bk == 25&#41; && p == 11&#41;
					return 2; //excepcio taules
				else &#123;
					if &#40;wk == 2 && t == 9 && &#40;bk == 17 || bk == 25&#41; && p == 8&#41;
						return 2; //excepcio taules
					else &#123;
						if (&#40;wk == 1 || wk == 9&#41; && t == 10 && &#40;bk == 18 || bk == 26&#41; && p == 11&#41;
							return 2; //excepcio taules
						else &#123;
							if &#40;wk == 2 && t == 10 && &#40;bk == 18 || bk == 26&#41; && p == 8&#41;
								return 2; //excepcio taules
							else &#123;
								if (&#40;wk == 3 || wk == 11&#41; && t == 10 && &#40;bk == 18 || bk == 26&#41; && p == 9&#41;
									return 2; //excepcio taules
								else &#123;
									if &#40;wk == 3 && t == 11 && &#40;bk == 19 || bk == 27&#41; && p == 9&#41;
										return 2; //excepcio taules
									else &#123;
										if (&#40;wk == 4 || wk == 12&#41; && t == 11 && &#40;bk == 19 || bk == 27&#41; && p == 10&#41;
											return 2; //excepcio taules
										else &#123;
											if &#40;wk == 4 && t == 12 && &#40;bk == 20 || bk == 28&#41; && p == 10&#41;
												return 2; //excepcio taules
											else &#123;
												if (&#40;wk == 5 || wk == 13&#41; && t == 12 && &#40;bk == 20 || bk == 28&#41; && p == 11&#41;
													return 2; //excepcio taules
												else &#123;
													if &#40;wk == 5 && t == 13 && &#40;bk == 21 || bk == 29&#41; && p == 11&#41;
														return 2; //excepcio taules
													else
														return 4;
												&#125;
											&#125;
										&#125;
									&#125;
								&#125;
							&#125;
						&#125;
					&#125;
				&#125;
			&#125;
		&#125;
	&#125;

	//peo corona
	if &#40;Entre&#91;p - 8&#93;&#91;wk&#93; & Bit&#40;bk&#41;)
		coronaambescac = false;
	if &#40;ROW&#40;p&#41; == 1 && !&#40;atwhite & Bit&#40;p - 8&#41;)) &#123;
		if &#40;c == black&#41; &#123;
			if &#40;bk != p - 8&#41; &#123;
				if &#40;ROW&#40;bk&#41; == 0 && &#40;rattacks & FILA1 & atwk&#41;) &#123;
					if &#40;COL&#40;t&#41; - COL&#40;wk&#41; > 2&#41; &#123;
						if &#40;COL&#40;bk&#41; > COL&#40;p&#41;)
							return 2;
						else
							return 0;
					&#125;
					else &#123;
						if &#40;ROW&#40;wk&#41; == 0&#41; &#123;
							if &#40;ROW&#40;t&#41; == 0&#41; &#123;
								if &#40;COL&#40;bk&#41; > COL&#40;t&#41;)
									return 4;
								else
									return 2;
							&#125;
						&#125;
						else &#123;
							if &#40;abs&#40;COL&#40;p&#41; - COL&#40;bk&#41;) < 3&#41;
								return 2;
							else &#123;
								if &#40;COL&#40;bk&#41; > COL&#40;p&#41;) &#123;
									if &#40;ROW&#40;t&#41; == 0 && abs&#40;COL&#40;p&#41; - COL&#40;bk&#41;) == 3&#41;
										return 2;
									/*else &#123;
									if &#40;ROW&#40;t&#41; == 1&#41; &#123;
									if &#40;ROW&#40;wk&#41; == 1&#41; &#123;
									if &#40;COL&#40;t&#41; < COL&#40;wk&#41;)
									return 4;
									&#125;
									&#125;
									&#125;*/
								&#125;
								/*	else
								return 2;*/
							&#125;
						&#125;
					&#125;
				&#125;
				else &#123;
					if (!bkingincheck && coronaambescac&#41; &#123;
						if &#40;COL&#40;t&#41; != COL&#40;p&#41;) &#123;
							if &#40;ROW&#40;p&#41; == ROW&#40;bk&#41; && ROW&#40;bk&#41; == ROW&#40;t&#41;)
								return 2;
							else
								return 0;
						&#125;
					&#125;

				&#125;
			&#125;
		&#125;
	&#125;

	//torre guanya peo
	if (&#40;rattacks & Bit&#40;p&#41;))
	&#123;
		if &#40;Distance&#40;bk, p&#41; + &#40;c == white&#41; > 3 - !&#40;Distance&#40;bk, p - 8&#41; == 2&#41;
			&& &#40;ROW&#40;p&#41; > 1 || c == white&#41; && &#40;ROW&#40;p&#41; != 6 || Distance&#40;bk, p&#41; + &#40;c == white&#41; > 4&#41;)
			return 4;
	&#125;

	//cas especial, fa mat quan negre corona
	if &#40;bk == 0 && p == 16 && ROW&#40;t&#41; == 1 && Distance&#40;wk, p&#41; - &#40;c == white&#41; - &#40;wk == 19&#41; < 2 + &#40;ROW&#40;wk&#41; != 0 && ROW&#40;wk&#41; < 4&#41;)
		return 4;

	//cas especial, fa mat quan negre corona
	if &#40;bk == 16 && p == 17 && COL&#40;t&#41; == 1 &&
		&#40;wk == 33 || &#40;Distance&#40;wk, 9&#41; - &#40;c == white&#41; + &#40;COL&#40;wk&#41; == 0 || &#40;Distance&#40;bk, t&#41; == 1 && Distance&#40;wk, t&#41; > 1&#41;) < 3&#41;)
		&& ROW&#40;t&#41; > ROW&#40;p&#41;)
		return 4;

	//alguns casos coronació
	if (!bkingincheck && ROW&#40;p&#41; == 2 && c == black && Distance&#40;wk, COL&#40;p&#41;) > 2 && COL&#40;t&#41; == COL&#40;wk&#41; && abs&#40;ROW&#40;t&#41; - ROW&#40;bk&#41;) == 1 && abs&#40;COL&#40;bk&#41; - COL&#40;p&#41;) <= 1
		&& ROW&#40;bk&#41; >= ROW&#40;p&#41;
		) &#123;
		if &#40;bk == 17 && ROW&#40;t&#41; > 2 && &#40;wk == 12 || wk == 13 || wk == 14 || wk == 15 || &#40;wk >= 20 && ROW&#40;t&#41; > ROW&#40;wk&#41;)))
			return 0; //no pot parar el peó
		else &#123;
			if &#40;bk == 18 && ROW&#40;t&#41; > 2 && &#40;wk == 8 || wk == 13 || wk == 14 || wk == 15 || &#40;wk >= 21 && ROW&#40;t&#41; > ROW&#40;wk&#41;)))
				return 0;
			else &#123;
				if &#40;bk == 19 && ROW&#40;t&#41; > 2 && &#40;wk == 13 || wk == 14 || wk == 15 || &#40;wk >= 22 && ROW&#40;t&#41; > ROW&#40;wk&#41;)))
					return 0;
				else &#123;
					if &#40;bk == 20 && ROW&#40;t&#41; > 2 && &#40;wk == 8 || wk == 14 || wk == 15 || wk == 16 || &#40;wk >= 23 && ROW&#40;t&#41; > ROW&#40;wk&#41;)))
						return 0;
					/*else
					return 2;*/
				&#125;
			&#125;
		&#125;

	&#125;

	//menja peo
	if (&#40;atwk & Bit&#40;p&#41;) && &#40;rattacks & Bit&#40;p&#41;) && &#40;bk == p + 8 || bk == p - 8 || c == white&#41;) &#123;
		if &#40;bk == 0 && p == 9&#41; &#123;
			if &#40;COL&#40;t&#41; == 1&#41;
				return 4; //farà mate
			else
				return 2;
		&#125;
		else &#123;
			if &#40;bk == 1 && p == 9 && c == black && COL&#40;t&#41; != 0&#41;
				return 2; //ofegarà
			else
				return 4;
		&#125;
	&#125;

	if &#40;c == black && ss->tau.c&#91;p - 8&#93; != CasellaBuida && !&#40;atbk & (~&#40;atwhite | Bit&#40;p&#41;)))) &#123;
		return 4; //mat o guanya
	&#125;
	else &#123;
		if &#40;p == 8 && bk == 0 && wk == 2 /*&& &#40;COL&#40;t&#41; == 1 || ROW&#40;t&#41; == 1 || COL&#40;t&#41; == 0&#41;*/) &#123;
			if &#40;c == white && ROW&#40;t&#41; == 0&#41;
				return 4; //mat
			else
				return 2; //ofegat o taules
		&#125;
		else &#123;
			if &#40;p == 16 && bk == 0 && wk == 2 /*&& &#40;ROW&#40;t&#41; == 1 || COL&#40;t&#41; == 1 || COL&#40;t&#41; == 0&#41; && c == black*/) &#123;
				if &#40;ROW&#40;t&#41; == 0 || c == white&#41;
					return 4;
				else
					return 2;
			&#125;
		&#125;
	&#125;


	//rei surt de casella 0 i vol coronar
	if &#40;bk == 0 && p == 8&#41; &#123;
		if &#40;c == black&#41; &#123;
			if &#40;ROW&#40;t&#41; == 2 &&
				((!&#40;atwk & &#40;Bit&#40;18&#41; | Bit&#40;17&#41; | Bit&#40;10&#41;))) || &#40;wk == 27&#41;)
				) &#123; //si reib no defensa casella on torre pugui fer escac, negre corona i guanya 
				if &#40;COL&#40;t&#41; == 0 || &#40;COL&#40;t&#41; != 2 && COL&#40;t&#41; != COL&#40;wk&#41;))
					return 2; //txp o escac i txp
				else &#123;
					if &#40;ROW&#40;wk&#41; != 1 && COL&#40;t&#41; > 2&#41;
						return 2;
					else
						return 0;
				&#125;
			&#125;
			else &#123;
				if &#40;wk == 16 || wk == 17 || wk == 18&#41; &#123;
					if &#40;wk == 18 && &#40;COL&#40;t&#41; == 0 || &#40;COL&#40;t&#41; == 2 && ROW&#40;t&#41; > 2&#41;))
						return 2;
					else
						return 4; //farà mat
				&#125;
				else &#123;
					if &#40;COL&#40;t&#41; > 2 && &#40;wk == 24 || wk == 25 || &#40;wk == 26 && ROW&#40;t&#41; == 1&#41;))
						return 4;
					else &#123;
						if &#40;COL&#40;wk&#41; >= 2&#41;
							return 2;
						else &#123;
							if &#40;COL&#40;t&#41; == 2 && ROW&#40;t&#41; > 3 && wk == t - 1&#41;
								return 0;
							else
								return 2;
						&#125;
					&#125;

				&#125;
			&#125;
		&#125;
		else &#123; //c == white
			//if &#40;Distance&#40;wk, p&#41; < 3&#41; //4248065
			if ((&#40;t == 9 || t == 17&#41; && &#40;wk == t + 1 || wk == 10&#41;) || &#40;ROW&#40;wk&#41; == 0 && t == 9&#41;)
				return 2;
			else &#123;
				if &#40;COL&#40;wk&#41; > 3 || ROW&#40;wk&#41; > 4&#41;
					return 2;
				else &#123;
					if (&#40;Distance&#40;wk, 10&#41; < 2 && ROW&#40;t&#41; == 0&#41; || &#40;wk == 10&#41;)
						return 4; //mat
					else &#123;
						if (&#40;COL&#40;t&#41; > 2 || t == 10&#41; && Distance&#40;wk, 18&#41; < 2&#41;
							return 4;
						else &#123;
							if &#40;wk == 16 || wk == 17 || wk == 18&#41;
								return 4;
							else &#123;
								if &#40;Distance&#40;wk, 17&#41; < 2 && &#40;t != 17 || &#40;ROW&#40;wk&#41; > 1 && wk != 26&#41;))
									return 4;
								else &#123;
									if &#40;ROW&#40;wk&#41; == 4 && Distance&#40;wk, 17&#41; < 3 && ROW&#40;t&#41; == 1 && t > 10&#41;
										return 4;
									//return 2;
								&#125;
							&#125;
						&#125;
					&#125;
				&#125;
			&#125;

		&#125;
	&#125;

	//cas especial taules
	if &#40;p == 17 && wk == 0 && t == 16 && Distance&#40;bk, 10&#41; - &#40;c == black&#41; < 1&#41; &#123;
		if (&#40;bk == 2 || bk == 10&#41; && c == black&#41;
			return 0;
		else
			return 2;
	&#125;

	//cas especial taules
	if &#40;p == 16 && c == black&#41; &#123;
		if &#40;bk == 24 || bk == 26&#41; &#123;
			if &#40;wk == 2 && t == 1&#41;
				return 2;
			else &#123;
				if &#40;wk == 18 && t == 17&#41;
					return 2;
			&#125;
		&#125;
		else &#123;
			if &#40;bk == 32 && t == 25 && wk == 18&#41;
				return 2;
			else &#123;
				if &#40;bk == 33 && t == 26 && wk == 18&#41;
					return 2;
			&#125;
		&#125;
	&#125;

	//cas especial taules
	if &#40;p == 8 && t == 1 && bk == 24 && wk == 2&#41; &#123;
		return 2;
	&#125;

	//casos especials
	if &#40;ROW&#40;p&#41; == 1 && &#40;atp & Bit&#40;t&#41;) && Distance&#40;bk, p + 8&#41; < 2&#41; &#123;
		if (&#40;atbk & Bit&#40;p - 8&#41;) && abs&#40;wk - bk&#41; != 2 && &#40;bk == 8 || &#40;wk != bk + 10 && wk != bk + 6&#41;))
			return 2;
		else &#123;
			if &#40;atwk & Bit&#40;p + 8&#41;) &#123;
				if &#40;ROW&#40;wk&#41; == 2 || ROW&#40;wk&#41; == 1 || ROW&#40;wk&#41; == ROW&#40;bk&#41;) &#123;
					return 4;
				&#125;
				else
					return 2;
			&#125;
			else &#123;
				if &#40;Distance&#40;wk, p + 1&#41; < 2 && &#40;Distance&#40;bk, p + 9&#41; > 1 || &#40;atwk & Bit&#40;p + 9&#41;)))
					return 4;
				else &#123;
					//return 2;
				&#125;
			&#125;
		&#125;
	&#125;

	if &#40;ROW&#40;bk&#41; >= ROW&#40;p&#41; && ROW&#40;p&#41; > 1&#41; &#123;
		struct InfoEval ie;
		ie.rei&#91;white&#93; = lsb&#40;bwk&#41;;
		ie.rei&#91;black&#93; = lsb&#40;bbk&#41;;
		int antmou = ss->estat_actual->mou;
		ss->estat_actual->mou = c;
		int kpk = -eval_KPK&#40;ss, &ie, black&#41;;
		ss->estat_actual->mou = antmou;
		if &#40;kpk == 0&#41; &#123;
			return 4;
		&#125;
	&#125;

	//rei ha parat peó
	if &#40;ROW&#40;p&#41; > ROW&#40;wk&#41; - &#40;c == white&#41; && ROW&#40;bk&#41; >= ROW&#40;p&#41; && Distance&#40;wk, p&#41; - &#40;c == white&#41; < Distance&#40;bk, p&#41; && ROW&#40;p&#41; - &#40;c == black&#41; >= 2&#41;
		return 4;

	//cas especial
	if &#40;COL&#40;bk&#41; == 0 && COL&#40;p&#41; == 0 && ROW&#40;p&#41; > 2 - &#40;c == black&#41; && &#40;wk == 2 || wk == 10&#41;) &#123;
		if &#40;p == 16 && t == 17 && wk == 10 & bk == 0 && c == black&#41;
			return 2;
		else
			return 4;
	&#125;

	//rei parant peo
	if &#40;COL&#40;wk&#41; == COL&#40;p&#41; + 1 && c == white && ROW&#40;wk&#41; < ROW&#40;p&#41;) &#123;
		if &#40;ROW&#40;p&#41; == 1 && p == wk + 7&#41; &#123;
			if &#40;ROW&#40;t&#41; == 0&#41;
				return 4;
			else &#123;
				if &#40;COL&#40;t&#41; == COL&#40;wk&#41; || COL&#40;t&#41; == COL&#40;wk&#41; + 2&#41; &#123;
					if &#40;ROW&#40;bk&#41; == 0&#41;
						return 2;  //clavarà dama amb torre
					else &#123;
						if &#40;COL&#40;bk&#41; == 0&#41; &#123;
							if &#40;ROW&#40;t&#41; > ROW&#40;bk&#41; + 2&#41;
								return 2; //fent escac canvia dama per torre
							else
								return 0;
						&#125;
						else
							return 0;
					&#125;
				&#125;
				else &#123;
					if &#40;ROW&#40;bk&#41; == 0 && COL&#40;bk&#41; - COL&#40;t&#41; > 1&#41;
						return 2; //farà escac per primera canviant dama x torre
					else &#123;
						if &#40;COL&#40;bk&#41; == 0&#41; &#123;
							if &#40;ROW&#40;t&#41; > ROW&#40;bk&#41; + 2&#41;
								return 2; //fent escac canvia dama per torre
							else
								return 0;
						&#125;
						else
							return 0;
					&#125;
				&#125;
			&#125;
		&#125;
		else &#123;
			if &#40;bk == 8 && &#40;t == 18 || t == 2&#41; && p == 17&#41;
				return 2;
			else &#123;
				if &#40;bk == 9 && &#40;t == 16 || t == 19&#41; && p == 18&#41;
					return 2;
				else &#123;
					if &#40;bk == 10 && &#40;t == 17 || t == 20&#41; & p == 19&#41;
						return 2;
					else
						return 4;
				&#125;
			&#125;
		&#125;
	&#125;

	//rei parant peo
	if &#40;COL&#40;wk&#41; == COL&#40;p&#41; - 1 && c == white && ROW&#40;wk&#41; < ROW&#40;p&#41;) &#123;
		if &#40;ROW&#40;p&#41; == 1 && p == wk + 9&#41; &#123;
			if &#40;ROW&#40;t&#41; == 0&#41;
				return 4;
			else &#123;
				if &#40;COL&#40;wk&#41; == 0&#41;
					return 0;
				else &#123;
					if &#40;COL&#40;t&#41; == COL&#40;wk&#41; || COL&#40;t&#41; == COL&#40;wk&#41; - 2&#41; &#123;
						if &#40;ROW&#40;bk&#41; == 0&#41;
							return 2;  //clavarà dama amb torre
						else &#123;
							return 0;
						&#125;
					&#125;
					else &#123;
						if &#40;ROW&#40;bk&#41; == 0 && COL&#40;t&#41; - COL&#40;bk&#41; > 1&#41;
							return 2; //farà escac per primera canviant dama x torre
						else &#123;
							return 0;
						&#125;
					&#125;
				&#125;
			&#125;
		&#125;
		else &#123;
			if &#40;bk == 10 && t == 19 && p == 17&#41;
				return 2;
			else &#123;
				if &#40;bk == 11 && &#40;t == 17 || t == 20&#41; && p == 18&#41;
					return 2;
				else &#123;
					if &#40;bk == 12 && &#40;t == 18 || t == 21&#41; & p == 19&#41;
						return 2;
					else
						return 4;
				&#125;
			&#125;
		&#125;
	&#125;

	//rei i torre podran parar peo
	if &#40;c == black && COL&#40;wk&#41; == COL&#40;p&#41; + 1 && ROW&#40;p&#41; > ROW&#40;wk&#41; + 1&#41; &#123;
		if &#40;ROW&#40;p&#41; > ROW&#40;wk&#41; + 2 || ROW&#40;p&#41; > 2&#41; &#123;
			if &#40;t == 10 && p == 25 && bk == 0&#41;
				return 2;
			else &#123;
				if &#40;t == 2 && p == 25 && bk == 8&#41;
					return 2;
				else
					return 4;
			&#125;
		&#125;
		else &#123;
			if &#40;bk == 0 && p == 17 && t == 18&#41;
				return 2;
			else &#123;
				if &#40;ROW&#40;t&#41; == 1 || ROW&#40;t&#41; == 0 || COL&#40;t&#41; == COL&#40;p&#41; || &#40;COL&#40;t&#41; == COL&#40;bk&#41; && ROW&#40;t&#41; > 2&#41;
					|| &#40;COL&#40;p&#41; - COL&#40;bk&#41; >= 2 && &#40;COL&#40;t&#41; > COL&#40;p&#41; + 1 || ROW&#40;t&#41; > ROW&#40;p&#41;))
					|| &#40;COL&#40;bk&#41; - COL&#40;p&#41; > 1&#41;
					)
					return 4;
				else &#123;
					if &#40;ROW&#40;bk&#41; > 1&#41; &#123;
						if &#40;t == p + 1&#41;
							return 2;
						else
							return 4;
					&#125;
					else
						if &#40;ROW&#40;bk&#41; == 0&#41; &#123;
							if &#40;COL&#40;bk&#41; + 1 == COL&#40;p&#41;) &#123;
								if &#40;COL&#40;t&#41; == COL&#40;bk&#41; - 1&#41;
									return 0;
								else &#123;
									if &#40;COL&#40;t&#41; == COL&#40;wk&#41; + 1&#41; &#123;
										if &#40;ROW&#40;t&#41; == 2&#41;
											return 0;
										else &#123;
											if &#40;COL&#40;bk&#41; == 0&#41;
												return 2;
											else
												return 0;
										&#125;
									&#125;
									else &#123;
										if &#40;COL&#40;t&#41; == COL&#40;wk&#41; + 2 || COL&#40;t&#41; == COL&#40;wk&#41; || &#40;ROW&#40;t&#41; > 2 && COL&#40;bk&#41; == 0&#41; || COL&#40;bk&#41; - COL&#40;t&#41; > 1&#41;
											return 2;
										else
											return 0;
									&#125;
								&#125;
							&#125;
							else &#123;
								if &#40;bk == 0 && &#40;t == 16 || t == 19&#41;)
									return 2;
								else &#123;
									if &#40;bk == 1 && &#40;t == 17 || t == 20&#41;)
										return 2;
									else
										return 4;
								&#125;
							&#125;
						&#125;
						else &#123;
							//ROW&#40;bk&#41; == 1
							if &#40;ROW&#40;t&#41; == 2&#41; &#123;
								if &#40;COL&#40;bk&#41; + 2 == COL&#40;p&#41;)
									return 2;
								else
									return 0;
							&#125;
							else &#123;
								if &#40;ROW&#40;t&#41; == 3&#41;
									return 0;
								else &#123;
									if &#40;COL&#40;bk&#41; == 0&#41;
										return 2;
									else
										return 0;
								&#125;
							&#125;
						&#125;
				&#125;
			&#125;
		&#125;
	&#125;

	//rei i torre podran parar peo
	if &#40;c == black && COL&#40;wk&#41; == COL&#40;p&#41; - 1 && ROW&#40;p&#41; > ROW&#40;wk&#41; + 1&#41; &#123;
		if &#40;ROW&#40;p&#41; > ROW&#40;wk&#41; + 2 || ROW&#40;p&#41; > 2&#41; &#123;
			return 4;
		&#125;
		else &#123;
			if &#40;ROW&#40;t&#41; == 1 || ROW&#40;t&#41; == 0 || COL&#40;t&#41; == COL&#40;p&#41; || &#40;COL&#40;t&#41; == COL&#40;bk&#41; && ROW&#40;t&#41; > 2&#41;
				|| &#40;COL&#40;bk&#41; - COL&#40;p&#41; >= 2 && &#40;COL&#40;t&#41; < COL&#40;p&#41; - 1 || ROW&#40;t&#41; > ROW&#40;p&#41;))
				|| &#40;COL&#40;p&#41; - COL&#40;bk&#41; > 1&#41;
				)
				return 4;
			else &#123;
				if &#40;ROW&#40;bk&#41; > 1&#41; &#123;
					if &#40;t == p - 1&#41;
						return 2;
					else
						return 4;
				&#125;
				else
					if &#40;ROW&#40;bk&#41; == 0&#41; &#123;
						if &#40;COL&#40;p&#41; + 1 == COL&#40;bk&#41;) &#123;
							if &#40;COL&#40;t&#41; == COL&#40;bk&#41; + 1&#41;
								return 0;
							else &#123;
								if &#40;COL&#40;wk&#41; == COL&#40;t&#41; + 1&#41; &#123;
									if &#40;ROW&#40;t&#41; == 2&#41;
										return 0;
									else
										return 0;
								&#125;
								else &#123;
									if &#40;COL&#40;wk&#41; == 0&#41;
										return 0;
									else &#123;
										if &#40;COL&#40;wk&#41; == COL&#40;t&#41; + 2 || COL&#40;t&#41; == COL&#40;wk&#41; || COL&#40;t&#41; - COL&#40;bk&#41; > 1&#41;
											return 2;
										else
											return 0;
									&#125;
								&#125;
							&#125;
						&#125;
						else &#123;
							if &#40;bk == 3 && t == 19&#41;
								return 2;
							else &#123;
								if &#40;bk == 4 && &#40;t == 17 || t == 20&#41;)
									return 2;
								else &#123;
									if &#40;bk == 5 && &#40;t == 18 || t == 21&#41;)
										return 2;
									else
										return 4;
								&#125;
							&#125;
						&#125;
					&#125;
					else &#123;
						//ROW&#40;bk&#41; == 1
						if &#40;ROW&#40;t&#41; == 3&#41; &#123;
							return 0;
						&#125;
						else &#123;
							if &#40;COL&#40;p&#41; + 1 < COL&#40;bk&#41;) &#123;
								if &#40;t + 1 == p&#41;
									return 2;
								else
									return 4;
							&#125;
							else
								return 0;
						&#125;
					&#125;
			&#125;
		&#125;
	&#125;

	//reib apropant-se al peó per parar-lo
	if &#40;ROW&#40;p&#41; > 3 && ROW&#40;wk&#41; < ROW&#40;p&#41; && Distance&#40;wk, p&#41; < ROW&#40;p&#41;) &#123;
		if &#40;c == white&#41;
			return 4;
		else &#123;
			if &#40;Distance&#40;wk, COL&#40;p&#41;) < ROW&#40;p&#41; - &#40;ROW&#40;p&#41; == 6&#41;) &#123;
				if &#40;p == 35 && wk == 8 && bk == 10 && t == 0&#41;
					return 2;
				else &#123;
					if &#40;COL&#40;p&#41; > 0 && ROW&#40;p&#41; == 4 && bk == p - 23 && wk == bk + 2 && t == wk - 8&#41;
						return 2;
					else &#123;
						if &#40;COL&#40;wk&#41; == 0 && COL&#40;p&#41; == 3 && bk == 10&#41; &#123;
							if &#40;p == 35 && wk == 24 && &#40;t == 4 || t == 5 || t == 6 || t == 7 || t == 20 || t == 21 || t == 22 || t == 23&#41;)
								return 2;
							else
								return 4;
						&#125;
						else &#123;
							if &#40;ROW&#40;bk&#41; == 1 && COL&#40;p&#41; + 1 == COL&#40;bk&#41;) &#123;
								if &#40;wk == bk + 18 && ROW&#40;p&#41; < 5 && COL&#40;t&#41; < COL&#40;p&#41; && &#40;ROW&#40;t&#41; == 0 || ROW&#40;t&#41; == 2&#41;)
									return 2;
								else &#123;
									if &#40;COL&#40;wk&#41; > COL&#40;bk&#41; + 2 && ROW&#40;wk&#41; > 3 && COL&#40;t&#41; < COL&#40;p&#41; && &#40;ROW&#40;t&#41; == 0 || ROW&#40;t&#41; == 2&#41;)
										return 2;
									else
										return 4;
								&#125;
							&#125;
							else &#123;
								if &#40;bk == 18 && wk == 24 && p == 35 && (&#40;ROW&#40;t&#41; == 1 || ROW&#40;t&#41; == 3&#41; && COL&#40;t&#41; > COL&#40;p&#41;))
									return 2;
								else &#123;
									if &#40;bk == 18 && p == 33 && wk == 28 && t == 8&#41;
										return 2;
									else &#123;
										if (!&#40;COL&#40;t&#41; < COL&#40;p&#41; && &#40;ROW&#40;t&#41; == 1 || ROW&#40;t&#41; == 3&#41;)) //torre mal posada
											return 4;
										else &#123;
											if (&#40;p == 41 || p == 49&#41; && bk == 18 && wk == 37&#41;
												return 2;
											else &#123;
												if &#40;p == 34 && wk == 29 && bk == 19&#41;
													return 2;
												else &#123;
													if (&#40;p == 42 || p == 50&#41; && wk == 38 && bk == 19&#41;
														return 2;
													else &#123;
														if &#40;p == 35 && wk == 30 && bk == 20&#41;
															return 2;
														else &#123;
															if (&#40;p == 43 || p == 51&#41; && wk == 39 && bk == 20&#41;
																return 2;
															else
																return 4;
														&#125;
													&#125;
												&#125;
											&#125;
										&#125;
									&#125;
								&#125;
							&#125;
						&#125;
					&#125;
				&#125;
			&#125;
		&#125;
	&#125;


	//reib apropant-se al peó per parar-lo
	if &#40;ROW&#40;p&#41; > 3 && Distance&#40;wk, COL&#40;p&#41;) - &#40;c == white&#41; - bkingincheck < 3&#41;
		return 4;

	//reib apropant - se al peó per parar-lo 
	if &#40;ROW&#40;p&#41; > 3 && ROW&#40;wk&#41; == 0 &&
		(&#40;ROW&#40;t&#41; == 0 && ROW&#40;p&#41; > 4 && COL&#40;wk&#41; - &#40;c == white&#41; < 6&#41;
		|| &#40;Distance&#40;wk, COL&#40;p&#41;) - &#40;c == white&#41; - bkingincheck < 5&#41;
		)
		) &#123;
		if &#40;wk == 5 && p == 33 && (&#40;bk == 18 && t == 8&#41; || &#40;bk == 10 && &#40;t == 0 || t == 10 || t == 16&#41;) || &#40;bk == 0 && t == 10&#41; || &#40;bk == 8 && &#40;t == 2 || t == 18&#41;)) && c == black&#41;
			return 2;
		else &#123;
			if &#40;wk == 4 && p == 32 && (&#40;bk == 1 && t == 11&#41; || &#40;bk == 9 && &#40;t == 3 || t == 19&#41;)) && c == black&#41;
				return 2;
			else &#123;
				if &#40;wk == 6 && p == 34 && (&#40;bk == 19 && t == 9&#41; || &#40;bk == 17 && t == 11&#41; || &#40;bk == 11 && &#40;t == 1 || t == 17&#41;) || &#40;bk == 1 && t == 11&#41; || &#40;bk == 9 && &#40;t == 3 || t == 19&#41;)) && c == black&#41;
					return 2;
				else &#123;
					if &#40;wk == 7 && p == 35 && (&#40;bk == 20 && t == 10&#41; || &#40;bk == 18 && t == 12&#41; || &#40;bk == 12 && &#40;t == 2 || t == 18&#41;) || &#40;bk == 2 && t == 12&#41; || &#40;bk == 10 && &#40;t == 4 || t == 20&#41;)) && c == black&#41;
						return 2;
					else &#123;
						return 4;
					&#125;
				&#125;
			&#125;
		&#125;
	&#125;

	//torre amenaça peó i se'l menjarà
	if &#40;COL&#40;t&#41; == COL&#40;p&#41; && Distance&#40;bk, p&#41; - &#40;c == black&#41; > 1 && &#40;rattacks & Bit&#40;p&#41;)) &#123;
		if (!&#40;c == black && ROW&#40;p&#41; == 6 && &#40;p - bk == 25 || p - bk == 23&#41;)) &#123; //que avançant dos caselles no quedi defensat
			if &#40;c == black&#41; &#123;
				if &#40;wk == 57 && bk == 24 && p == 48 && t == 56&#41;
					return 2;
				else &#123;
					if (&#40;wk == 61 || wk == 62 || wk == 63&#41; && bk == 25 && p == 49 && t == 57&#41;
						return 2;
					else &#123;
						if (&#40;wk == 62 || wk == 63&#41; && bk == 26 && p == 50 && t == 58&#41;
							return 2;
						else &#123;
							if &#40;wk == 63 && bk == 27 && p == 51 && t == 59&#41;
								return 2;
							else &#123;
								if &#40;wk == 40 && bk == 56 && p == 9 && &#40;t == 17 || t == 25 || t == 33 || t == 41&#41;)
									return 2;
								else
									return 4;
							&#125;
						&#125;
					&#125;
				&#125;
			&#125;
			else
				return 4;
		&#125;
	&#125;

	//peo retrassat
	if &#40;ROW&#40;p&#41; + &#40;c == white&#41; > 3 && Distance&#40;bk, p&#41; - &#40;c == black&#41; > 4&#41; &#123;
		if &#40;rattacks & rook_attacks&#40;p + 8, allpieces&#41;) //torre podrà anar davant peó i menjar-lo
			return 4;
		else &#123;
			if (&#40;rattacks & rook_attacks&#40;COL&#40;p&#41;, allpieces&#41;) && Distance&#40;bk, COL&#40;p&#41;) + &#40;c == white&#41; > 2&#41; //torre podrà anar davant peó i menjar-lo
				return 4;
		&#125;
	&#125;

	//peo retrassat a columna A
	if &#40;COL&#40;p&#41; == 0 && ROW&#40;p&#41; > 3&#41; &#123;
		if &#40;Distance&#40;wk, COL&#40;p&#41;) - &#40;c == white&#41; - &#40;ROW&#40;bk&#41; == 0&#41; < 4&#41; &#123;
			if &#40;wk == 36 && bk == 17 && t == 10&#41;
				return 2;
			else &#123;
				if &#40;wk == 4 && bk == 1 && t == 11 && p == 32&#41;
					return 2;
				else
					return 4;
			&#125;
		&#125;
		else &#123;
			/*if &#40;Distance&#40;wk, COL&#40;p&#41;) > 6&#41;
			return 2;*/
		&#125;
	&#125;

	//cas especial mat
	//5310956
	if (!bkingincheck && bk == 7 && &#40;wk == 13 || wk == 22&#41;) &#123;
		if &#40;c == white&#41;
			return 4;
		else &#123;
			if &#40;wk == 13&#41; &#123;
				if &#40;ROW&#40;t&#41; == 1&#41; &#123;
					if &#40;t == 12&#41;
						return 2;
					else
						return 0;
				&#125;
				else &#123;
					if &#40;p == 11 && &#40;t == 18 || t == 20&#41;) &#123;
						return 2; //tisores de caball
					&#125;
					else
						if &#40;ROW&#40;p&#41; == 1&#41; &#123;
							if (&#40;rattacks & COLUMNAH&#41; & PrecalculAlfil&#91;p - 8&#93;) &#123; //dama al coronar evitarà mat per columna H
								if &#40;COL&#40;t&#41; == 4&#41;
									return 2; //escac a e1
								else
									return 0; //dama evita mat
							&#125;
							else
								return 4; //mat
						&#125;
						else
							return 4; //mat
				&#125;
			&#125;
			else &#123;
				//wk == 22
				if &#40;ROW&#40;p&#41; == 1&#41;
					return 0;
				else &#123;
					if &#40;ROW&#40;p&#41; == 1&#41; &#123;
						if (&#40;rattacks & COLUMNAH&#41; & PrecalculAlfil&#91;p - 8&#93;) &#123; //dama al coronar evitarà mat per columna H
							return 0; //dama evita mat
						&#125;
						else
							return 4; //mat
					&#125;
					else
						return 4; //mat
				&#125;
			&#125;
		&#125;
	&#125;

	//cas especial mat
	if &#40;bk == 63 && !bkingincheck && &#40;wk == 46 || wk == 53&#41;) &#123;
		if &#40;c == white&#41;
			return 4;
		else &#123;
			if &#40;wk == 46&#41; &#123;
				if &#40;p == 9&#41;
					return 0;
				else &#123;
					if &#40;COL&#40;t&#41; == 6 && ROW&#40;p&#41; == 1&#41;
						return 0;
					else
						return 4;
				&#125;
			&#125;
			else
			&#123; //wk == 53
				if &#40;ROW&#40;t&#41; == 6 && ROW&#40;p&#41; == 1&#41;
					return 0;
				else &#123;
					if &#40;p == 9&#41;
						return 2; //tapa escac amb dama
					else &#123;
						if &#40;ROW&#40;p&#41; == 1&#41; &#123;
							if (&#40;rattacks & COLUMNAH&#41; & PrecalculAlfil&#91;p - 8&#93;) &#123; //dama al coronar evitarà mat per columna H
								return 0; //dama evita mat
							&#125;
							else
								return 4; //mat
						&#125;
						else
							return 4; //mat
					&#125;
				&#125;
			&#125;
		&#125;
	&#125;

	if &#40;ROW&#40;p&#41; == 1 && ROW&#40;bk&#41; == 0 && c == black && !&#40;atwhite & Bit&#40;p - 8&#41;) && bk != p - 8 && !bkingincheck&#41; &#123;
		Bitboard b = &#40;rattacks & atwk&#41; & FILA1; //casella on torre pot anar a 1a defensat per rei
		bool torreatacapeo = rattacks & Bit&#40;p&#41;;
		if &#40;b&#41; &#123;
			if &#40;ROW&#40;wk&#41; == 1&#41; &#123;
				if &#40;COL&#40;t&#41; > COL&#40;bk&#41; && COL&#40;t&#41; > COL&#40;p&#41;) &#123;
					if &#40;COL&#40;bk&#41; > COL&#40;p&#41; + 3 || &#40;COL&#40;bk&#41; > COL&#40;p&#41; + 1 && torreatacapeo&#41;)
						return 4;
					else
						return 2;
				&#125;
				else &#123;
					if &#40;COL&#40;t&#41; < COL&#40;bk&#41; && COL&#40;t&#41; < COL&#40;p&#41;) &#123;
						return 2;
					&#125;
					else
						if &#40;COL&#40;t&#41; > COL&#40;p&#41; && COL&#40;bk&#41; == COL&#40;t&#41; + 1&#41;
							return 0;
				&#125;
			&#125;
		&#125;
	&#125;

	//corona i potser guanya
	if &#40;c == black && !bkingincheck && ROW&#40;p&#41; == 1 && ROW&#40;t&#41; != 0 && COL&#40;t&#41; < COL&#40;p&#41; && bk != p - 8&#41; &#123;
		//return 0;
		if &#40;ROW&#40;t&#41; == ROW&#40;bk&#41;) &#123;
			if &#40;ROW&#40;wk&#41; == ROW&#40;t&#41;) &#123;
				if &#40;COL&#40;wk&#41; < COL&#40;p&#41; && COL&#40;t&#41; < COL&#40;wk&#41;)
					return 0;
				else &#123;
					if &#40;Distance&#40;bk, p&#41; > 2&#41; &#123;
						if &#40;ROW&#40;wk&#41; == ROW&#40;bk&#41; && wk < bk && p < wk&#41;
							return 0;
						else
							return 4;
					&#125;
					else &#123;
						return 2;
					&#125;
				&#125;
			&#125;
			else &#123;
				return 2;
			&#125;
		&#125;
		else &#123;
			if &#40;COL&#40;p&#41; == COL&#40;wk&#41;) &#123;
				//aquí COL&#40;bk&#41; == COL&#40;p&#41;)
				if &#40;ROW&#40;t&#41; < ROW&#40;bk&#41; || ROW&#40;t&#41; >= ROW&#40;wk&#41;)
					return 0;
				else &#123;
					if &#40;ROW&#40;wk&#41; > ROW&#40;t&#41; + 1&#41; &#123;
						if &#40;ROW&#40;t&#41; > ROW&#40;bk&#41; + 1&#41;
							return 2;
						else
							return 0;
					&#125;
					else &#123;
						if &#40;Distance&#40;bk, p&#41; > 3&#41;
							return 4;
						else
							return 2;
					&#125;
				&#125;
			&#125;
			else &#123;
				if &#40;COL&#40;bk&#41; == 0 && wk == bk + 2&#41; &#123; //casos especials mat
					if &#40;abs&#40;ROW&#40;t&#41; - ROW&#40;bk&#41;) == 1&#41;
						return 0;
					else &#123;
						if (&#40;p == 11 && wk == 18&#41; || &#40;p == 11 && wk == 34 && ROW&#40;t&#41; < ROW&#40;bk&#41;))
							return 2;
						else &#123;
							if &#40;p == 11 && &#40;bk == 40 || bk == 48 || bk == 56&#41; && ROW&#40;t&#41; == 3&#41;
								return 0;
							else
								return 4;
						&#125;
					&#125;
				&#125;
				else &#123;
					//return 0;
					if &#40;COL&#40;p&#41; == 2 && COL&#40;bk&#41; < 2 && ROW&#40;t&#41; > ROW&#40;bk&#41; && ROW&#40;wk&#41; == ROW&#40;t&#41; + 1&#41; &#123;
						if &#40;ROW&#40;t&#41; < 3&#41;
							return 0;
						else &#123;
							if &#40;COL&#40;wk&#41; == 0&#41;
								return 0;
							else &#123;
								if &#40;COL&#40;wk&#41; > 1&#41;
									return 0;
								else
									return 2;
							&#125;

						&#125;
					&#125;
					else &#123;
						if &#40;p == 11 && COL&#40;t&#41; == 1 && wk == 0&#41;
							return 2;
						else &#123;
							if &#40;wk == 8 && bk == 2&#41; &#123;
								if &#40;ROW&#40;t&#41; == 2&#41;
									return 0;
								else
									return 2;
							&#125;
							else &#123;
								if &#40;bk == p - 7 && wk == bk + 10&#41; &#123;
									if &#40;ROW&#40;t&#41; < 3&#41;
										return 0;
									else
										return 2;
								&#125;
								else
								&#123;
									if &#40;COL&#40;t&#41; == 0 && bk == 2 && p == 11 && !&#40;COL&#40;wk&#41; == 0 && wk < t&#41; && !&#40;wk == t + 1&#41; && !&#40;wk == t + 2 && wk != 18&#41;)
										return 2;
									else &#123;
										if &#40;p == 10 && &#40;wk == 0 || wk == 8&#41; && COL&#40;t&#41; == 1 && ROW&#40;bk&#41; == 0&#41;
											return 2;
										else &#123;
											if &#40;p == 11 && &#40;wk == 1 || wk == 9&#41; && COL&#40;t&#41; == 2 && ROW&#40;bk&#41; == 0&#41;
												return 2;
											else &#123;
												if &#40;wk == 8 && bk == 10&#41; &#123;
													if &#40;ROW&#40;t&#41; == 2 || ROW&#40;t&#41; == 3&#41;
														return 0;
													else
														return 2;
												&#125;
												else &#123;
													if &#40;wk == bk + 2 && COL&#40;bk&#41; == COL&#40;p&#41; + 1&#41; &#123;
														if &#40;ROW&#40;t&#41; <= ROW&#40;bk&#41; + 2 || ROW&#40;wk&#41; == 0&#41;
															return 0;
														else
															return 2;
													&#125;
													else &#123;
														if &#40;COL&#40;bk&#41; == 7 && wk == bk - 2 && abs&#40;ROW&#40;t&#41; - ROW&#40;bk&#41;) > 1 &&
															!(&#40;rattacks & COLUMNAH&#41; & PrecalculAlfil&#91;p - 8&#93;)  //dama al coronar evitarà mat per columna H
															) &#123;
															if &#40;ROW&#40;t&#41; > ROW&#40;bk&#41; && &#40;PrecalculAlfil&#91;p - 8&#93; & Bit&#40;bk + 8&#41;))
																return 2; //tapa de dama
															else &#123;
																if &#40;ROW&#40;t&#41; < ROW&#40;bk&#41; && &#40;PrecalculAlfil&#91;p - 8&#93; & Bit&#40;bk - 8&#41;))
																	return 2; //tapa de dama
																else
																	return 4;
															&#125;
														&#125;
														else &#123;
															if &#40;COL&#40;bk&#41; == COL&#40;p&#41;) &#123;
																if &#40;ROW&#40;t&#41; > ROW&#40;bk&#41; + 2&#41; &#123;
																	if &#40;Distance&#40;wk, p&#41; < 3&#41; &#123;
																		if &#40;Distance&#40;bk, p&#41; < 3&#41;
																			return 2;
																		else &#123;
																			if &#40;knight_attacks&#91;p - 8&#93; & bwk&#41; &#123; //fa escac de caball al coronar 
																				if (&#40;wk == 11 || wk == 18&#41; && bk == 33&#41;
																					return 4;
																				else
																					return 2;
																			&#125;
																			else
																				return 4;
																		&#125;
																	&#125;
																	else &#123;
																		if &#40;Distance&#40;wk, p&#41; < 3 && Distance&#40;bk, p&#41; == 3&#41;
																			return 4;
																		else &#123;
																			if &#40;ROW&#40;t&#41; == ROW&#40;wk&#41; && COL&#40;wk&#41; <= COL&#40;p&#41; && COL&#40;t&#41; < COL&#40;wk&#41;)
																				return 0;
																			else &#123;
																				if &#40;bk == p + 24 && &#40;wk == p + 3 || wk == p - 3&#41;)
																					return 4;
																				else
																					return 2;
																			&#125;
																		&#125;
																	&#125;
																&#125;
																else &#123;

																&#125;
															&#125;
														&#125;
													&#125;
												&#125;
											&#125;
										&#125;
									&#125;
								&#125;
							&#125;
						&#125;
					&#125;
				&#125;
			&#125;
		&#125;
	&#125;
	return 999;
&#125;


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

Re: advanced krkp function

Post by hgm » Sat May 06, 2017 12:31 pm

cdani wrote:It solves a big part (if I remember well + than 50%) of the positions with tablebase like resolution.
I suppose you mean with bitbase-like resolution. You don't get any DTM/DTZ.

How important is it really to go into so much detail? When I was doing KPK evaluation in KingSlayer, I noticed that the only important thing is really to recognize some certain-draw positions, where it would take very long for the draw to become apparent. Positions where a draw is achieved quickly, e.g. because of stalemate or because the Pawn gets lost, are found very quickly by the search.
Last edited by hgm on Sat May 06, 2017 12:43 pm, edited 2 times in total.

User avatar
cdani
Posts: 2095
Joined: Sat Jan 18, 2014 9:24 am
Location: Andorra
Contact:

Re: advanced krkp function

Post by cdani » Sat May 06, 2017 12:36 pm

hgm wrote:
cdani wrote:It solves a big part (if I remember well + than 50%) of the positions with tablebase like resolution.
I suppose you mean with bitbase-like resolution. You don't get any DTM/DTZ.
Sorry, yes :-)

Daniel Anulliero
Posts: 652
Joined: Fri Jan 04, 2013 3:55 pm
Location: Nice

Re: advanced krkp function

Post by Daniel Anulliero » Fri May 12, 2017 10:49 am

Great work Daniel !
So , Mr Sean and Henk can see your own work for Andscacs :wink:

AlvaroBegue
Posts: 912
Joined: Tue Mar 09, 2010 2:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: advanced krkp function

Post by AlvaroBegue » Fri May 12, 2017 1:50 pm

I'll definitely give this a try. I'll just translate the comments from Catalan to Basque so more people can read them. :)

User avatar
cdani
Posts: 2095
Joined: Sat Jan 18, 2014 9:24 am
Location: Andorra
Contact:

Re: advanced krkp function

Post by cdani » Fri May 12, 2017 5:27 pm

AlvaroBegue wrote:I'll definitely give this a try. I'll just translate the comments from Catalan to Basque so more people can read them. :)
:-)
Nice!

I forgot to tell that it requires also a KPK endgame bitbase accessible (the call to eval_KPK). The function uses it to find a lot of won endgames, because if the kpk endgame was draw, then the krkp is won for the rook side on most cases (the drawn cases are filtered previously to this call to eval_KPK).

User avatar
cdani
Posts: 2095
Joined: Sat Jan 18, 2014 9:24 am
Location: Andorra
Contact:

Re: advanced krkp function

Post by cdani » Fri May 12, 2017 5:41 pm

hgm wrote: How important is it really to go into so much detail? When I was doing KPK evaluation in KingSlayer, I noticed that the only important thing is really to recognize some certain-draw positions, where it would take very long for the draw to become apparent. Positions where a draw is achieved quickly, e.g. because of stalemate or because the Pawn gets lost, are found very quickly by the search.
Sorry, I didn't saw the rest of your message, or maybe was not there when I first answered.

Really not important in most cases as you tell. I have done it more for fun than for anything else. Anyway should be a bit better than a basic function, but probably not really measurable in elo.

I have done also the KNPK (yes, against a lone king). Contrary to what one can think at first, is full of draws. Is bigger than this one, over 2000 lines of code :-) due to that the exceptions are very common but more sparse, and difficult to grab a lot of them in a few instructions, so often it compares against little local (local to the "if") databases of positions such exceptions. Maybe I will publish it when I clean a little. Of course it solves the typical a7 pawn a8 wk c7/c8 bk that is draw due to the inability of the knight to win tempos, this with a few if's.

I also have done other way of doing a shorter function for KRPKB that instead of going exact, returns a typical eval related to the possibilities of winning/drawing of different structures of the pieces/pawns, comparing all the posibilities thanks to syzygy so selecting the wheigths that return more similar results to the tablebase.

User avatar
velmarin
Posts: 1580
Joined: Mon Feb 21, 2011 8:48 am

Re: advanced krkp function

Post by velmarin » Fri May 12, 2017 8:32 pm

AlvaroBegue wrote:I'll definitely give this a try. I'll just translate the comments from Catalan to Basque so more people can read them. :)
Not much difference, the Basques shave their beard without foam, the Catalans if they use it.

:lol: :lol: :lol: :lol: :lol: :lol: :lol:

brtzsnr
Posts: 433
Joined: Fri Jan 16, 2015 3:02 pm
Contact:

Re: advanced krkp function

Post by brtzsnr » Fri May 12, 2017 10:01 pm

What would be the Elo gain of this function? Endgame evaluation didn't work so far for me which is why it's completely missing from my engine. I tried a few things like KmKm is draw, or bitbase for KpK.

User avatar
cdani
Posts: 2095
Joined: Sat Jan 18, 2014 9:24 am
Location: Andorra
Contact:

Re: advanced krkp function

Post by cdani » Fri May 12, 2017 10:25 pm

brtzsnr wrote:What would be the Elo gain of this function? Endgame evaluation didn't work so far for me which is why it's completely missing from my engine. I tried a few things like KmKm is draw, or bitbase for KpK.
Near 0. As told was more for fun than for anything practical.

Yo can win something with endgame functions as you start to accumulate quite a few of them, starting from the most basic ones and going up covering the most common ones.

Post Reply