From 5536ee62ab8306744b4e56ca9a9c31d3a21b4991 Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 20 Sep 2019 22:17:41 -0500 Subject: [PATCH] Problem 12 comments and cleanup --- uil/october-2013/12/bin/CheckerBoard.class | Bin 4863 -> 4863 bytes uil/october-2013/12/bin/Point.class | Bin 3017 -> 3017 bytes uil/october-2013/12/bin/problem12.class | Bin 1488 -> 1488 bytes uil/october-2013/12/src/problem12.java | 12 ++++++++++-- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/uil/october-2013/12/bin/CheckerBoard.class b/uil/october-2013/12/bin/CheckerBoard.class index 29d720bab1cb189c298cf39b78cd7d07f05040b7..d5d7e134357b9a74e431d6d25f8b212e8b4ea5eb 100644 GIT binary patch delta 300 zcmWNNODIHf6vlu5l3ep>C<_Z@an-CeN|Yj5j7ZWfB#DGPMp<|!4JHe&DLNtLnY{BT z(&P~v1`B0pGYcDQ3;S_aU*GAR?{QLg%Dz0Z{Jo^nNsw+D=pjTu?F`UGm_7!HC@v@$ zhUC-wDICUP1TUlHGDZR8)G9VJL5I%6Ov+d0wTVc~)o7+A>1r{vQsxess5tH^Gbfhk zE^nR;)y&7CgheWesk=jy&RSWLZ%@)%(T!DntX(C%ep9`nrkmujMKRlyvqJ^D)UZcA z`x^OxHV!rNu?9HNNTrI>+3HbiZtrTVb2JT7cK?^)$^F*m)70=Z1qV*H1 T^{P*J(|Yejl`r!l!R+`y0#s2g delta 300 zcmWNMODKeK6vco4l6>aTP!<+w7N44xMu}1+ixEkhg(RUo!j$q>#t?=~V!Gp%5E83N zj7-UM!P?Gd7BNikEDF-?6DBHXUsyEEz|qS&(XH&_pEW44XxJ%bfpeo}nH7gj+51{MZE22KVc20jL11`!64$*gR-g5p3?381JXP*jRRkwJQLGut9Y e`ORwVCM<&C3>*v*K&eOuT_A175Is4YI}QNpeo}nH7gj+*1{MY(22KWH20jK6AQYX<%9blA0Th)4ib?@Rr5O|%WF|MWEn-yI ctj2D_A{fTN!4M9Vj$qIQ(q;@%le4+w00D#yi~s-t diff --git a/uil/october-2013/12/bin/problem12.class b/uil/october-2013/12/bin/problem12.class index 919a8e18b253f117a2f687cbbc21686c3d2177b8..3ad21849aa114ebf4dd2ff9e281d10e62a3711b4 100644 GIT binary patch delta 83 zcmcb>eSv#}1PkM($&xG=9j`KQFNIjHp3kTLx#Hy<_z~3Y#Ht| l1OVwMpjZmSBZhp2#|-5RPZ*kjYP%VpGxRgOn5@mZ6aXW48S(%C delta 83 zcmcb>eSv#}1PkM-$&xG=9nUgwF`Q!%W;o9v&2Wi9k>N6fHp3MLLx!si<_y;uY#FXI l1OVwMpjZmSErxuC+YIFlcNm(0YP%WkGxRe&n5@mZ6aWo(8Danc diff --git a/uil/october-2013/12/src/problem12.java b/uil/october-2013/12/src/problem12.java index 0303806..75454cb 100644 --- a/uil/october-2013/12/src/problem12.java +++ b/uil/october-2013/12/src/problem12.java @@ -1,7 +1,6 @@ import static java.lang.System.*; import java.io.File; import java.io.FileNotFoundException; -import java.util.Arrays; import java.util.List; import java.util.ArrayList; import java.util.Scanner; @@ -31,7 +30,8 @@ class Point { Point merge(Point other) { return new Point(this.x + other.x, this.y + other.y, this.type); } - + + // Offsets the point by a Point's (x, y) set void offset(Point other) { this.x += other.x; this.y += other.y; @@ -82,6 +82,7 @@ class Point { return -1; } + // Creates a List of Points based on a primitive int[][] matrix static List asList(int[][] primitivePoints) { List points = new ArrayList(); for (int[] primPoint: primitivePoints) { @@ -110,6 +111,7 @@ class CheckerBoard { } } + // toString method for a Checkerboard, prints a matrix of types public String toString() { String[] result = new String[this.matrix.length]; for(int x = 0; x < this.matrix.length; x++) { @@ -121,10 +123,13 @@ class CheckerBoard { return String.join("\n", result); } + // Simple functions for identifying whether a point is inBounds. private static boolean inBounds(Point point) {return CheckerBoard.inBounds(point.x, point.y);} private static boolean inBounds(int x, int y) {return x >= 0 && y >= 0 && x < 8 && y < 8;} + // Simple internal getter functions private Point getPoint(Point point) {return this.matrix[point.x][point.y];} String getType(Point point) {return this.matrix[point.x][point.y].type;} + // Identifies whether two points are opposite in types. R(ed) != B(lack) private boolean isReverse(Point first, Point second) {return (first.type.equals(team1) && second.type.equals(team2)) || (first.type.equals(team2) && second.type.equals(team1));} // Just returns all Points with type designated @@ -139,11 +144,14 @@ class CheckerBoard { return found; } + // Starter function for finding max jumps at a point. private int getMaxJumps(Point point) { List previous = new ArrayList(); previous.add(point); return getMaxJumps(point, 0, previous); } + + // Recursively finds maximum possible jumps at a point. private int getMaxJumps(Point point, int score, List previous) { List offsetScores = new ArrayList(); offsetScores.add(score);