Problem with bitboard knight attack generator

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Volker Annuss
Posts: 180
Joined: Mon Sep 03, 2007 9:15 am

Re: Problem with bitboard knight attack generator

Post by Volker Annuss »

ZirconiumX wrote: How do I detect a space - as the compiler will warn about ' ' as being empty.
Use

Code: Select all

 ' '
instead of

Code: Select all

''
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Problem with bitboard knight attack generator

Post by mcostalba »

Dave_N wrote:Here is how I handled the fen
Not bad, but C++ is more powerful ;-)

Code: Select all

  const string PieceToChar(".PNBRQK  pnbrqk  ");
  std::istringstream fen(fenStr);
  Square sq = SQ_A8;
  char token;

  while ((fen >> token) && !isspace(token))
  {
      if (token == '/')
          sq -= Square(16); // Jump back of 2 rows

      else if (isdigit(token))
          sq += Square(token - '0'); // Skip the given number of files

      else if ((p = PieceToChar.find(token)) != string::npos)
      {
          put_piece(Piece(p), sq);
          sq++;
      }
  }
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 »

mcostalba wrote:
Dave_N wrote:Here is how I handled the fen
Not bad, but C++ is more powerful ;-)

Code: Select all

  const string PieceToChar(".PNBRQK  pnbrqk  ");
  std::istringstream fen(fenStr);
  Square sq = SQ_A8;
  char token;

  while ((fen >> token) && !isspace(token))
  {
      if (token == '/')
          sq -= Square(16); // Jump back of 2 rows

      else if (isdigit(token))
          sq += Square(token - '0'); // Skip the given number of files

      else if ((p = PieceToChar.find(token)) != string::npos)
      {
          put_piece(Piece(p), sq);
          sq++;
      }
  }
Nice, by no doubt. But why not this:

Code: Select all

const string PieceToChar("PNBRQKpnbrqk");
i.e. what is the purpose of the dot and the spaces in your version of PieceToChar? Just curious (it seems to have no effect, apart from allowing a useless '.' in the FEN string) ...

Also, error handling is not included (which is another topic).

Sven
Last edited by Sven on Tue Dec 27, 2011 7:06 pm, edited 1 time in total.
Dave_N
Posts: 153
Joined: Fri Sep 30, 2011 7:48 am

Re: Problem with bitboard knight attack generator

Post by Dave_N »

mcostalba wrote:
Dave_N wrote:Here is how I handled the fen
Not bad, but C++ is more powerful ;-)

Code: Select all

  const string PieceToChar(".PNBRQK  pnbrqk  ");
  std::istringstream fen(fenStr);
  Square sq = SQ_A8;
  char token;

  while ((fen >> token) && !isspace(token))
  {
      if (token == '/')
          sq -= Square(16); // Jump back of 2 rows

      else if (isdigit(token))
          sq += Square(token - '0'); // Skip the given number of files

      else if ((p = PieceToChar.find(token)) != string::npos)
      {
          put_piece(Piece(p), sq);
          sq++;
      }
  }
I did use C++, the vecFen is a std::vector however the complete error checking code still needs to be implemented ... including .pgn file loading. My style sometimes seems to be very labour saving from the implementation perspective (good for rapid development) however in cases like this I have to go back to redo part of my project ... I think I am at pre-beta stage for release 1.
Dave_N
Posts: 153
Joined: Fri Sep 30, 2011 7:48 am

Re: Problem with bitboard knight attack generator

Post by Dave_N »

I was just thinking it would be interesting to use "try" and "catch" for unsafe functions to find errors, making the job easier.
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 »

Dave_N wrote:I was just thinking it would be interesting to use "try" and "catch" for unsafe functions to find errors, making the job easier.
Enabling exception handling might make a chess engine a tiny bit slower. It might be worth testing it again. In my old engine Surprise I had actually enabled EH for a while, in KnockOut I disabled it from the beginning, and I think that it made a small difference at least for KnockOut.

Enabling EH only for selected modules can be dangerous, you must be very sure that you never miss to handle an exception to avoid that it gets passed to a higher-level component which has EH disabled, possibly causing your program to abort. That's why I would either do completely with or completely without EH.

Sven
Dave_N
Posts: 153
Joined: Fri Sep 30, 2011 7:48 am

Re: Problem with bitboard knight attack generator

Post by Dave_N »

actually I am in a stage of the first version of my GUI and the overhead for parsing and handling a PV has to be 100ms (assuming a core is devoted to the GUI and system idle processes) and thats the minimum time interval I have supported for the clock atm. So some FEN's are generated and the board is set sometimes while an engine is running and I want to keep that part of the code fairly optimal, so perhaps a multi-layered approach to FEN strings works well
Dave_N
Posts: 153
Joined: Fri Sep 30, 2011 7:48 am

Re: Problem with bitboard knight attack generator

Post by Dave_N »

actually I am in a stage of the first version of my GUI and the overhead for parsing and handling a PV has to be 100ms (assuming a core is devoted to the GUI and system idle processes) and thats the minimum time interval I have supported for the clock atm. So some FEN's are generated and the board is set sometimes while an engine is running and I want to keep that part of the code fairly optimal, so perhaps a multi-layered approach to FEN strings works well
mcostalba
Posts: 2684
Joined: Sat Jun 14, 2008 9:17 pm

Re: Problem with bitboard knight attack generator

Post by mcostalba »

Sven Schüle wrote: Nice, by no doubt. But why not this:

Code: Select all

const string PieceToChar("PNBRQKpnbrqk");
i.e. what is the purpose of the dot and the spaces in your version of PieceToChar?
Because PieceToChar must map enum Piece correctly, namely white pawn starts from 1. Instead the dot is there because the same PieceToChar string is used also in print(), and the dot corresponds to a dark square.
Sven Schüle wrote:
Also, error handling is not included (which is another topic).
Yes, a topic we have already discussed at length ;-)
Dave_N
Posts: 153
Joined: Fri Sep 30, 2011 7:48 am

Re: Problem with bitboard knight attack generator

Post by Dave_N »

in fact my gui works well in the situation of duel core engines on a duel core machine and the overhead from parsing the uci/winboard output isn't a problem atm. I am trying to keep the realtime use of setBoard() to a minimum anyway :/