9
atlas1515
317d

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.

Comments
  • 6
    Honestly a great question

    Building a culture of chess players #based
  • 5
    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.
  • 1
    In validating a step on a chessboard, branching and cache locality will be the bottlenecks.
  • 4
    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.
  • 1
    I'd love that in an interview. At the end, I'd challenge you to blitz it out against my chess engine. ^^
  • 0
    @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.
  • 1
    @Fast-Nop I don't understand most words in that
  • 5
    @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.
  • 1
    Game, Player, Board, Figure
  • 0
    @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
  • 1
    @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.
  • 2
    Borland Pascal came with a chess engine as one of OOP samples. The engine wasn't particularly powerful, but that wasn't the goal...
  • 0
    @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
Add Comment