Problem with bitboard knight attack generator

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Problem with bitboard knight attack generator

Post by lucasart »

ZirconiumX wrote:I admit defeat...

Lucas was right.
It's not a defeat: I'm trying to help you, not to beat you :D
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Problem with bitboard knight attack generator

Post by lucasart »

ZirconiumX wrote: Out of interest, if you declare a typedef struct as extern, which order do the keywords go in? (I think typedef extern struct is correct, but I'll ask anyway)
??

typedef defines a new type
extern references a variable that is defined in another compiing unit.

not sure what you mean. Can you give a code example of what you want to do ?
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Problem with bitboard knight attack generator

Post by lucasart »

Ah OK, I understand what you mean with typedef extern. Have a look here, it's all explained:
http://www.allegro.cc/forums/print-thread/588235
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Problem with bitboard knight attack generator

Post by lucasart »

lucasart wrote:Ah OK, I understand what you mean with typedef extern. Have a look here, it's all explained:
http://www.allegro.cc/forums/print-thread/588235
If you're running Linux, you can have a look at the Linux Kernel header files directly:

Code: Select all

lucas@megatron:~$ find /usr/src/linux-headers-3.0.0-14-generic/include/ -iname "*.h" -exec grep "extern struct" {} \;
It seems that the developpers of the Linux Kernel avoid using typedef, as much as possible. So simply "extern struct Board" in dummy.h and "struct Board {...};" in board.h for example. Then instead of defining a Board varialble as Board B, you write struct Board B, which is somewhat more explicit, and good programming practice (according to the developpers of the Linux Kernel at least, but I would tend to agree).
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Problem with bitboard knight attack generator

Post by Sven »

ZirconiumX wrote:Blame the CPW for that:

Code: Select all

U64 kingAttacks(U64 kingSet) {
   U64 attacks = eastOne(kingSet) | westOne(kingSet);
   kingSet    |= attacks;
   attacks    |= nortOne(kingSet) | soutOne(kingSet);
   return attacks;
}
I don't have a nortOne or a SoutOne function, so I subsituted the actual code for it.
However, your substitution code for eastOne() and westOne() is not the same as in CPW. Again, you need to take care of the wraparound. In CPW "eastOne(U64 b)" is defined as "(b & notHFile) << 1" (there is also an equivalent second way) and "westOne()" accordingly.

As to the "rank" vs. "file" error in the context of pawn attacks, that was my fault, I proposed a correction but introduced a sloppy error myself. As you see, I am constantly testing the alertness of the forum :-) Thanks to Lucas for correcting it.

Sven
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Problem with bitboard knight attack generator

Post by Sven »

lucasart wrote:Ah OK, I understand what you mean with typedef extern. Have a look here, it's all explained:
http://www.allegro.cc/forums/print-thread/588235
How about C++, Lucas? ;-)

Code: Select all

struct A &#123;
   ...
&#125;;

...

extern A my_a;
extern A * my_a_ptr;
No need for a "typedef" for structs any longer, "A" from the declaration "struct A" is already the name of the type (since "struct" is a special form of "class" where all members are public).

999:998 for C++ :-)

Sven
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Problem with bitboard knight attack generator

Post by lucasart »

Sven Schüle wrote:
lucasart wrote:Ah OK, I understand what you mean with typedef extern. Have a look here, it's all explained:
http://www.allegro.cc/forums/print-thread/588235
How about C++, Lucas? ;-)

Code: Select all

struct A &#123;
   ...
&#125;;

...

extern A my_a;
extern A * my_a_ptr;
No need for a "typedef" for structs any longer, "A" from the declaration "struct A" is already the name of the type (since "struct" is a special form of "class" where all members are public).

999:998 for C++ :-)

Sven
If I Coul;d have only the good stuff in C++ without all the crap, why not. But post C++98 exceptions are everywhere in the STL and even thrown by language operators...
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Problem with bitboard knight attack generator

Post by Sven »

lucasart wrote:
Sven Schüle wrote:
lucasart wrote:Ah OK, I understand what you mean with typedef extern. Have a look here, it's all explained:
http://www.allegro.cc/forums/print-thread/588235
How about C++, Lucas? ;-)

Code: Select all

struct A &#123;
   ...
&#125;;

...

extern A my_a;
extern A * my_a_ptr;
No need for a "typedef" for structs any longer, "A" from the declaration "struct A" is already the name of the type (since "struct" is a special form of "class" where all members are public).

999:998 for C++ :-)

Sven
If I Coul;d have only the good stuff in C++ without all the crap, why not. But post C++98 exceptions are everywhere in the STL and even thrown by language operators...
You can use C++ without using any single line of STL. All my chess programs were written in C++ but there was never STL in it. Actually you don't need STL for chess programming.

In other areas of software development things are probably different. But I promised not to try converting you :-)

Sven

EDIT: Sorry to Matthew for hijacking your thread, I think I'll stop now.
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Problem with bitboard knight attack generator

Post by lucasart »

Sven Schüle wrote:
lucasart wrote:
Sven Schüle wrote:
lucasart wrote:Ah OK, I understand what you mean with typedef extern. Have a look here, it's all explained:
http://www.allegro.cc/forums/print-thread/588235
How about C++, Lucas? ;-)

Code: Select all

struct A &#123;
   ...
&#125;;

...

extern A my_a;
extern A * my_a_ptr;
No need for a "typedef" for structs any longer, "A" from the declaration "struct A" is already the name of the type (since "struct" is a special form of "class" where all members are public).

999:998 for C++ :-)

Sven
If I Coul;d have only the good stuff in C++ without all the crap, why not. But post C++98 exceptions are everywhere in the STL and even thrown by language operators...
You can use C++ without using any single line of STL. All my chess programs were written in C++ but there was never STL in it. Actually you don't need STL for chess programming.

In other areas of software development things are probably different. But I promised not to try converting you :-)

Sven

EDIT: Sorry to Matthew for hijacking your thread, I think I'll stop now.
But if you don't use STL in your chess program, why do you use C++ anyway ? Is it just because of this syntactic sugar (classes and the like can be written in plain C very well)
Ron Murawski
Posts: 397
Joined: Sun Oct 29, 2006 4:38 am
Location: Schenectady, NY

Re: Problem with bitboard knight attack generator

Post by Ron Murawski »

@Lucas,

You can remain in pure C and use STL-like libraries

C Containers Library
http://code.google.com/p/ccl/wiki/PageName
BTW, this library is being proposed to be added to the next-generation C standard library.

Look at section 6 of the pdf. It will show some typical library usage. No syntactic sugar necessary!

Ron