-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandomWalk.java
52 lines (37 loc) · 1.13 KB
/
RandomWalk.java
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
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class RandomWalk {
static Random r = new Random();
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
while (!"".equals(s.nextLine())) {}; // skip map
while (true)
oneRound(s);
}
public static String randomDirection() {
switch (r.nextInt(4)) {
case 0: return "L";
case 1: return "U";
case 2: return "R";
case 3: return "D";
}
return null; // not reached
}
public static void oneRound(Scanner sc) {
ArrayList<Things.Thing> things = new ArrayList();
sc.nextLine(); // skip points
String l = sc.nextLine();
while (!"".equals(l)) {
things.add(Things.parseThing(l));
l = sc.nextLine();
}
for (Things.Thing t : things) {
if (t instanceof Things.Soldier) {
Things.Soldier s = (Things.Soldier) t;
System.out.println(s.name+" "+randomDirection());
}
}
System.out.println("");
}
}