Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
My first ever fully self-designed program was a CLI chess game in C++, it used a char[64]. Considering that the volume of data and the cost of the fundamental operations is tiny, I'd do the same today.
-
In validating a step on a chessboard, branching and cache locality will be the bottlenecks.
-
And if extreme optimization is not a goal, a char[64] also has the benefit of being so incredibly obvious to use that it's actually difficult to find an abstraction that's easier.
-
I'd love that in an interview. At the end, I'd challenge you to blitz it out against my chess engine. ^^
-
@lorentz Well, 10x12 mailbox is actually easier once you get around to move generation because you can skip all the board guard code. With bitboards, even sliders get easy, but at the expense of some pretty opaque magic constants stuff.
-
@lorentz 10x12 means your actual board is 10 files wide and 12 ranks high, but you only use the middle 8x8 for the actual pieces. The other squares gets set e.g. to a negative piece ID, where 0 is a free square. Now when you generate moves, including knights, you don't need to constantly check whether you leave the 8x8 board - checking for >= 0 is enough.
Bitboards is using a single 64 bit word for all squares occupied by white pawns, another 64 bit word for all squares occupied by white knights, and so on. That way, you don't need to loop through stuff, you use bitwise logic, shifts, and masks. Makes sense on architectures that support native 64 bit operations. -
@lorentz didn't you have to limit the amount of steps it thinks forward? I was once working on a chess game too but realized that it would become very heavy and quitted on it. The UTF8 chess pawns look so beautiful in console btw! Badass
-
@retoor No I mean a chessboard where you can specify moves and they would be executed. The moves were given as a pair of source and target coordinates too, I didn't even interpret standard move notations.
I was programming for about a month at this point. -
Borland Pascal came with a chess engine as one of OOP samples. The engine wasn't particularly powerful, but that wasn't the goal...
-
Tonnoman6221y@retoor if you mean in terms of making a chess engine, yes it's standard to have some sort of depth parameter for denominating how many moves the engine will calculate for
Related Rants
Are you familiar with chess? What classes/objects and methods/functions would you use to implement the game of chess? Who knows if checkmate is reached? What about timed games?
It always leads to an interesting discussion and you can easily throw out prodding questions if they get stuck. I've never had anybody give me the exact same answer, and it's been complimented post-interview a handful of times.
rant
wk369