Compare commits
3
Commits
124caff620
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c85ccb2eb | ||
|
|
6436ada263 | ||
|
|
c8aa16c246 |
@@ -6,7 +6,7 @@ import org.junit.jupiter.api.BeforeEach;
|
|||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
/*
|
|
||||||
public class ADS4_2_test {
|
public class ADS4_2_test {
|
||||||
HilbertServer hlb;
|
HilbertServer hlb;
|
||||||
Turtle turtle;
|
Turtle turtle;
|
||||||
@@ -97,4 +97,3 @@ public class ADS4_2_test {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
@@ -11,7 +11,7 @@ public class HanoiServer implements CommandExecutor {
|
|||||||
} else if (n > 1) {
|
} else if (n > 1) {
|
||||||
moveDisk(n - 1, from, help, to, result);
|
moveDisk(n - 1, from, help, to, result);
|
||||||
result.append("Lege die oberste Scheibe von Turm " + from + " auf Turm " + to + "\n");
|
result.append("Lege die oberste Scheibe von Turm " + from + " auf Turm " + to + "\n");
|
||||||
moveDisk(n-1, help, to, from, result);
|
moveDisk(n - 1, help, to, from, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package ch.zhaw.ads;
|
||||||
|
|
||||||
|
public class HilbertServer implements CommandExecutor {
|
||||||
|
Turtle turtle;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String execute(String command) {
|
||||||
|
int depth = Integer.parseInt(command);
|
||||||
|
double dist = 0.8 / (Math.pow(2,depth+1)-1);
|
||||||
|
turtle = new Turtle(0.1, 0.1);
|
||||||
|
hilbert(depth, dist, -90);
|
||||||
|
return turtle.getTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hilbert(int depth, double dist, double angle){
|
||||||
|
if(depth < 0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
depth --;
|
||||||
|
turtle.turn(-angle);
|
||||||
|
// draw recursive
|
||||||
|
hilbert(depth, dist, -angle);
|
||||||
|
turtle.move(dist);
|
||||||
|
turtle.turn(angle);
|
||||||
|
// draw recursive
|
||||||
|
hilbert(depth, dist, angle);
|
||||||
|
turtle.move(dist);
|
||||||
|
// draw recursive
|
||||||
|
hilbert(depth, dist, angle);
|
||||||
|
turtle.turn(angle);
|
||||||
|
turtle.move(dist);
|
||||||
|
// draw recursive
|
||||||
|
hilbert(depth, dist, -angle);
|
||||||
|
turtle.turn(-angle);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user