Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1.         private void generateTree(Tree t, int layer, Chip first) {
  2.                 List connections = connectedChips(( Chip ) (t.getDatum()));
  3.                 ListNode ptr;
  4.                 Chip c;
  5.  
  6.                 /**** DEBUGGING ****/
  7.                 int i = layer;
  8.                 while (i-- > 0)
  9.                         System.out.print("-");
  10.                 ((Chip)t.getDatum()).printChip();
  11.  
  12.                 try {
  13.                         /* go through each possible connection */
  14.                         for (ptr = connections.front(); ptr.isValidNode(); ptr = ptr.next()) {
  15.                                 c = (Chip)ptr.item();
  16.                                 /* add the chip to tree if it isn't in it already */
  17.                                 if (inTree(t, c) || straightLine(t, c) || inWrongZone(first, c))
  18.                                         continue;
  19.                                 t.addChild(c);
  20.                         }
  21.                         if (t.getChildren().isEmpty())
  22.                                 return;
  23.                         /* for each new child, call this recursively */
  24.                         for (ptr = t.getChildren().front(); ptr.isValidNode(); ptr = ptr.next()) {
  25.                                 generateTree((Tree)ptr.item(), layer + 1, first);
  26.                         }
  27.                 }
  28.                 catch (InvalidNodeException e) {
  29.                 }
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement