Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void generateTree(Tree t, int layer, Chip first) {
- List connections = connectedChips(( Chip ) (t.getDatum()));
- ListNode ptr;
- Chip c;
- /**** DEBUGGING ****/
- int i = layer;
- while (i-- > 0)
- System.out.print("-");
- ((Chip)t.getDatum()).printChip();
- try {
- /* go through each possible connection */
- for (ptr = connections.front(); ptr.isValidNode(); ptr = ptr.next()) {
- c = (Chip)ptr.item();
- /* add the chip to tree if it isn't in it already */
- if (inTree(t, c) || straightLine(t, c) || inWrongZone(first, c))
- continue;
- t.addChild(c);
- }
- if (t.getChildren().isEmpty())
- return;
- /* for each new child, call this recursively */
- for (ptr = t.getChildren().front(); ptr.isValidNode(); ptr = ptr.next()) {
- generateTree((Tree)ptr.item(), layer + 1, first);
- }
- }
- catch (InvalidNodeException e) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement