-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6-1.pde
144 lines (119 loc) · 3.47 KB
/
6-1.pde
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// https://github.com/becojo/daggerverse/tree/main/processing
///////////////////////////////////////////////////////////////////////////////////
int frames = 30; // number of frames per period
float period = TWO_PI; // period of the animation
boolean preload = false; // run the sketch for 1 period before starting to record
int periods = 200; // number of periods to record
///////////////////////////////////////////////////////////////////////////////////
import java.util.Map;
HashMap<String, String> hm = new HashMap<String, String>();
float size;
int mapWidth, mapHeight;
int dx = 0, dy = -1;
int gx, gy;
boolean done = false;
int count = 0;
boolean shouldExit = false;
char mapGet(int x, int y) {
String key = String.format("%d,%d", x, y);
if (!hm.containsKey(key)) return 0;
return hm.get(key).charAt(0);
}
void setup() {
if(!record) frameRate(100);
String[] lines = loadStrings("6-test");
for (int i = 0; i < lines.length; i++) {
for (int j = 0; j < lines[i].length(); j++) {
char c = lines[i].charAt(j);
if (c == '\n') continue;
String key = String.format("%d,%d", j, i);
hm.put(key, String.valueOf(c));
if(c == '^') {
gx = j;
gy = i;
}
}
}
mapWidth = lines[0].length();
mapHeight = lines.length;
size = width * 0.8 / mapWidth;
textSize(24);
}
void render(float r) {
background(0);
translate(width / 2 - mapWidth / 2 * size, height / 2 - mapHeight / 2 * size);
fill(255);
text(String.format("count: %d", count), -0, -20);
for(int x = 0; x < mapWidth; x++) {
for(int y = 0; y < mapHeight; y++) {
String key = String.format("%d,%d", x, y);
String value = hm.get(key);
if (value == null) continue;
switch(value) {
case "#":
fill(255, 0, 0);
break;
case "^":
fill(0, 255, 0);
break;
case ".":
fill(30);
break;
case "V":
fill(0, 0, 255);
break;
case "C":
fill(0, 0, 100);
break;
}
rect(x * size, y * size, size, size);
}
}
if(!done) {
hm.put(String.format("%d,%d", gx, gy), "V");
gx += dx;
gy += dy;
}
char c = mapGet(gx, gy);
switch (c) {
case '#':
gx -= dx;
gy -= dy;
int tmp = dx;
dx = -dy;
dy = tmp;
gx += dx;
gy += dy;
break;
case 0:
done = true;
break;
}
if (!done) {
hm.put(String.format("%d,%d", gx, gy), "^");
}
if(shouldExit) {
exit();
}
if(done) {
String key = null, value = null;
boolean found = false;
for(int i = 0; i < mapWidth * mapHeight; i++) {
key = String.format("%d,%d", i % mapWidth, i / mapWidth);
value = hm.get(key);
if(value == null) continue;
if(value.equals("V")) {
count += 1;
found = true;
break;
}
}
if(found) {
hm.put(key, "C");
}
if(!found) {
shouldExit = true;
println(frameCount);
}
}
}