Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in Othello code (all moves are considered legal) #197

Open
Markvy opened this issue May 29, 2020 · 0 comments
Open

Bug in Othello code (all moves are considered legal) #197

Markvy opened this issue May 29, 2020 · 0 comments

Comments

@Markvy
Copy link

Markvy commented May 29, 2020

On this line in the Othello code:

https://github.com/careercup/CtCI-6th-Edition/blob/master/Java/Ch%2007.%20Object-Oriented%20Design/Q7_08_Othello/Board.java#L40

We have the some code that looks a bit like this (condensed slightly to fit in this tiny edit box):

int flipped = 0;
for (int result : results)
	if (result > 0) flipped += result;
if (flipped < 0) return false;

It seems to me that there is no way the "return false" can be reached here, because the sum of positive numbers is never negative (assuming no integer overflow).

Granted, these kind of details aren't really the point of Chapter 7, which is more "big picture stuff" it's still nice if demo code actually works. (The code that centers the initial 4 pieces on the board is also wrong, but that's relatively cosmetic.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant