problem 12 continued work

This commit is contained in:
Xevion
2019-09-19 19:52:57 -05:00
parent 9e4f2f265c
commit cfbc66b891
7 changed files with 397 additions and 39 deletions

11
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,11 @@
{
"configurations": [
{
"type": "java",
"name": "CodeLens (Launch) - problem12",
"request": "launch",
"mainClass": "problem12",
"projectName": "12"
}
]
}

235
uil/october-2013/12/.idea/workspace.xml generated Normal file
View File

@@ -0,0 +1,235 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="1fd89a9c-d895-4e45-acab-398cb78a9403" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/12.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bin/CheckerBoard.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/bin/Point.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/bin/problem12.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/problem12.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/problem12.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../3/java/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../3/java/.idea/workspace.xml" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/bin/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FUSProjectUsageTrigger">
<session id="1210997399">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.closed" value="1" />
<entry key="project.open.time.6" value="1" />
<entry key="project.opened" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="java" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="JAVA" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="java" value="42" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="JAVA" value="42" />
</counts>
</usages-collector>
</session>
</component>
<component name="FileEditorManager">
<leaf>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/problem12.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="29" lean-forward="true" selection-start-line="29" selection-end-line="29" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#880#881#0" expanded="true" />
<element signature="e#901#902#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../../.." />
</component>
<component name="GradleLocalSettings">
<option name="projectSyncType">
<map>
<entry key="A:/Programming/Modding/Minecraft/EnderStorage" value="PREVIEW" />
<entry key="A:/Programming/Modding/Minecraft/Fabric/fabric-example-mod" value="PREVIEW" />
<entry key="A:/Programming/Modding/Minecraft/HelloWorldMod" value="PREVIEW" />
</map>
</option>
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/problem12.java" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="351" />
<option name="y" value="-16" />
<option name="width" value="974" />
<option name="height" value="1057" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="PackagesPane" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="12" type="b2602c69:ProjectViewProjectNode" />
<item name="12" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="12" type="b2602c69:ProjectViewProjectNode" />
<item name="12" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="12" type="b2602c69:ProjectViewProjectNode" />
<item name="12" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="problem12.java" type="529ef68f:ClassesTreeStructureProvider$PsiClassOwnerTreeNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568926242667" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager">
<configuration name="problem12" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="problem12" />
<module name="12" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.problem12" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="1fd89a9c-d895-4e45-acab-398cb78a9403" name="Default Changelist" comment="" />
<created>1568926083487</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1568926083487</updated>
</task>
<servers />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1066" extended-state="6" />
<layout>
<window_info id="Image Layers" />
<window_info id="Designer" />
<window_info id="UI Designer" />
<window_info id="Capture Tool" />
<window_info id="Favorites" side_tool="true" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
<window_info anchor="bottom" id="Terminal" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info active="true" anchor="bottom" id="Messages" visible="true" weight="0.32939914" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="right" id="Palette" />
<window_info anchor="right" id="Theme Preview" />
<window_info anchor="right" id="Capture Analysis" />
<window_info anchor="right" id="Palette&#9;" />
<window_info anchor="right" id="Maven Projects" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/problem12.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="29" lean-forward="true" selection-start-line="29" selection-end-line="29" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#880#881#0" expanded="true" />
<element signature="e#901#902#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
<component name="masterDetails">
<states>
<state key="ProjectJDKs.UI">
<settings>
<last-edited>11</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

@@ -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<Point> 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<Point> list) {
for(Point other : list) {
if(this.x == other.x && this.y == other.y)
return list.indexOf(other);
}
return -1;
}
public static List<Point> asList(int[][] primitivePoints) {
List<Point> points = new ArrayList<Point>();
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<Point> offsets = Arrays.asList(new Point[]{Point(1, 1), Point(-1, -1), Point(-1, 1), Point(1, -1)});
// Offsets
List<Point> 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<Point> getPossible(int x, int y) {
return getPossible(x, y, new ArrayList<Point>());
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<Point> getCheckers(String type) {
List<Point> found = new ArrayList<Point>();
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<Point> getPossible(int x, int y, List<Point> blacklist) {}
int getMaxJumps(Point point) {return getMaxJumps(point, 0, Arrays.asList(point));}
int getMaxJumps(Point point, int score, List<Point> previous) {
List<Integer> 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<Point> entries = getCheckers(team);
out.println(entries);
List<Integer> jumps = new ArrayList<Integer>();
// 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 {
@@ -55,7 +186,9 @@ class problem12 {
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());
}

View File

@@ -44,6 +44,7 @@
<session id="-1963689904">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.closed" value="1" />
<entry key="project.open.time.0" value="1" />
<entry key="project.opened" value="1" />
</counts>
@@ -75,28 +76,7 @@
</session>
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/problem3.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
<caret line="88" column="21" lean-forward="true" selection-start-line="88" selection-start-column="21" selection-end-line="88" selection-end-column="21" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#242#243#0" expanded="true" />
<element signature="e#261#262#0" expanded="true" />
<element signature="e#456#457#0" expanded="true" />
<element signature="e#517#518#0" expanded="true" />
<element signature="e#597#598#0" expanded="true" />
<element signature="e#658#659#0" expanded="true" />
<element signature="e#641#648#0" expanded="true" />
<element signature="e#692#699#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
@@ -161,8 +141,8 @@
</panes>
</component>
<component name="PropertiesComponent">
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568926039217" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568926048325" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../../12" />
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
</component>
<component name="RunDashboard">
@@ -215,7 +195,6 @@
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1066" extended-state="6" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25266525" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
@@ -227,7 +206,7 @@
<window_info anchor="bottom" id="Messages" weight="0.32939914" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.29077253" />
<window_info anchor="bottom" id="Run" order="2" weight="0.29077253" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.39914164" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />