problem 3 work

This commit is contained in:
Xevion
2019-09-19 09:17:15 -05:00
parent d3d823f6c3
commit ff1db0a8ab
12 changed files with 248 additions and 97 deletions

6
uil/october-2013/3/java/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../../.." vcs="Git" />
</component>
</project>

View File

@@ -1,7 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="250f6713-4389-436f-88a0-d6dffc72af7e" name="Default Changelist" comment="" />
<list default="true" id="250f6713-4389-436f-88a0-d6dffc72af7e" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../12/bin/CheckerBoard.class" beforeDir="false" afterPath="$PROJECT_DIR$/../../12/bin/CheckerBoard.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../12/bin/Point.class" beforeDir="false" afterPath="$PROJECT_DIR$/../../12/bin/Point.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../12/bin/problem12.class" beforeDir="false" afterPath="$PROJECT_DIR$/../../12/bin/problem12.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../12/src/problem12.java" beforeDir="false" afterPath="$PROJECT_DIR$/../../12/src/problem12.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/input.dat" beforeDir="false" afterPath="$PROJECT_DIR$/input.dat" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/problem3.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/problem3.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/../../9/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/../../9/.idea/workspace.xml" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/out/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
@@ -38,16 +48,52 @@
</counts>
</usages-collector>
</session>
<session id="-1963689904">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.open.time.0" value="1" />
<entry key="project.opened" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="dat" value="23" />
<entry key="java" value="2538" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="JAVA" value="2538" />
<entry key="PLAIN_TEXT" value="23" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="dat" value="7" />
<entry key="java" value="2" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="JAVA" value="2" />
<entry key="PLAIN_TEXT" value="7" />
</counts>
</usages-collector>
</session>
</component>
<component name="FileEditorManager">
<leaf>
<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="187">
<caret line="11" column="15" selection-start-line="11" selection-start-column="15" selection-end-line="11" selection-end-column="15" />
<state relative-caret-position="216">
<caret line="68" column="32" selection-start-line="68" selection-start-column="32" selection-end-line="68" selection-end-column="32" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#456#457#0" expanded="true" />
<element signature="e#517#518#0" expanded="true" />
<element signature="e#641#648#0" expanded="true" />
<element signature="e#692#699#0" expanded="true" />
</folding>
</state>
</provider>
@@ -62,6 +108,14 @@
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>out.println</find>
</findStrings>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$/../../../.." />
</component>
<component name="GradleLocalSettings">
<option name="projectSyncType">
<map>
@@ -74,6 +128,7 @@
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/input.dat" />
<option value="$PROJECT_DIR$/src/problem3.java" />
</list>
</option>
@@ -84,28 +139,30 @@
<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="Scope" />
<pane id="PackagesPane" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="3" type="b2602c69:ProjectViewProjectNode" />
<item name="3" type="462c0819:PsiDirectoryNode" />
<item name="java" type="b2602c69:ProjectViewProjectNode" />
<item name="java" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
<pane id="PackagesPane" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568536537998" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1568902382723" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
</component>
<component name="RunDashboard">
@@ -120,6 +177,20 @@
</list>
</option>
</component>
<component name="RunManager">
<configuration name="problem3" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="problem3" />
<module name="3" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.problem3" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
@@ -137,43 +208,73 @@
<frame x="-8" y="-8" width="1936" height="1066" extended-state="6" />
<editor active="true" />
<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 active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.25" />
<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" />
<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 id="Image Layers" order="2" />
<window_info id="Designer" order="3" />
<window_info id="UI Designer" order="4" />
<window_info id="Capture Tool" order="5" />
<window_info id="Favorites" order="6" side_tool="true" />
<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 anchor="bottom" id="Run" order="2" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.35193133" />
<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" />
<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="bottom" id="Terminal" order="7" />
<window_info anchor="bottom" id="Event Log" order="8" side_tool="true" />
<window_info anchor="bottom" id="Version Control" order="9" show_stripe_button="false" />
<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" />
<window_info anchor="right" id="Palette" order="3" />
<window_info anchor="right" id="Capture Analysis" order="4" />
<window_info anchor="right" id="Theme Preview" order="5" />
<window_info anchor="right" id="Palette&#9;" order="6" />
<window_info anchor="right" id="Maven Projects" order="7" />
</layout>
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="editorHistoryManager">
<entry file="jar://C:/Program Files/AdoptOpenJDK/jdk-8.0.212.04-hotspot/src.zip!/java/lang/Object.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="436">
<caret line="234" column="18" selection-start-line="234" selection-start-column="18" selection-end-line="234" selection-end-column="18" />
<folding>
<element signature="e#11062#11063#0" expanded="true" />
<element signature="e#11145#11146#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="jar://C:/Program Files/AdoptOpenJDK/jdk-8.0.212.04-hotspot/src.zip!/java/lang/String.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="232">
<caret line="657" selection-start-line="657" selection-end-line="657" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/input.dat">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="238">
<caret line="14" column="17" lean-forward="true" selection-start-line="14" selection-start-column="17" selection-end-line="14" selection-end-column="17" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/problem3.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="187">
<caret line="11" column="15" selection-start-line="11" selection-start-column="15" selection-end-line="11" selection-end-column="15" />
<state relative-caret-position="216">
<caret line="68" column="32" selection-start-line="68" selection-start-column="32" selection-end-line="68" selection-end-column="32" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#456#457#0" expanded="true" />
<element signature="e#517#518#0" expanded="true" />
<element signature="e#641#648#0" expanded="true" />
<element signature="e#692#699#0" expanded="true" />
</folding>
</state>
</provider>

