summaryrefslogtreecommitdiff
path: root/src/ch/epfl/maze/util/LabyrinthGenerator.java
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-11-21 10:36:18 +0100
committerPacien TRAN-GIRARD2015-11-21 10:36:18 +0100
commit655ac88f4e73b2df532a451aedf5a561ea1b0d2c (patch)
treeef6f914a465575f313e2b280bf0639d87a4cbd58 /src/ch/epfl/maze/util/LabyrinthGenerator.java
parent56279eb59ccdea48b18daa027a5095d861b4e2f4 (diff)
downloadmaze-solver-655ac88f4e73b2df532a451aedf5a561ea1b0d2c.tar.gz
Import project structure
Diffstat (limited to 'src/ch/epfl/maze/util/LabyrinthGenerator.java')
-rw-r--r--src/ch/epfl/maze/util/LabyrinthGenerator.java533
1 files changed, 533 insertions, 0 deletions
diff --git a/src/ch/epfl/maze/util/LabyrinthGenerator.java b/src/ch/epfl/maze/util/LabyrinthGenerator.java
new file mode 100644
index 0000000..f0e5f1b
--- /dev/null
+++ b/src/ch/epfl/maze/util/LabyrinthGenerator.java
@@ -0,0 +1,533 @@
1package ch.epfl.maze.util;
2
3import java.io.File;
4import java.io.FileNotFoundException;
5import java.util.ArrayList;
6import java.util.Scanner;
7import java.util.regex.Matcher;
8import java.util.regex.Pattern;
9
10/**
11 * Generates a set of pre-computed labyrinth structures
12 *
13 */
14
15public final class LabyrinthGenerator {
16
17 /**
18 * Returns a precomputed labyrinth of small size.
19 *
20 * @return A small labyrinth
21 */
22
23 public static int[][] getSmall() {
24 int[][] labyrinth = {
25 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1 },
26 { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 },
27 { 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
28 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
29 { 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1 },
30 { 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1 },
31 { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1 },
32 { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 },
33 { 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1 },
34 { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1 },
35 { 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
36 };
37
38 return labyrinth;
39 }
40
41 /**
42 * Returns a precomputed labyrinth of medium size.
43 *
44 * @return A medium labyrinth
45 */
46
47 public static int[][] getMedium() {
48 int[][] labyrinth = {
49 { 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
50 { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
51 { 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
52 { 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
53 { 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1 },
54 { 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1 },
55 { 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1 },
56 { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1 },
57 { 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1 },
58 { 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 },
59 { 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 },
60 { 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1 },
61 { 1, 0, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1 },
93 { 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1 },
94 { 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1 },
95 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
96 };
97
98 return labyrinth;
99 }
100
101 // ==============================================================
102
103 // ==============================================================
104
105 /**
106 * Returns the labyrinth structure of the Pac-Man level.
107 *
108 * @return The Pac-Man level
109 */
110
111 public static int[][] getPacMan() {
112 int[][] labyrinth = {
113 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
114 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
115 { 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1 },
116 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
117 { 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1 },
118 { 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1 },
119 { 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1 },
120 { 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1 },
121 { 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1 },
122 { 0, 0, 0, 0, 0, 0, 0, 1, -1, -1, -1, 1, 0, 0, 0, 0, 0, 0, 0 },
123 { 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 },
124 { 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 },
125 { 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1 },
126 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
127 { 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1 },
128 { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1 },
129 { 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1 },
130 { 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
131 { 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1 },
132 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
133 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
134 };
135
136 return labyrinth;
137 }
138
139 // ==============================================================
140
141 /**
142 * Returns the labyrinth structure of one of the Ms. Pac-Man levels.
143 *
144 * @return One of the Ms. Pac-Man levels
145 */
146
147 public static int[][] getMsPacMan() {
148 int[][] labyrinth = {
149 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
150 { 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 },
151 { 1, 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 0, 1, 0, 1, 1, 0, 1 },
168 { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
169 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
170 };
171
172 return labyrinth;
173 }
174
175 /**
176 * Returns a hard-coded labyrinth which is multiply connected.
177 * <p>
178 * If the Monkey algorithm is run on this labyrinth, it will never find the
179 * solution.
180 *
181 * @return A labyrinth multiply connected
182 */
183
184 public static int[][] getMultiplyConnected() {
185 int[][] labyrinth = {
186 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, },
187 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, },
188 { 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, },
189 { 1, 0, 0, 3, 1, 0, 1, 0, 0, 0, 1, },
190 { 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, },
191 { 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, },
192 { 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, },
193 { 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, },
194 { 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, },
195 { 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, },
196 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, }