UseZirconiumX wrote: How do I detect a space - as the compiler will warn about ' ' as being empty.
Code: Select all
' '
Code: Select all
''
Moderators: hgm, Rebel, chrisw
UseZirconiumX wrote: How do I detect a space - as the compiler will warn about ' ' as being empty.
Code: Select all
' '
Code: Select all
''
Not bad, but C++ is more powerfulDave_N wrote:Here is how I handled the fen
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:mcostalba wrote:Not bad, but C++ is more powerfulDave_N wrote:Here is how I handled the fen
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++; } }
Code: Select all
const string PieceToChar("PNBRQKpnbrqk");
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.mcostalba wrote:Not bad, but C++ is more powerfulDave_N wrote:Here is how I handled the fen
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++; } }
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.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.
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: Nice, by no doubt. But why not this:i.e. what is the purpose of the dot and the spaces in your version of PieceToChar?Code: Select all
const string PieceToChar("PNBRQKpnbrqk");
Yes, a topic we have already discussed at lengthSven Schüle wrote:
Also, error handling is not included (which is another topic).