1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#!/bin/sh
# Run tests for just a subset of layers.
#
# Usage:
# build_and_test_until [file prefix] [test name]
# Provide the second arg to run just a single test.
set -e
# clean previous builds if they were building until a different layer
touch .until
PREV_UNTIL=`cat .until`
if [ "$PREV_UNTIL" != $1 ]
then
./clean top-level
echo $1 > .until
fi
./build --until $1 && ./subx_bin test $2
span class="kt">int curx = x + directions[i][0];
int cury = y + directions[i][1];
// Out of bounds check.
if (curx < 0 || cury < 0
|| curx > maze.length - 1 || cury > maze[0].length - 1)
continue;
if (visited[curx][cury])
continue;
// Marker cells.
if (maze[curx][cury] == '$')
System.out.print("|");
else if (maze[curx][cury] == '#')
System.out.print("!");
// Print the maze on every iteration.
for(int j = 0; j < maze.length; j++)
for(int k = 0; k < maze[j].length; k++)
if (j == curx && k == cury)
System.out.print("@");
else
System.out.print(visited[j][k] ? "-" : maze[j][k]);
System.out.println();
// Found a solution, exiting.
if (maze[curx][cury] == '$')
System.exit(0);
if (maze[curx][cury] == '.') {
visited[curx][cury] = true;
traverse(curx, cury, maze, visited);
visited[curx][cury] = false;
}
}
}
public static void main(String[] args) {
char[][] maze = {
{'.', '#', '.', '#', '.', '.', '#', '.'},
{'.', '.', '.', '.', '.', '.', '.', '.'},
{'.', '#', '.', '.', '#', '.', '.', '$'},
{'.', '.', '.', '#', '.', '#', '.', '.'},
{'.', '.', '.', '.', '.', '.', '.', '#'},
{'.', '#', '#', '.', '.', '.', '#', '.'},
{'.', '.', '.', '.', '.', '.', '.', '.'},
};
boolean[][] visited = new boolean[maze.length][maze[0].length];
for (int i = 0; i < maze.length; i++)
for (int j = 0; j < maze[i].length; j++)
visited[i][j] = false;
System.out.println(String.format("rows:%d cols:%d", maze.length, maze[0].length));
// Print the maze.
for(int j = 0; j < maze.length; j++)
for(int k = 0; k < maze[j].length; k++)
System.out.print(maze[j][k]);
System.out.println();
// Start at 0,0.
visited[0][0] = true;
traverse(0, 0, maze, visited);
}
}
|