diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..1dfdcba
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,11 @@
+{
+ "configurations": [
+ {
+ "type": "java",
+ "name": "CodeLens (Launch) - problem12",
+ "request": "launch",
+ "mainClass": "problem12",
+ "projectName": "12"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/uil/october-2013/12/.idea/workspace.xml b/uil/october-2013/12/.idea/workspace.xml
new file mode 100644
index 0000000..01a6175
--- /dev/null
+++ b/uil/october-2013/12/.idea/workspace.xml
@@ -0,0 +1,235 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1568926083487
+
+
+ 1568926083487
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 11
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/uil/october-2013/12/bin/CheckerBoard.class b/uil/october-2013/12/bin/CheckerBoard.class
index e3874c7..73a1d91 100644
Binary files a/uil/october-2013/12/bin/CheckerBoard.class and b/uil/october-2013/12/bin/CheckerBoard.class differ
diff --git a/uil/october-2013/12/bin/Point.class b/uil/october-2013/12/bin/Point.class
index cb97d49..b8be3eb 100644
Binary files a/uil/october-2013/12/bin/Point.class and b/uil/october-2013/12/bin/Point.class differ
diff --git a/uil/october-2013/12/bin/problem12.class b/uil/october-2013/12/bin/problem12.class
index 1250e4b..0298c2f 100644
Binary files a/uil/october-2013/12/bin/problem12.class and b/uil/october-2013/12/bin/problem12.class differ
diff --git a/uil/october-2013/12/src/problem12.java b/uil/october-2013/12/src/problem12.java
index 3954ba5..ddb1c71 100644
--- a/uil/october-2013/12/src/problem12.java
+++ b/uil/october-2013/12/src/problem12.java
@@ -5,38 +5,169 @@ import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
+import java.util.Collection;
+import java.util.Collections;
+// Point representing and (X, Y) coordinate
class Point {
- int x;
- int y;
+ String type;
+ int x, y;
+
+ // Untyped Point Constructor
Point(int x, int y) {
this.x = x;
this.y = y;
}
- void merge(Point other) {
+ // Typed Point Constructor
+ Point(int x, int y, String type) {
+ this.x = x;
+ this.y = y;
+ this.type = type.equals(" ") ? "" : type;
+ }
+
+ // Returns a point which is the translated end-point based on the other point (offset).
+ Point merge(Point other) {
+ return new Point(this.x + other.x, this.y + other.y);
+ }
+
+ void offset(Point other) {
this.x += other.x;
this.y += other.y;
}
- void merge(int x, int y) {
- this.x += x;
- this.y += y;
+ // Point string representation
+ public String toString() {
+ return String.format(
+ "Point(\"%s\", %d, %d)",
+ (this.type.equals("") ? "?" : this.type),
+ this.x,
+ this.y
+ );
+ }
+
+ public boolean isEmpty() {
+ return this.type == "";
+ }
+
+ // equals() method for testing equality of two Point() objects
+ // positional untyped equality test, see fullEquals()
+ public boolean equals(Point other) {
+ return this.x == other.x && this.y == other.y;
+ }
+
+ // tests equality of x, y and type
+ public boolean fullEquals(Point other) {
+ return this.equals(other) && this.type == other.type;
+ }
+
+ // Returns whether a point could be found in a collection
+ public boolean collectionContains(Collection collection) {
+ for(Point other : collection) {
+ if(this.x == other.x && this.y == other.y) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // Class method that searches a List
+ // Returns -1 if item not found in list
+ public int findPoint(List list) {
+ for(Point other : list) {
+ if(this.x == other.x && this.y == other.y)
+ return list.indexOf(other);
+ }
+ return -1;
+ }
+
+ public static List asList(int[][] primitivePoints) {
+ List points = new ArrayList();
+ for(int x = 0; x < primitivePoints.length; x++) {
+ for(int y = 0; y < primitivePoints[x].length; y++) {
+ points.add(new Point(x, y));
+ }
+ }
+ return points;
}
}
+// Represents a checkers checkerboard
class CheckerBoard {
- List offsets = Arrays.asList(new Point[]{Point(1, 1), Point(-1, -1), Point(-1, 1), Point(1, -1)});
+ // Offsets
+ List offsets = Point.asList(new int[][]{{1, 1}, {-1, -1}, {-1, 1}, {1, -1}});
+ Point[][] matrix;
+ // Team Constants, Team1 is default team.
+ String team1 = "R";
+ String team2 = "B";
CheckerBoard(String[][] matrix) {
-
+ // Build the point matrix
+ this.matrix = new Point[8][8];
+ for(int x = 0; x < matrix.length; x++) {
+ for(int y = 0; y < matrix[x].length; y++) {
+ this.matrix[x][y] = new Point(x, y, matrix[x][y]);
+ }
+ }
}
- List getPossible(int x, int y) {
- return getPossible(x, y, new ArrayList());
+ public static boolean inBounds(Point point) {return CheckerBoard.inBounds(point.x, point.y);}
+ public static boolean inBounds(int x, int y) {return x >= 0 && y >= 0 && x < 8 && y < 8;}
+ Point getPoint(Point point) {return this.matrix[point.x][point.y];}
+ String getType(Point point) {return this.matrix[point.x][point.y].type;}
+ boolean isReverse(Point first, Point second) {return first.type == team1 ? second.type == team2 : (first.type == team2 ? second.type == team1 : false);}
+
+ // Just returns all Points with type designated
+ List getCheckers(String type) {
+ List found = new ArrayList();
+ for(int x = 0; x < this.matrix.length; x++) {
+ for(int y = 0; y < this.matrix[x].length; y++) {
+ if(this.matrix[x][y].type.equals(type))
+ found.add(this.matrix[x][y]);
+ }
+ }
+ return found;
}
- List getPossible(int x, int y, List blacklist) {}
+ int getMaxJumps(Point point) {return getMaxJumps(point, 0, Arrays.asList(point));}
+ int getMaxJumps(Point point, int score, List previous) {
+ List offsetScores = Arrays.asList(0);
+ for(Point offset : this.offsets) {
+ Point newPoint = point.merge(offset);
+ // Ensure new point is in matrix bounds
+ if(CheckerBoard.inBounds(newPoint)) {
+ // Ensure new point is of reverse type
+ if(this.isReverse(newPoint, this.getPoint(newPoint))) {
+ newPoint = point.merge(offset);
+ // Ensure second new point is inBounds & Empty
+ if(CheckerBoard.inBounds(newPoint)) {
+ if(this.getPoint(newPoint).isEmpty()) {
+ // add new point to blacklist, ensuring we don't get a infinite recursive nightmare
+ previous.add(newPoint);
+ // will return at least 1
+ offsetScores.add(getMaxJumps(newPoint, score + 1, previous));
+ }
+ }
+ }
+ }
+ }
+ return Collections.max(offsetScores);
+ }
+
+ // Scanning methods for best jumps
+ String scan() {return this.scan(this.team1);} // default to Red checkers
+ String scan(String team) {
+ List entries = getCheckers(team);
+ out.println(entries);
+ List jumps = new ArrayList();
+ // Scan each entry point for jumps
+ for(Point entry : entries) {
+ jumps.add(getMaxJumps(entry));
+ }
+ // Return the best jump
+ out.println(jumps);
+ return Integer.toString(Collections.max(jumps));
+ }
}
class problem12 {
@@ -54,8 +185,10 @@ class problem12 {
for(int y = 0; y < 8; y++)
rawMatrix[x][y] = line.substring(y, y+1);
}
-
- out.println(Arrays.deepToString(rawMatrix));
+
+ for(String[] x : rawMatrix)
+ out.println(Arrays.toString(x));
+
CheckerBoard cb = new CheckerBoard(rawMatrix);
out.println(cb.scan());
}
diff --git a/uil/october-2013/3/java/.idea/workspace.xml b/uil/october-2013/3/java/.idea/workspace.xml
index 68b0d1c..c830dee 100644
--- a/uil/october-2013/3/java/.idea/workspace.xml
+++ b/uil/october-2013/3/java/.idea/workspace.xml
@@ -44,6 +44,7 @@
+
@@ -75,28 +76,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -161,8 +141,8 @@
-
-
+
+
@@ -215,7 +195,6 @@
-
@@ -227,7 +206,7 @@
-
+