small rybka source code released by author to public

Discussion of chess software programming and technical issues.

Moderator: Ras

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: 2251
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(i = 0; i < pos.knight_count(side); i++) {
      from = pos.knight_list(side, i);
      b = pos.knight_attacks(from) & target;
      while(b) {
        to = pop_1st_bit(&b);
        mlist[n++].move = make_move(from, to);
      }
    }
    return n;
  }
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 (bb1) {
			int sq;
			sq = obtenerPrimerBit(bb1);

			bb2 = (st_caballo[sq] & (ptrPosicion->piezas_negras | ptrPosicion->vacias));

			while (bb2) {
				int sq2 = obtenerPrimerBit(bb2);
				pORIGEN(ptrMovimiento,sq);
				pDESTINO(ptrMovimiento,sq2);
				pCAPTURA(ptrMovimiento,ptrPosicion->piezas[sq2]);
				ponerBit0(bb2,sq2);
				++cont;
				ptrMovimiento = &listado_movimientos[jugada_actual][cont];
				*ptrMovimiento = 0;
			}
			ponerBit0(bb1, sq);
		}
Dann Corbit
Posts: 12777
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 (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
For comparison, here is Strelka's knight captures (they are divided by color so this is only half):

Code: Select all

    for (mask_from = Board->mp[WhiteKnight]; mask_from != 0; mask_from &= (mask_from-1)) {
      from = first_one(mask_from);
      for (mask_to = MaskKnightMoves[from] & mask_b; mask_to != 0; mask_to &= (mask_to-1)) {
        to = first_one(mask_to);
        list->move = (from << 6) | to;
        (list++)->score = (Board->square[to]) * 3 + 12;  //score is captured piece * 3 + 12;
      }
    }
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:
      {
        CTBB theToBB = RefAttackFrSq(theFrSq) & thePasLocusBB;
        CTSq theToSq;

        CTScanBB(theToSq, theToBB)
        {
          theMove.PutToSq(theToSq);
          theMove.PutToMan(theBoard.GetSqMan(theToSq));
          theMLPtr->ATM(theMove);
        };
        theMove.PutToMan(CTManVacant);
      };
      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 [boards+18h]	//white knights bitboard
		mov 	ebx, dword ptr [boards+1Ch]
		mov	eax, edi
		or 	eax, ebx
		je 	short capwBP1			//jump to bishops if no knights
		mov 	dword ptr [temp], edi		//save bitboard
		mov 	dword ptr [temp+4], ebx
	capwKN1:
		sub 	esi, esi
		bsr 	ecx, ebx			//bitscan
		lea	edx, [esi+1]
		jne 	short capwKN2
		bsr 	ecx, edi
		shl 	edx, cl
		xor 	esi, ecx
		xor 	dword ptr [temp], edx
		jmp 	short capwKN3
	capwKN2:
		shl 	edx, cl
		lea 	esi, [ecx+0x20]
		xor 	dword ptr [temp+4], edx
	capwKN3:
		mov 	edi, dword ptr Ndb [esi*8]	//knight moves database esi=FROM square
		mov 	ebx, dword ptr Ndb+4 [esi*8]
		and 	edi, dword ptr [boards+8]	//AND black pieces
		and 	ebx, dword ptr [boards+0Ch]
		mov	eax, edi
		or	eax, ebx
		je	short capwKN7			//loop if no moves
	capwKN4:
		mov	edx, 1
		bsr 	ecx, ebx			//bitscan
		jnz 	short capwKN5
		bsr 	ecx, edi
		shl 	edx, cl	
		xor 	edi, edx
		jmp	short capwKN6
	capwKN5:
		shl 	edx, cl
		lea 	ecx, [ecx+0x20]
		xor 	ebx, edx
	capwKN6:
		call	whiteCaps			//get captured piece and FROM in eax
		shl	ecx, 6
		mov	edx, ebx
		lea	eax, [eax+ecx+0x3000]		//ecx=TO square
		or 	edx, edi
		push	eax				//store move on stack
		jne 	short capwKN4			//loop if more moves
	capwKN7:
		mov 	edi, dword ptr [temp]
		mov 	ebx, dword ptr [temp+4]
		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.