View File

@@ -12,8 +12,8 @@
F
F
F |
4
UUUUULL
UULULUL
UUUUUURUULL

View File

Binary file not shown.

View File

Binary file not shown.

View File

Binary file not shown.

View File

@@ -1,39 +1,50 @@
import static java.lang.System.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.Set;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.HashSet;
class Point {
int x;
int y;
int x, y;
Point(int x, int y) {
this.x = x;
this.y = y;
}
void merge(Point other) {
this.x += other.x;
this.y += other.y;
}
public String toString() {
return String.format("Point(%d, %d)", this.x, this.y);
}
}
class Maze {
int[][] offsets = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
String[][] rawMatrix;
Set<Point> snake;
Set<Point> pellets;
// Offset Constants
List<Point> positionOffsets = Arrays.asList(new Point(0, 1), new Point(1, 0), new Point(0, -1), new Point(-1, 0));
List<String> nameOffsets = Arrays.asList("U R D L".split(" "));
// Maze Data
private List<Point> snake = new ArrayList<Point>();;
private List<Point> pellets = new ArrayList<Point>();
private char[][] rawMatrix;
Maze(String[][] rawMatrix) {
Maze(char[][] rawMatrix) {
this.rawMatrix = rawMatrix;
snake = new ArrayList<Point>();
for(int x = 0; x < 15; x++) {
for(int y = 0; y < 15; y++) {
switch(rawMatrix[x][y]) {
case " ":
case ' ':
break;
case "X":
snake.add(new Point(x, y));
case 'X':
this.snake.add(new Point(x, y));
break;
case "F":
pellets.add(new Point(x, y));
case 'F':
this.pellets.add(new Point(x, y));
break;
default:
out.println("Possibly faulty Maze Input with item \"" + rawMatrix[x][y] + "\" found.");
@@ -45,20 +56,42 @@ class Maze {
// Simulate the snake game using instructions
String simulate(String input) {
return "";
char curDirection = 'R';
int score = 0;
for(int i = 0; i < input.length(); i++) {
// Calculate the offset based on the current instruction
Point offset;
char curOffset = input.charAt(i);
if(curOffset == 'O')
offset = positionOffsets.get(nameOffsets.indexOf(curDirection));
else
offset = positionOffsets.get(nameOffsets.indexOf(input.substring(i, i+1)));
out.println(offset);
// Calculate the new point, ensure it's real
Point newPoint = snake.get(snake.size() -1);
newPoint.merge(offset);
if(!this.inBounds(newPoint))
return "GAME OVER @ " + newPoint;
// Add new point, discard end of snake to simulate it's movement
snake.add(newPoint);
snake.remove(0);
// Check if we're at a pellet
score += pellets.contains(newPoint) ? 1 : 0;
}
return Integer.toString(score);
}
boolean inBounds(int x, int y) {
return x >= 0 && y >= 0 && x < 15 && y < 15;
}
// Methods for testing whether a position is in the maze's boundaries
public boolean inBounds(Point point) {return this.inBounds(point.x, point.y);}
private boolean inBounds(int x, int y) {return x >= 0 && y >= 0 && x < 15 && y < 15;}
// Prints a string representation of the Maze
String toString() {
public String toString() {
String[] lines = new String[15];
for(int x = 0; x < 15; x++) {
String[] temp = "";
String[] temp = new String[15];
for(int y = 0; y < 15; y++) {
temp[y] = rawMatrix[x][y];
temp[y] = Character.toString(rawMatrix[x][y]);
}
lines[x] = String.join(" - ", temp);
}
@@ -69,23 +102,31 @@ class Maze {
public class problem3 {
public static void main(String[] args ) throws FileNotFoundException {
// Constants
File input = new File("input.dat");
Scanner read = new Scanner(input);
File fileInput = new File("input.dat");
Scanner read = new Scanner(fileInput);
// Read the maze into a String matrix
char[][] rawMatrix = new String[15][15];
char[][] rawMatrix = new char[15][15];
for(int x = 0; x < 15; x++) {
String line = read.nextLine();
for(int y = 0; y < 15; y++) {
rawMatrix[x][y] = line.charAt(y);
}
}
Maze originalMaze = new Maze(rawMatrix);
// Read each of the inputs and process inside the maze
// Read each of the inputs
int lines = Integer.parseInt(read.nextLine());
String[] inputs = new String[lines];
for(int i = 0; i < lines; i++)
inputs[i] = read.nextLine();
// Simulate inputs
for(String input : inputs) {
Maze temp = originalMaze;
out.println(temp.simulate(input));
out.println(temp);
}
}
}