forked from Metropolice23/Reversi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AIcomp.java
144 lines (136 loc) · 2.43 KB
/
AIcomp.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
public class AIcomp
{
private Gameboard gameboard;
private Square[][] squares;
public AIcomp (Gameboard gameboard)
{
this.gameboard=gameboard;
squares= gameboard.getSquares();
if (corners()==false)
{
if (sides()==false)
{
if (content()==false)
{
}
}
}
if (!gameboard.checkwin())
{
gameboard.checkplayer();
}
}
public boolean corners ()
{
int x=-1,y=-1,max=0;
if(squares[0][0].getColor().equals("Empty")&&max<gameboard.checksum("White",0,0))
{
max=gameboard.checksum("White",0,0);
x=0;
y=0;
}
if(squares[7][0].getColor().equals("Empty")&&max<gameboard.checksum("White",7,0))
{
max=gameboard.checksum("White",7,0);
x=7;
y=0;
}
if(squares[0][7].getColor().equals("Empty")&&max<gameboard.checksum("White",0,7))
{
max=gameboard.checksum("White",0,7);
x=0;
y=7;
}
if(squares[7][7].getColor().equals("Empty")&&max<gameboard.checksum("White",7,7))
{
max=gameboard.checksum("White",7,7);
x=7;
y=7;
}
int[] sides;
if (max==0)
{return false;}
if(x!=-1&&y!=-1)
{
sides=gameboard.check("White",x,y);
gameboard.change (sides,x,y);
}
// System.out.println("("+x+" "+y+")");
return true;
}
public boolean sides ()
{
int max=0;//gameboard.checksum("White",1,0);
int x=1;
int y=0;
for (int i=1;i<7;i++)
{
if(squares[i][0].getColor().equals("Empty")&&max<gameboard.checksum("White",i,0))
{
max=gameboard.checksum("White",i,0);
x=i;
y=0;
}
}
for (int i=1;i<7;i++)
{
if(squares[0][i].getColor().equals("Empty")&&max<gameboard.checksum("White",0,i))
{
max=gameboard.checksum("White",0,i);
x=0;
y=i;
}
}
for (int i=1;i<7;i++)
{
if(squares[7][i].getColor().equals("Empty")&&max<gameboard.checksum("White",7,i))
{
max=gameboard.checksum("White",7,i);
x=7;
y=i;
}
}
for (int i=1;i<7;i++)
{
if(squares[i][7].getColor().equals("Empty")&&max<gameboard.checksum("White",i,7))
{
max=gameboard.checksum("White",i,7);
x=i;
y=7;
}
}
if (max==0)
{return false;}
int[] sides;
sides=gameboard.check("White",x,y);
gameboard.change (sides,x,y);
// System.out.println("("+x+" "+y+")");
return true;
}
public boolean content ()
{
int max= 0;
int x=-1;
int y=-1;
for (int i=1;i<7;i++)
{
for (int j=1;j<7;j++)
{
if(squares[i][j].getColor().equals("Empty")&&max<gameboard.checksum("White",i,j))
{
max=gameboard.checksum("White",i,j);
x=i;
y=j;
}
}
}
// System.out.println("("+x+" "+y+")");
if (max==0)
{return false;}
int[] sides;
sides=gameboard.check("White",x,y);
gameboard.change (sides,x,y);
// System.out.println("("+x+" "+y+")");
return true;
}
}