Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
tigerwingxys committed Feb 16, 2020
1 parent b227b13 commit add8b61
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
42 changes: 22 additions & 20 deletions src/signpost/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,20 @@ class Model implements Iterable<Model.Sq> {
for(int w = 0; w <width(); w++ ){
for( int h=0; h<height(); h++){
int sn = solution[w][h];
Sq sq = new Sq(w,h,0,false,0,-1);
_solnNumToPlace[sn] = pl(w,h);
Sq sq ;
if(sn==1||sn==last){
sq = new Sq(w,h,sn,true,0,0);
}else {
sq = new Sq(w,h,0,false,0,-1);
}
_board[w][h] = sq;
allNums.set(sn);
_allSquares.add(sq);
_solnNumToPlace[sn] = pl(w,h);
}
}
solnNumToSq(1).setFixedNum(1);
solnNumToSq(last).setFixedNum(last);
//solnNumToSq(1).setFixedNum(1);
//solnNumToSq(last).setFixedNum(last);
for(int i = 1; i<= last; i ++){
if( !allNums.get(i) ){
throw badArgs("the sequence number"+i+"has not set");
Expand All @@ -148,16 +153,14 @@ class Model implements Iterable<Model.Sq> {
sq._dir = arrowDirection(sq.x,sq.y);
sq._successors = allSuccessors(sq.x,sq.y,sq._dir);
}
for(int i=2; i<=last; i++){
Sq sq=solnNumToSq(i);
sq._predecessors = new PlaceList();
for(int j=1; j<=last; j++){
if( j==i ) continue;
Sq fromSq = solnNumToSq(j);
if( fromSq._dir == dirOf(fromSq.x,fromSq.y,sq.x,sq.y) ){
Place fromPlace = solnNumToPlace(j);
sq._predecessors.add(fromPlace);
for(Sq sq:_allSquares){
if( sq.successors() ==null ) continue;
for(Place target:sq.successors()){
Sq tsq = get(target);
if( tsq.predecessors()==null){
tsq._predecessors = new PlaceList();
}
tsq._predecessors.add(sq.pl);
}
}

Expand Down Expand Up @@ -586,7 +589,7 @@ PlaceList predecessors() {
*/
boolean connectable(Sq s1) {
// FIXME
if(direction() != pl.dirOf(s1.pl)){
if(direction()==0 || direction() != pl.dirOf(s1.pl)){
return false;
}
if(s1.predecessor() != null || successor() != null ){
Expand All @@ -599,14 +602,13 @@ boolean connectable(Sq s1) {
return false;
}
if( this.sequenceNum()==0 && s1.sequenceNum()==0 ){
if( group()>0 || s1.group()>0)
{
if(group() == s1.group())
{
return false;
}
if( _head == s1._head){
return false;
}
}
if( s1.sequenceNum() == 1 || sequenceNum()==width()*height()){
return false;
}
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/signpost/PuzzleGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public Model getPuzzle(int width, int height, boolean allowFreeEnds) {
Model model =
new Model(makePuzzleSolution(width, height, allowFreeEnds));
// FIXME: Remove the "//" on the following two lines.
System.out.println(model);
makeSolutionUnique(model);
model.autoconnect();
return model;
Expand Down Expand Up @@ -142,7 +141,6 @@ static Sq findUniqueSuccessor(Model model, Sq start) {
// FIXME: Fill in to satisfy the comment.
int cnt = 0;
Sq found = null;
cnt = start.successors().size();

for(Place p : start.successors()){
Sq sq = model.get(p);
Expand All @@ -155,6 +153,8 @@ static Sq findUniqueSuccessor(Model model, Sq start) {
if( start.sequenceNum()>0 && start.sequenceNum() == sq.sequenceNum()-1 ){
return sq;
}


}
if( cnt==1 ){
return found;
Expand Down

0 comments on commit add8b61

Please sign in to comment.