Author: Dan Newman
Date: 03:01:42 02/13/00
Go up one level in this thread
On February 13, 2000 at 03:07:09, Tom Kerrigan wrote:
>On February 12, 2000 at 20:03:44, Dan Newman wrote:
>
>>In the 0x88 program I do something like this:
>>
>> while( !p->end() ) {
>> int from = p->from();
>> switch( p->type() ) {
>> ....
>> case W_KNIGHT: {
>> int to = from + 33;
>> if( on_board( to) && is_black( to) )
>> (movep++)->add_wn_capture( from, to);
>> to = from + 31;
>> if( on_board( to) && is_black( to) )
>> (movep++)->add_wn_capture( from, to);
>> //and so on, 6 more times...
>> break;
>> }
>> ....
>> }
>> p++;
>> }
>
>Here is some code I wrote to generate moves for *all* pieces. I think it might
>be faster than what you have above.
>
>p = first_piece[side];
>do {
> if (!p->dead) {
> for (i = 0; i < vectors[p->t]; ++i) {
> n = p->sq;
> for (;;) {
> n = unbounds[bounds[n] + vector[p->t][i]];
> if (n == -1)
> break;
> if (board[n]) {
> if (board[n]->c == xside)
> add_move(p->sq, n, 0x40000);
> break;
> }
> add_move(p->sq, n, 0x0);
> if (p->bit & 0x22)
> break;
> }
> }
> }
> p = p->next;
>} while (p);
>
>Some obvious speedups are possible, but you get the idea.
>
>-Tom
It sure is compact. The unbound[ bound[] + vector[][]] thing took me a few
minutes to figure out--and I'm not sure I've got it figured out yet... Do
bound[] and unbound[] map to and from 0x88 coordinates (with the occasional
-1 thrown in for bad coords)?
I guess this code is only the for pieces and not the pawns, since it seems
like it would generate diagonal pawn moves and doesn't have any obvious
promotion code, and ISTR you mentioning separate pawn and piece lists.
I'm still not sure what "if (p->bit & 0x22) break;" is about...
Anyway, it's nice and compact which is to its advantage, but I suspect it's
probably slower than my code which has a lot of the loops unrolled, uses
constant offsets (which tend to become immediate operations), and very few
array lookups. My 0x88 move generator is pretty ugly of course (about 900
LOC with lots of macros to make it smaller)...
Also, I generate captures and promotions entirely separately from non-capture,
non-promo moves, so it'd be hard to compare with a generator that generates
them all together. That is, I'd be at a disadvantage if we were comparing
full move generation rates, and at an advantage if just comparing capture
generation...
I've attempted to write clear, compact chess code several times--to try to
come up with something for pedagogical purposes (like TSCP)--but I always
start fiddling with the code (for performance) and end up with bloaters :).
-Dan.
This page took 0.01 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.