-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoggleGame.java
More file actions
80 lines (63 loc) · 1.81 KB
/
Copy pathBoggleGame.java
File metadata and controls
80 lines (63 loc) · 1.81 KB
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
package core_problem;
public class BoggleGame {
static char[][] alphabet = {{'T', 'W', 'I', 'C', 'E'}, {'I', 'S', 'C', 'U', 'B'},
{'L', 'E', 'M', 'O', 'N'}, {'U','F', 'M', 'O', 'A'}, {'S', 'O', 'I', 'T', 'U'}};
static String word = "SO";
public static void main(String[] args) {
String result = "";
// String word = "TWICE";
// String word = "IS";
// String word = "BEAUTIFUL";
int x=0; int y=0; int cnt=0;
String[] loc = location(x,y,cnt).split("");
x = Integer.parseInt(loc[0]);
y = Integer.parseInt(loc[1]);
System.out.println(search(word, x, y, ++cnt));
}
static String location(int x, int y, int cnt) {
String loc = "";
end:for(int i=x; i<alphabet.length; i++) {
for(int j=y; j<alphabet[0].length; j++) {
if(alphabet[i][j] == word.charAt(cnt)) {
loc += Integer.toString(i);
loc += Integer.toString(j);
break end;
}
}
}
return loc;
}
static boolean search(String word, int i, int j, int cnt) {
if(!(i>=0 && i<5 && j>=0 && j<5))
return false;
// 현재 위치
if(alphabet[i][j] == word.charAt(0)) {
search(word, i, j, cnt+1);
}
// 위 방향 ( i 감소 )
if(alphabet[i-1][j] == word.charAt(cnt)) {
}
// 아래 방향( i 증가 )
if(alphabet[i+1][j] == word.charAt(cnt)) {
}
// 왼쪽 방향( j 감소 )
if(alphabet[i][j-1] == word.charAt(cnt)) {
}
// 오른쪽 방향( j 증가 )
if(alphabet[i][j+1] == word.charAt(cnt)) {
}
// 왼쪽 위( i, j 감소 )
if(alphabet[i-1][j] == word.charAt(cnt)) {
}
// 왼쪽 아래( i 증가, j 감소 )
if(alphabet[i-1][j] == word.charAt(cnt)) {
}
// 오른쪽 위( i 감소, j 증가 )
if(alphabet[i-1][j-1] == word.charAt(cnt)) {
}
// 오른쪽 아래( i, j 증가 )
if(alphabet[i+1][j+1] == word.charAt(cnt)) {
}
return false;
}
}