Newbie to chess programming: should I go for bitboards?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Aleks Peshkov
Posts: 892
Joined: Sun Nov 19, 2006 9:16 pm
Location: Russia

Re: Newbie to chess programming: should I go for bitboards?

Post by Aleks Peshkov »

Code: Select all

void Board::setPieces(const unsigned short state[]) {
   //set pieces in separate arrays for every piece
   for&#40;short i = 0; i < 64; ++i&#41; &#123;
      if&#40;state&#91;i&#93; == BLANK&#41; &#123; //Blank square
         continue; //Do nothing
      &#125;
      else if&#40;state&#91;i&#93; == WPAWN&#41; &#123;
         Board&#58;&#58;WP&#91;i&#93; = WPAWN;
      &#125;
...
      //Copy state to allBoard&#58;
      for &#40;short n = 0; i < 64; i++) &#123;
         Board&#58;&#58;allBoard&#91;i&#93; = state&#91;i&#93;;
      &#125;

   &#125;
&#125; 
Sorry, it is impossible to create any complex program with that kind of code.
User avatar
vittyvirus
Posts: 646
Joined: Wed Jun 18, 2014 2:30 pm
Full name: Fahad Syed

Re: Newbie to chess programming: should I go for bitboards?

Post by vittyvirus »

Aleks Peshkov wrote:

Code: Select all

void Board&#58;&#58;setPieces&#40;const unsigned short state&#91;&#93;) &#123;
   //set pieces in separate arrays for every piece
   for&#40;short i = 0; i < 64; ++i&#41; &#123;
      if&#40;state&#91;i&#93; == BLANK&#41; &#123; //Blank square
         continue; //Do nothing
      &#125;
      else if&#40;state&#91;i&#93; == WPAWN&#41; &#123;
         Board&#58;&#58;WP&#91;i&#93; = WPAWN;
      &#125;
...
      //Copy state to allBoard&#58;
      for &#40;short n = 0; i < 64; i++) &#123;
         Board&#58;&#58;allBoard&#91;i&#93; = state&#91;i&#93;;
      &#125;

   &#125;
&#125; 
Sorry, it is impossible to create any complex program with that kind of code.
So what? Complicated doesn't mean the best? Or does it..?
Angrim
Posts: 97
Joined: Mon Jun 25, 2012 10:16 pm
Location: Forks, WA
Full name: Ben Nye

Re: Newbie to chess programming: should I go for bitboards?

Post by Angrim »

chess programs are unavoidably complex. Which makes tidy and careful programming more important for them than for simpler programs where there is more room for errors.
User avatar
vittyvirus
Posts: 646
Joined: Wed Jun 18, 2014 2:30 pm
Full name: Fahad Syed

Re: Newbie to chess programming: should I go for bitboards?

Post by vittyvirus »

Angrim wrote:chess programs are unavoidably complex. Which makes tidy and careful programming more important for them than for simpler programs where there is more room for errors.
This code was just supposed to be a starting point, you know..