Stockfish: tbprobe.cpp: Line 686

Created on 26 Oct 2019  路  13Comments  路  Source: official-stockfish/Stockfish

int flipSquares = (symmetricBlackToMove || blackStronger) * 070;

For all code octal constant using at one place only. Sure it give only misunderstanding especially with brief look.

Most helpful comment

Octal number writing in code is rare and unexpected, it doesn't make for great readability.

All 13 comments

Indeed, only octal used in whole SF code, used also here
squares[i] ^= 070; // Vertical flip: SQ_A8 -> SQ_A1

Using 56 instead would be just fine too or SQ_A8, as we do in types.h when we define the ~ operator.

constexpr Square operator~(Square s) {
  return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
}

or find a way to use the ~ operator.

@ddugovic nice to see u with emoji but I prefer words. If you want I can send u the corrected code of ur polyglot which is not works on modern systems for a long time.

Ah, that would be appreciated as after much effort I wasn't able to get my polyglot working.

I don't see what's so confusing about bitmask 070 or how alternatives are more readily understood. In my own fork I've used bitmask 0x3F and in hindsight 077 would have been easier to understand (since a chess board has 8 ranks; 0x88 board representation is a standard albeit an unpopular one).

@ddugovic Trust me most programmers used dec or hex (rarely bin)
I certainly understand that you came from pure c and all above for u is "easy-peasy, lemon squeezy"

Sure, most programmers, myself included, use decimal or hexadecimal. And most IDEs used by beginners, upon hovering over the constant, do evaluate it.

The code in question in int flipSquares = (symmetricBlackToMove || blackStronger) * 070;. Perhaps this code could use a comment (or even a ternary operator or an if/else since the reason for multiplication is unclear), but I don't think replacing the constant with SQ_A8 or 56 would clearly indicate a bitmask.

@ddugovic Okey-dockey, i'm probably wrong again?
What I want to say - in my whole life I used octal into network drivers and protocols..
And it is unexpected to meet such code into user-space application.. especially in small quantities..
This is not perceived at all when I read big-big code..
IMHO

Octal number writing in code is rare and unexpected, it doesn't make for great readability.

Why don't we just constexpr, or #define a FLIP_SQUARES = xxx;. This makes all of the code more readable.

Also I wanna say that MISRA C++ against octals too..

https://www.misra.org.uk/MISRACHome/tabid/128/Default.aspx

OK, fair enough and I do like protonspring's suggestion.
MISRA - https://rules.sonarsource.com/c/RSPEC-1314

I used a constexpr and removed the octals in my trivials PR.
https://github.com/official-stockfish/Stockfish/pull/2385

I'm fine with removing the octals!

Octals removed in 384bff4264f199ded8fa28d241ce0e7dc021a97c, closing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Alayan-stk-2 picture Alayan-stk-2  路  5Comments

rayoh123 picture rayoh123  路  5Comments

ZagButNoZig picture ZagButNoZig  路  6Comments

BKSpurgeon picture BKSpurgeon  路  6Comments

Silver-Fang picture Silver-Fang  路  7Comments