small rybka source code released by author to public

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

kaustubh

small rybka source code released by author to public

Post by kaustubh »

The author of rybka chess released small source code of rybka to public in his forum i am showing you this. If this is against the rules of this forum then i will delete it quickly.

here's white knight captures :D

for (bb_t knights = Board.pieces [WN]; knights; knights &= knights-1)
{
int knight_sq = bit_scan (knights);
for (bb_t captures = knight_moves [knight_sq] & opponent_pieces; captures; captures &= captures - 1)
{
int capture_sq = bit_scan (captures);
*moves ++ = move (knight_sq, capture_sq);
*values ++ = Board.sq [capture_sq] * 256 + 192;
}
}

Vas http://rybkaforum.net/cgi-bin/rybkaforu ... =#pid20184
yoshiharu
Posts: 56
Joined: Sat Nov 11, 2006 11:14 pm

Re: small rybka source code released by author to public

Post by yoshiharu »

kaustubh wrote: here's white knight captures :D

(omitted)
Honestly...

Cheers, Mauro
Gerd Isenberg
Posts: 2250
Joined: Wed Mar 08, 2006 8:47 pm
Location: Hattingen, Germany

Re: small rybka source code released by author to public

Post by Gerd Isenberg »

So Rybka has despite bitboards a board array - and keeps disjoint lists for moves and their scores.
You will find such tiny bitscan loops in almost every classical bitboard program. Here is what Tord does in Glaurung:

