-
Notifications
You must be signed in to change notification settings - Fork 1
/
29_chessBoardCellColor
47 lines (41 loc) · 1.32 KB
/
29_chessBoardCellColor
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
boolean solution(String cell1, String cell2) {
// 0 1 0 1 0 1 0 1
// 1 0 1 0 1 0 1 0
// 0 1 0 1 0 1 0 1
// 1 0 1 0 1 0 1 0
// 0 1 0 1 0 1 0 1
// 1 0 1 0 1 0 1 0
// 0 1 0 1 0 1 0 1
// 1 0 1 0 1 0 1 0
Integer b[] = new Integer[]{0,1,0,1,0,1,0,1};
Integer w[] = new Integer[]{1,0,1,0,1,0,1,0};
List<List<Integer>> board = new ArrayList<>();
for(int i=1;i<=8;i++){
if(i%2==0) board.add(Arrays.asList(w));
else board.add(Arrays.asList(b));
}
//System.out.println(board);
Map<String,Integer> hm = new HashMap<>();
Integer zero = 0;
Integer one = 1;
Integer lastEntried = 0;
for(char c='A';c<='H';c++){
for(int n=1;n<=8;n++){
StringBuilder sb = new StringBuilder();
sb.append(c);
sb.append(n);
if(lastEntried == 0){
if(n%2==0) hm.put(sb.toString(),one);
else hm.put(sb.toString(),zero);
}
else{
if(n%2!=0) hm.put(sb.toString(),one);
else hm.put(sb.toString(),zero);
}
System.out.println(sb.toString()+" = "+hm.get(sb.toString()));
}
if(lastEntried == 0) lastEntried = 1;
else lastEntried = 0;
}
return hm.get(cell1) == hm.get(cell2);
}