forked from zpltys/Othello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDfs.java
149 lines (141 loc) · 2.93 KB
/
Dfs.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
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
145
146
147
148
149
import java.awt.Point;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Dfs extends AI{
public int [][]weight;
public Dfs() {
weight = new int[8][];
int i, j;
for(i = 0; i < 8; i++)
weight[i] = new int[8];
for(i = 0; i < 8; i++)
for(j = 0; j < 8; j++)
weight[i][j] = 1;
for(i = 0;i < 8;i++)
{
weight[0][i] = 3;
weight[7][i] = 3;
weight[i][0] = 3;
weight[i][7] = 3;
}
weight[0][0] = 10;
weight[0][7] = 10;
weight[7][0] = 10;
weight[7][7] = 10;
}
@Override
public Point calStep(State state,int color)
{
int ans = -100000;
Point p = new Point();
p.x = -1;
p.y = -1;
List<statev> statevList = new ArrayList<statev>();
for(int i = 0;i < 8;i++)
for(int j = 0;j < 8;j++)
{
int x = state.test(i,j,color);
if(x > 0)
statevList.add(new statev(i,j,x));
}
Collections.sort(statevList, new sortstatev());
int count = 0;
for(statev ss : statevList)
{
count++;
State temp = new State(state);
int x = temp.insert(ss.x,ss.y,color);
x += mean(temp,3 - color,5);
x *= weight[ss.x][ss.y];
if(x > ans)
{
ans = x;
p.x = ss.x;
p.y = ss.y;
}
}
return p;
}
class statev
{
int x,y;
int value;
public statev(int xx,int yy,int v)
{
x=xx;
y=yy;
value = v;
}
}
class sortstatev implements Comparator {
public int compare(Object o1, Object o2) {
statev s1 = (statev) o1;
statev s2 = (statev) o2;
if(s1.value > s2.value)
return 1;
else
return -1;
}
}
public int mean(State state,int color,int cnt)
{
boolean fag = false;
int ans = -100000;
List<statev> statevList = new ArrayList<statev>();
for(int i = 0;i < 8;i++)
for(int j = 0;j < 8;j++)
{
int x = state.test(i,j,color);
if(x > 0)
statevList.add(new statev(i,j,x));
}
/*if(cnt>0)
{
for(int i=0;i<8;i++)
{
for(int j=0;j<i;j++)
System.out.print(state.s[i][j]);
System.out.println("\n");
}
}*/
if(cnt <= 0)
{
//ans=-1;
for(int i = 0;i < 8;i++)
for(int j = 0;j < 8;j++)
{
int x = state.test(i,j,color);
if(x > ans && x > 0)
ans = x;
}
return ans;
}
Collections.sort(statevList, new sortstatev());
State temp = new State();
int count = 0;
for(statev ss : statevList)
{
count++;
if(count > 5)
break;
fag=true;
for(int ii = 0;ii < 8;ii++)
for(int jj = 0;jj < 8;jj++)
temp.s[ii][jj] = state.s[ii][jj];
int x = temp.insert(ss.x,ss.y,color);
x -= mean(temp,3 - color,cnt-1);
x *= weight[ss.x][ss.y];
if(x > ans)
ans = x;
}
if(ans == -100000)
{
//System.out.print(cnt);
//System.out.print(fag);
ans = -mean(state,3 - color,cnt-1);
}
return ans;
}
}