I’m a bit concerned with the bitboard representation. What happens when a pawn takes another piece? Edit: The above is what I would say if someone presented this approach in an interview.
I'd like to see the rest of this implemented. What does this global functions look like? Are they swamped with if statements "I hope not" or are you storing some game logic in structs to replace polymorphism. I don't disagree with with the compact pawn struct as a starting point but to further prove your point I would love to see the rest / pseudo code.
Is abstraction overrated in programming? Chess, interviews and OOP
101–110 of 149 posts
Re: Is abstraction overrated in programming? Chess, interviews and OOP
#102Earlier quoted context omitted.
Oh please. As if the interviewer's next question wouldn't be "make it faster/more efficient" anyway. The interviewer is the problem here because he wants to build a chess game in an extremely stupid way using OOP for no other reason than to use OOP. I'd say most applications of OOP fail in similar ways in real life, creating monsters of complexity where simplicity could have existed. The author should consider himsel…
The interviewer gave the OP a simple question that could be answered within a short time to gauge how well they understood OO design, and OP specifically implemented it in a way to frustrate them. So again, whose the idiot? If OP wanted to crush the question, they could quickly answer it by saying this is how you could implement using classes and inheritance, now let me explain why OO is a poor solution for this spec…
Re: Is abstraction overrated in programming? Chess, interviews and OOP
#103In a modern, state of the art chess program that uses alpha-beta with a branching factor b and depth d, you will have at most d boards allocated, or even 1 board allocated. Neither of those figures approach b^d. That makes board size largely irrelevant, except for the amount of memory copying needed, which for a d-board approach would be b^d copies (a single board approach would only mutate that board).
EDIT: One major issue I just noticed with the article is that the two differing implementations are not apples-to-apples equivalent. One uses bitboards, based around manipulation of bits, and another one is akin to representing the board with an array.
Re: Is abstraction overrated in programming? Chess, interviews and OOP
#104Earlier quoted context omitted.
Or maybe the OP understood that everyone who has ever implemented a chessboard are also building chess engines where memory efficiency and speed actually matter a lot. It's the interviewers who are ignorant here, they took a real problem and translated it badly into a toy problem. Then they failed to realize what they did.
They could be building an online social game site, or implementing a UI but using an existing AI. In which case the OO version will be easier to code, understand, render, and render history in chess notation. The only thing his methods is good for is implementing an AI and serialization.
This is complicated by the two approaches not being apples-to-apples, however.
Re: Is abstraction overrated in programming? Chess, interviews and OOP
#105Earlier quoted context omitted.
A variant of the flyweight pattern using contextual identity. All board representation remains a bunch of uint64_t, all messages sent to boards result in bit manipulation (i.e. not massive duplication of objects), and you instantiate the piece objects once per game. There's simply no need for "instantiate all the things" approach assumed in the Quora answer. That is OO at its most naive. OOP is messaging, encapsulati…
I have the sinking feeling that your first paragraph is probably what the original author had in mind all along… He advocated for a representation of the entire board, and that's apparently what you would do as well. I originally though you were advocating for a representation of each piece on the board, were "messages" were "sent" to individual pieces, not the entire board. I was curious about how you'd map that int…
Re: Is abstraction overrated in programming? Chess, interviews and OOP
#106Earlier quoted context omitted.
Competent entity systems are OOP, entity is synonymous with object (bring out some other object-like system, and a theasurus is usually used to find another word for object). You just don’t use classes, but there have been plenty of classless OOP systems since the Treaty of Orlando. Anything with a nounish tint will lean more OO than functional (of course, taxonomies are never perfect). Objects have always been about…
First, let us agree on what OOP might even mean. http://loup-vaillant.fr/articles/taboo-oo http://loup-vaillant.fr/articles/deaths-of-oop
http://web.media.mit.edu/~lieber/Publications/Treaty-of-Orla...
It is scary that the broad definition given in the 80s has been supplanted by a narrow “java or C++” definition today. If that what you mean by it, then no we aren’t talking about the same thing. I’ve built plenty of OO systems that don’t correspond to that definition at all, and at any rate, were still considered OO systems by the OO community (at least by the people who attend ECOOP and OOPSLA).
Re: Is abstraction overrated in programming? Chess, interviews and OOP
#107The point is to allow programming things like the AI algorithm without caring at all about if the board is represented with a hash map, nested arrays, or a bitboard. In all cases, all the AI cares about is move generation, not internal representation.
Abstraction does not hinder ideas like the bitboard, it enables them. Both the interviewer and the interviewee are missing the point.
Re: Is abstraction overrated in programming? Chess, interviews and OOP
#108Is this for real? The solution he proposes is specific to Chess ! I mean, does this guy really think the company cares about efficiently representing chess game states?? Obviously, obviously, OBVIOUSLY, the Chess aspects of this question are irrelevant. What they are trying to find out if how well you will work on their actual codebase, which is presumably not comprised of global functions operating on bitfields
The guy is openly arguing with an interviewer after taking a question too literally. I suspect my interview impressions would've included "candidate may be on the spectrum". However, this entire thesis is founded on a false dilemma, because you can write an OO domain model with a compact representation.
Re: Is abstraction overrated in programming? Chess, interviews and OOP
#109I don't know why he wants to waste so much space with twelve unsigned longs when he can do it in eight (one for each piece and two more masks for color).
I don’t know why would you both want to waste so much space? A cell is either empty, or contains one of the 12 figures. To store 13 values, you need 4 bits per cell i.e. 256 bits for the complete board. That’s 4 unsigned longs.
Re: Is abstraction overrated in programming? Chess, interviews and OOP
#110Earlier quoted context omitted.
composition over inheritance https://en.wikipedia.org/wiki/Composition_over_inheritance
No, my observation has nothing to do with composition vs/ inheritance. It's about defining what a class IS vs/ what a class HAS.
> No, my observation has nothing to do with composition vs/ inheritance.
> It's about defining what a class IS vs/ what a class HAS.
What do you feel is the difference between these two sentences? In other words, why is inheritance vs composition not the same as what a class is vs what a class has?