1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| public class Cell {
final public int col,row,sqr;
private int value;
private Board board;
public Cell(Board board,int r, int c, int v) {
this.board=board;
this.col=c; this.row=r;
this.sqr=(c/board.K)+board.K*(r/board.K);
this.setValue(v);
}
public boolean setNextPossibleValue() {
int currentvalue=this.value;
// unset current value (if any)
this.unsetValue();
// find and set the next value
for(int v=currentvalue+1;v<=board.N;v++) {
if (board.isLocked(this, v)) continue;
this.setValue(v);
return true;
}
return false;
}
public void setValue(int v) {
this.value=v;
board.setLock(this,true);
}
public void unsetValue() {
board.setLock(this,false);
this.value=0;
}
public int getValue() {
return this.value;
}
} |
Partager