Skip to content

Commit

Permalink
Count components correctly
Browse files Browse the repository at this point in the history
Fix a bug where if you placed a subcircuit twice, its contents were only
counted once. Going to try not to think about how long this has been broken.
  • Loading branch information
ausbin committed Sep 9, 2023
1 parent 2c3cda9 commit abba52c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ it alongside a grader. The following steps are an example workflow:
...
// version gitVersion()
```
For autograders (consumers) using newer versions of Gradle, you may also
need to comment out the `sourcesJar` and `javadocJar` tasks as well as the
`artifacts {}` and `publishing {}` sections. Isn't software "engineering"
fun?
4. Run `./gradlew jar` in both the cloned copy of this repository and
in the top-level autograder directory, in that order. If you modify
the code in the copy of this repository, you will have to rerun the
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/io/zucchini/circuitsimtester/api/Subcircuit.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public Map<String, Integer> lookupComponentCounts(
Map.Entry::getKey, entry -> entry.getValue().size()));
}

private Map<String, Set<ComponentPeer<?>>> lookupComponentPeers(
private Map<String, List<ComponentPeer<?>>> lookupComponentPeers(
Collection<String> componentNames,
boolean inverse,
boolean recursive) {
Expand All @@ -285,18 +285,19 @@ private Map<String, Set<ComponentPeer<?>>> lookupComponentPeers(
String.join(", ", components)));
}

Map<String, Set<ComponentPeer<?>>> matchingComponents = new HashMap<>();
Map<String, List<ComponentPeer<?>>> matchingComponents = new HashMap<>();
// Run a depth-first search through the simulation DAG starting
// at this subcircuit. (Setting revisit=false makes this a DFS)
walk(recursive, false, (circuitBoard, component) -> {
// at this subcircuit. Setting revisit=true ensures we correctly count the
// components in multiple occurrences of the same subcircuit
walk(recursive, true, (circuitBoard, component) -> {
Pair<String, String> name = componentNameInfo.getPeerCategoryAndName(component);
boolean match = goalCategories.contains(name.getKey()) ||
goalComponents.contains(name.getValue());

if (match ^ inverse) {
matchingComponents.computeIfAbsent(
name.getValue(),
k -> new HashSet<>()).add(component);
k -> new ArrayList<>()).add(component);
}
});

Expand Down

0 comments on commit abba52c

Please sign in to comment.