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
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
small rybka source code released by author to public
Moderators: hgm, Rebel, chrisw
-
- Posts: 56
- Joined: Sat Nov 11, 2006 11:14 pm
Re: small rybka source code released by author to public
Honestly...kaustubh wrote: here's white knight captures
(omitted)
Cheers, Mauro
-
- Posts: 2250
- Joined: Wed Mar 08, 2006 8:47 pm
- Location: Hattingen, Germany
Re: small rybka source code released by author to public
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:
Gerd
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;
}
-
- Posts: 620
- Joined: Fri Feb 08, 2008 10:44 am
- Location: Madrid - Spain
Re: small rybka source code released by author to public
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);
}
-
- Posts: 12540
- Joined: Wed Mar 08, 2006 8:57 pm
- Location: Redmond, WA USA
Re: small rybka source code released by author to public
For comparison, here is Strelka's knight captures (they are divided by color so this is only half):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 capturesVas http://rybkaforum.net/cgi-bin/rybkaforu ... =#pid20184Code: 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; } }
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;
}
}
-
- Posts: 4675
- Joined: Mon Mar 13, 2006 7:43 pm
Re: small rybka source code released by author to public
Symbolic's knight capturing code:
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.
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;
-
- Posts: 67
- Joined: Mon Aug 06, 2007 4:42 pm
- Location: London, England
Re: small rybka source code released by author to public
Knight capture code in Atlanchess.
Moves are pushed onto the stack and retrieved at the end of the function.
Grant
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
Re: small rybka source code released by author to public
This was already posted half a year ago:
http://www.talkchess.com/forum/viewtopi ... ite+knight
Not much new.
http://www.talkchess.com/forum/viewtopi ... ite+knight
Not much new.