Dear /prog/,
I'm wirting a program for my CS class which solves Hitori puzzles (not unlike sudoku, see http://en.wikipedia.org/wiki/Hitori for example.) Now, it seems like it should be a damn simple program to write in java, but I'm absolutely fucked when it comes to getting part of it to work. My program will get the puzzle down to one of each # per row/column, but I can't for the life of me get a properly working algorthm to ensure that all whitespace is connected. Please 4chan, would anyone be willing to help a brother out, by finding what's wrong with my code? I'll post it if anyone's willing.
Name:
Anonymous2006-09-24 22:53
FAILS for using JAVA
Name:
Anonymous2006-09-24 22:56
>2
Yeah, because, y'know, not like that's the first language my university teaches for it's BCSC degree. OH SHI-
>5
Eat a fucking dick you whiny cunt, that's what I'm trying to do, I just need someone to help me debug this shit. Code forthcoming...
Name:
Anonymous2006-09-25 0:02
Here it is. Expect it to be illegible, and goddamn messy. I just need to know why it goes into a loop when it tries to check for continuity. Everything else omitted for berevity.
Starts here:
public boolean solve(int location){
int row = location / x;
int col= location % x;
//display();
if (location == x * y) //at end of puzzle
return true;
else { //Try to make the location "white"
puzzle[row][col].setWhite(); attempts++;
if ((solve(location+1))&&(checkLocation(row, col))){
return true;}
else{ //Try to make the location "black"
puzzle[row][col].setBlack(); attempts++;
if (solve(location+1)&&(checkLocation(row, col))&&!breaksContinuity(location+1)){
return true;}
else { //This location can not be white or black so set unknown and backtrack
puzzle[row][col].setUnknown();
return false;
}
}
}
}
boolean checkLocation(int row, int col){
int cellValue = puzzle[row][col].cellValue;
int cvOccurances=0;
for(int i=col; i<y; i++){
if((puzzle[row][i].cellValue==cellValue)&&!(puzzle[row][i].isBlack()))
cvOccurances++;
}
if(cvOccurances>1)
return false;
cvOccurances=0;
else if(location-1>=0&&checkContinuity(location-1)){
I don't think it could cause an infinite loop, but the first test of all four of these ifs is wrong anyway; eg assume that location is the first square of the second row, loc-1>=0 holds, but there is no square to the left.
Also it might simplify things if you let checkCont return an int with the number of white squares in its part of the fill tree, instead of the boolean mess and global accumulator you have now.
Name:
Anonymous2006-09-25 5:11
Ok you have a problem in the way checkContinuity recurses - it calls itself in such a way that it doesn't terminate.
The breaksContinuity method calls checkContinuity(0) first of all (when i is 0). Upon reaching this:
Thanks for the assistance boys (no girls on internet n' all), I think I've fixed the problems. That, of course, only brought up more, smaller errors, but I'll be fine with those. Thanks y'all.
Name:
Anonymous2006-09-25 17:24
>>12
You still haven't fixed the bug reported by >>10
Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy