mirror of
https://github.com/Xevion/contest.git
synced 2025-12-07 20:06:40 -06:00
Problem 12 comments and cleanup
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,6 @@
|
|||||||
import static java.lang.System.*;
|
import static java.lang.System.*;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
@@ -31,7 +30,8 @@ class Point {
|
|||||||
Point merge(Point other) {
|
Point merge(Point other) {
|
||||||
return new Point(this.x + other.x, this.y + other.y, this.type);
|
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) {
|
void offset(Point other) {
|
||||||
this.x += other.x;
|
this.x += other.x;
|
||||||
this.y += other.y;
|
this.y += other.y;
|
||||||
@@ -82,6 +82,7 @@ class Point {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Creates a List of Points based on a primitive int[][] matrix
|
||||||
static List<Point> asList(int[][] primitivePoints) {
|
static List<Point> asList(int[][] primitivePoints) {
|
||||||
List<Point> points = new ArrayList<Point>();
|
List<Point> points = new ArrayList<Point>();
|
||||||
for (int[] primPoint: primitivePoints) {
|
for (int[] primPoint: primitivePoints) {
|
||||||
@@ -110,6 +111,7 @@ class CheckerBoard {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// toString method for a Checkerboard, prints a matrix of types
|
||||||
public String toString() {
|
public String toString() {
|
||||||
String[] result = new String[this.matrix.length];
|
String[] result = new String[this.matrix.length];
|
||||||
for(int x = 0; x < this.matrix.length; x++) {
|
for(int x = 0; x < this.matrix.length; x++) {
|
||||||
@@ -121,10 +123,13 @@ class CheckerBoard {
|
|||||||
return String.join("\n", result);
|
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(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;}
|
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];}
|
private Point getPoint(Point point) {return this.matrix[point.x][point.y];}
|
||||||
String getType(Point point) {return this.matrix[point.x][point.y].type;}
|
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));}
|
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
|
// Just returns all Points with type designated
|
||||||
@@ -139,11 +144,14 @@ class CheckerBoard {
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Starter function for finding max jumps at a point.
|
||||||
private int getMaxJumps(Point point) {
|
private int getMaxJumps(Point point) {
|
||||||
List<Point> previous = new ArrayList<Point>();
|
List<Point> previous = new ArrayList<Point>();
|
||||||
previous.add(point);
|
previous.add(point);
|
||||||
return getMaxJumps(point, 0, previous);
|
return getMaxJumps(point, 0, previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recursively finds maximum possible jumps at a point.
|
||||||
private int getMaxJumps(Point point, int score, List<Point> previous) {
|
private int getMaxJumps(Point point, int score, List<Point> previous) {
|
||||||
List<Integer> offsetScores = new ArrayList<Integer>();
|
List<Integer> offsetScores = new ArrayList<Integer>();
|
||||||
offsetScores.add(score);
|
offsetScores.add(score);
|
||||||
|
|||||||
Reference in New Issue
Block a user