Code: Select all

  int generate_knight_moves(const Position& pos, MoveStack* mlist, 
                            Color side, Bitboard target) {
    Square from, to;
    Bitboard b;
    int i, n = 0;

    for&#40;i = 0; i < pos.knight_count&#40;side&#41;; i++) &#123;
      from = pos.knight_list&#40;side, i&#41;;
      b = pos.knight_attacks&#40;from&#41; & target;
      while&#40;b&#41; &#123;
        to = pop_1st_bit&#40;&b&#41;;
        mlist&#91;n++&#93;.move = make_move&#40;from, to&#41;;
      &#125;
    &#125;
    return n;
  &#125;
Gerd
User avatar
Kempelen
Posts: 620
Joined: Fri Feb 08, 2008 10:44 am
Location: Madrid - Spain

Re: small rybka source code released by author to public

Post by Kempelen »

I post my knight genmove routine. I think it is quit fast. Sorry, it is in spanish

Code: Select all

		// MOVIMIENTO CABALLO BLANCO
		// ----------------------------------------------------------------------
		bb1 = ptrPosicion->caballos_blancos;

		while &#40;bb1&#41; &#123;
			int sq;
			sq = obtenerPrimerBit&#40;bb1&#41;;

			bb2 = &#40;st_caballo&#91;sq&#93; & &#40;ptrPosicion->piezas_negras | ptrPosicion->vacias&#41;);

			while &#40;bb2&#41; &#123;
				int sq2 = obtenerPrimerBit&#40;bb2&#41;;
				pORIGEN&#40;ptrMovimiento,sq&#41;;
				pDESTINO&#40;ptrMovimiento,sq2&#41;;
				pCAPTURA&#40;ptrMovimiento,ptrPosicion->piezas&#91;sq2&#93;);
				ponerBit0&#40;bb2,sq2&#41;;
				++cont;
				ptrMovimiento = &listado_movimientos&#91;jugada_actual&#93;&#91;cont&#93;;
				*ptrMovimiento = 0;
			&#125;
			ponerBit0&#40;bb1, sq&#41;;
		&#125;
Dann Corbit
Posts: 12540
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: small rybka source code released by author to public

Post by Dann Corbit »

kaustubh wrote:The author of rybka chess released small source code of rybka to public in his forum i am showing you this. If this is against the rules of this forum then i will delete it quickly.

here's white knight captures :D

Code: Select all

for &#40;bb_t knights = Board.pieces &#91;WN&#93;; knights; knights &= knights-1&#41;
&#123;
    int knight_sq = bit_scan &#40;knights&#41;;
    for &#40;bb_t captures = knight_moves &#91;knight_sq&#93; & opponent_pieces; captures; captures &= captures - 1&#41;
    &#123;
        int capture_sq = bit_scan &#40;captures&#41;;
        *moves ++ = move &#40;knight_sq, capture_sq&#41;;
        *values ++ = Board.sq &#91;capture_sq&#93; * 256 + 192;
    &#125;
&#125;
Vas http://rybkaforum.net/cgi-bin/rybkaforu ... =#pid20184
For comparison, here is Strelka's knight captures (they are divided by color so this is only half):

Code: Select all

    for &#40;mask_from = Board->mp&#91;WhiteKnight&#93;; mask_from != 0; mask_from &= &#40;mask_from-1&#41;) &#123;
      from = first_one&#40;mask_from&#41;;
      for &#40;mask_to = MaskKnightMoves&#91;from&#93; & mask_b; mask_to != 0; mask_to &= &#40;mask_to-1&#41;) &#123;
        to = first_one&#40;mask_to&#41;;
        list->move = &#40;from << 6&#41; | to;
        &#40;list++)->score = &#40;Board->square&#91;to&#93;) * 3 + 12;  //score is captured piece * 3 + 12;
      &#125;
    &#125;
There is clearly a distinct similarity.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: small rybka source code released by author to public

Post by sje »

Symbolic's knight capturing code:

Code: Select all

    case CTPieceKnight&#58;
      &#123;
        CTBB theToBB = RefAttackFrSq&#40;theFrSq&#41; & thePasLocusBB;
        CTSq theToSq;

        CTScanBB&#40;theToSq, theToBB&#41;
        &#123;
          theMove.PutToSq&#40;theToSq&#41;;
          theMove.PutToMan&#40;theBoard.GetSqMan&#40;theToSq&#41;);
          theMLPtr->ATM&#40;theMove&#41;;
        &#125;;
        theMove.PutToMan&#40;CTManVacant&#41;;
      &#125;;
      break;
The case body is selected only if the side to move is not in check and the knight in question is not pinned; therefore, only legal moves are output.
grant
Posts: 67
Joined: Mon Aug 06, 2007 4:42 pm
Location: London, England

Re: small rybka source code released by author to public

Post by grant »

Knight capture code in Atlanchess.
Moves are pushed onto the stack and retrieved at the end of the function.

Code: Select all

mov 	edi, dword ptr &#91;boards+18h&#93;	//white knights bitboard
		mov 	ebx, dword ptr &#91;boards+1Ch&#93;
		mov	eax, edi
		or 	eax, ebx
		je 	short capwBP1			//jump to bishops if no knights
		mov 	dword ptr &#91;temp&#93;, edi		//save bitboard
		mov 	dword ptr &#91;temp+4&#93;, ebx
	capwKN1&#58;
		sub 	esi, esi
		bsr 	ecx, ebx			//bitscan
		lea	edx, &#91;esi+1&#93;
		jne 	short capwKN2
		bsr 	ecx, edi
		shl 	edx, cl
		xor 	esi, ecx
		xor 	dword ptr &#91;temp&#93;, edx
		jmp 	short capwKN3
	capwKN2&#58;
		shl 	edx, cl
		lea 	esi, &#91;ecx+0x20&#93;
		xor 	dword ptr &#91;temp+4&#93;, edx
	capwKN3&#58;
		mov 	edi, dword ptr Ndb &#91;esi*8&#93;	//knight moves database esi=FROM square
		mov 	ebx, dword ptr Ndb+4 &#91;esi*8&#93;
		and 	edi, dword ptr &#91;boards+8&#93;	//AND black pieces
		and 	ebx, dword ptr &#91;boards+0Ch&#93;
		mov	eax, edi
		or	eax, ebx
		je	short capwKN7			//loop if no moves
	capwKN4&#58;
		mov	edx, 1
		bsr 	ecx, ebx			//bitscan
		jnz 	short capwKN5
		bsr 	ecx, edi
		shl 	edx, cl	
		xor 	edi, edx
		jmp	short capwKN6
	capwKN5&#58;
		shl 	edx, cl
		lea 	ecx, &#91;ecx+0x20&#93;
		xor 	ebx, edx
	capwKN6&#58;
		call	whiteCaps			//get captured piece and FROM in eax
		shl	ecx, 6
		mov	edx, ebx
		lea	eax, &#91;eax+ecx+0x3000&#93;		//ecx=TO square
		or 	edx, edi
		push	eax				//store move on stack
		jne 	short capwKN4			//loop if more moves
	capwKN7&#58;
		mov 	edi, dword ptr &#91;temp&#93;
		mov 	ebx, dword ptr &#91;temp+4&#93;
		mov	eax, edi
		or	eax, ebx
		jne 	short capwKN1			//loop if more knights
Grant
Guetti

Re: small rybka source code released by author to public

Post by Guetti »

This was already posted half a year ago:

http://www.talkchess.com/forum/viewtopi ... ite+knight

Not much new.