Permalink
Browse files

twos and 4s open and closed

  • Loading branch information...
1 parent 13ef917 commit 68840615e1d86ca93fac34a0a0866a9cb18ed097 @dbieber committed Apr 7, 2012
Showing with 35 additions and 5 deletions.
  1. +35 −5 Solution.java
View
40 Solution.java
@@ -32,14 +32,44 @@ public static void main(String args[]) {
for (GraphNode n : b.canBeTakens) {
boolean[][] visited = new boolean[GRID_SIZE][GRID_SIZE];
- visited[n.x][n.y] = true;
- GraphNode next;
- for (GraphNode c : n.children) {
-
+ boolean chainDone = false;
+ boolean closed = false;
+ int chainSize = 1;
+ GraphNode current = n;
+
+ while (!chainDone) {
+ visited[current.x][current.y] = true;
+
+ if (current.children.size() == 0) {
+ chainDone = true;
+ closed = false;
+ break;
+ }
+ if (current.children.size() == 1) {
+ chainDone = true;
+ closed = true;
+ break;
+ }
+ if (current.children.size() > 2) {
+ chainDone = true;
+ closed = false;
+ break;
+ }
+ if (current.children.size() == 2) {
+ GraphNode next = current.children.get(0);
+ if (visited[next.x][next.y])
+ next = current.children.get(1);
+ current = next;
+ }
+
+ if (!current.outside)
+ chainSize++;
}
- //2 open, 4 closed
+ if (! ((closed && chainSize == 4) || (!closed && chainSize == 2))) {
+ //take and be done
+ }
}
}
}

0 comments on commit 6884061

Please sign in to comment.