From 567e8aeff3b9a1ad92757c07568d1ba1975f3340 Mon Sep 17 00:00:00 2001 From: brucephillips Date: Sat, 31 Jul 2021 07:36:08 -0500 Subject: [PATCH] Changes to improve output shown --- CCSPiJ/src/chapter1/CompressedGene.java | 1 + CCSPiJ/src/chapter1/Hanoi.java | 3 ++- CCSPiJ/src/chapter2/Maze.java | 8 ++++++++ CCSPiJ/src/chapter4/Graph.java | 1 + CCSPiJ/src/chapter4/UnweightedGraph.java | 6 +++--- 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CCSPiJ/src/chapter1/CompressedGene.java b/CCSPiJ/src/chapter1/CompressedGene.java index 5c51ceb..a77cfae 100644 --- a/CCSPiJ/src/chapter1/CompressedGene.java +++ b/CCSPiJ/src/chapter1/CompressedGene.java @@ -69,6 +69,7 @@ public String decompress() { final int firstBit = (bitSet.get(i) ? 1 : 0); final int secondBit = (bitSet.get(i + 1) ? 1 : 0); final int lastBits = firstBit << 1 | secondBit; + System.out.println("lastBits = " + lastBits); switch (lastBits) { case 0b00: // 00 is 'A' builder.append('A'); diff --git a/CCSPiJ/src/chapter1/Hanoi.java b/CCSPiJ/src/chapter1/Hanoi.java index 5fb8c6d..5ee60f5 100644 --- a/CCSPiJ/src/chapter1/Hanoi.java +++ b/CCSPiJ/src/chapter1/Hanoi.java @@ -47,10 +47,11 @@ public void solve() { public static void main(String[] args) { Hanoi hanoi = new Hanoi(3); + System.out.println("Tower A at start: " + hanoi.towerA); hanoi.solve(); System.out.println(hanoi.towerA); System.out.println(hanoi.towerB); - System.out.println(hanoi.towerC); + System.out.printf("Tower C at end %s%n", hanoi.towerC); } } diff --git a/CCSPiJ/src/chapter2/Maze.java b/CCSPiJ/src/chapter2/Maze.java index 1562a3c..389c5c3 100644 --- a/CCSPiJ/src/chapter2/Maze.java +++ b/CCSPiJ/src/chapter2/Maze.java @@ -185,7 +185,9 @@ public double manhattanDistance(MazeLocation ml) { public static void main(String[] args) { Maze m = new Maze(); + System.out.println("Maze"); System.out.println(m); + System.out.println("\n\n"); Node solution1 = GenericSearch.dfs(m.start, m::goalTest, m::successors); if (solution1 == null) { @@ -193,7 +195,9 @@ public static void main(String[] args) { } else { List path1 = GenericSearch.nodeToPath(solution1); m.mark(path1); + System.out.println("Maze solved using depth first search"); System.out.println(m); + System.out.println("\n\n"); m.clear(path1); } @@ -203,7 +207,9 @@ public static void main(String[] args) { } else { List path2 = GenericSearch.nodeToPath(solution2); m.mark(path2); + System.out.println("Maze solved using breadth first search"); System.out.println(m); + System.out.println("\n\n"); m.clear(path2); } @@ -213,7 +219,9 @@ public static void main(String[] args) { } else { List path3 = GenericSearch.nodeToPath(solution3); m.mark(path3); + System.out.println("Maze solved using a * search"); System.out.println(m); + System.out.println("\n\n"); m.clear(path3); } } diff --git a/CCSPiJ/src/chapter4/Graph.java b/CCSPiJ/src/chapter4/Graph.java index 9a05343..8a5d377 100644 --- a/CCSPiJ/src/chapter4/Graph.java +++ b/CCSPiJ/src/chapter4/Graph.java @@ -74,6 +74,7 @@ public List neighborsOf(int index) { // Look up a vertice's index and find its neighbors (convenience method) public List neighborsOf(V vertex) { + System.out.printf("Neighbors of %s are %s \n\n", vertex, neighborsOf(indexOf(vertex))); return neighborsOf(indexOf(vertex)); } diff --git a/CCSPiJ/src/chapter4/UnweightedGraph.java b/CCSPiJ/src/chapter4/UnweightedGraph.java index 7fc6cf3..a869d62 100644 --- a/CCSPiJ/src/chapter4/UnweightedGraph.java +++ b/CCSPiJ/src/chapter4/UnweightedGraph.java @@ -79,14 +79,14 @@ public static void main(String[] args) { cityGraph.addEdge("Philadelphia", "Washington"); System.out.println(cityGraph.toString()); - Node bfsResult = GenericSearch.bfs("Boston", - v -> v.equals("Miami"), + Node bfsResult = GenericSearch.bfs("Chicago", + v -> v.equals("Philadelphia"), cityGraph::neighborsOf); if (bfsResult == null) { System.out.println("No solution found using breadth-first search!"); } else { List path = GenericSearch.nodeToPath(bfsResult); - System.out.println("Path from Boston to Miami:"); + System.out.println("Path from Chicago to Philadelphia:"); System.out.println(path); } }