-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivity.java
More file actions
176 lines (157 loc) · 4.08 KB
/
activity.java
File metadata and controls
176 lines (157 loc) · 4.08 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/** Activity - evaluates position based on piece activity.
*
* Development: develop, get castled early.
* Piece placement: bishops need diagonals, rooks need files, knights need outposts.
* Pawn breaks: determine if a pawn break will unleash pieces.
* To take is a mistake!
**/
public class Activity
{
public static int development() {
int dev = 0;
BB.getPieces();
BB.refreshMoves();
for (int i = 0; i < 64; i++)
{
if(BB.piecesW[i] && !BB.controlB()[i]) // WHITE
dev += BB.valueOf(i)/6*(7-i)/8;
if(BB.piecesB[i] && !BB.controlW()[i]) // BLACK
dev += BB.valueOf(i)/6*i/8;
}
return dev;
}
public static int piecePlacement(String[][] pos) {
int pieceEvalW = 0;
int pieceEvalB = 0;
for (int i = 0; i < 64; i++) {
switch (pos[i / 8][i % 8]) {
case "N":
pieceEvalW += knightEvalW(i);
break;
case "n":
pieceEvalB += knightEvalB(i);
break;
case "B":
pieceEvalW += knightEvalW(i);
break;
case "b":
pieceEvalB += knightEvalW(i);
break;
case "R":
pieceEvalW += rookEvalW(i);
break;
case "r":
pieceEvalB += rookEvalB(i);
break;
}
}
return (pieceEvalW-pieceEvalB);
}
public static int knightEvalW(int i)
{
int nEval = 0;
int r = i / 8;
int c = i % 8;
if (c == 0 || c == 7 || r == 7 || r==0)
nEval -= 10;
try{
if (BB.pawnsB[i+8] && !BB.pawnsB[i+7] && !BB.pawnsB[i+9])
{
nEval+=20;
if(PawnStructure.isBackward((r+1)*8+c))
nEval+=30;
}
}catch (Exception e){}
return nEval;
}
public static int knightEvalB(int i)
{
int nEval = 0;
int r = i / 8;
int c = i % 8;
if (c == 0 || c == 7 || r == 0 || r == 7)
nEval -= 10;
try{
if (BB.pawnsW[i-8] && !BB.pawnsW[i-7] && !BB.pawnsW[i-9])
{
nEval+=20;
if(PawnStructure.isBackward((r-1)*8+c))
nEval+=30;
}
}catch (Exception e){}
return nEval;
}
public static int bishopEvalW(int i)
{ int r = i / 8;
int c = i % 8;
int bEval=0;
if(BB.pawnsW[i-8] /* bishop blocking pawn */)
bEval -= 15;
if (c == 0 || c == 7 || r == 0 || r == 7)
bEval -= 10;
if (BB.pawnsB[(r-1)*8 + c+1] || BB.pawnsB[(r-1)*8 + c-1])
bEval-=50;
for (int j=0; j<64; j++){
if(BB.bMovesW[j]) bEval+=2;
if(BB.bMovesW[j] && BB.piecesB[j]) bEval+=5;
}
return bEval;
}
public static int bishopEvalB(int i)
{ int r = i / 8;
int c = i % 8;
int bEval=0;
if(BB.pawnsB[i-8] /* bishop blocking pawn */)
bEval -= 15;
if (c == 0 || c == 7 || r == 0 || r == 7)
bEval -= 10;
if (BB.pawnsW[(r-1)*8 + c+1] || BB.pawnsW[(r-1)*8 + c-1])
bEval-=50;
for (int j=0; j<64; j++){
if(BB.bMovesW[j]) bEval+=2;
if(BB.bMovesW[j] && BB.piecesB[j]) bEval+=5;
}
return bEval;
}
public static int rookEvalW(int i) {
int r = i / 8;
int c = i % 8;
int rEval = 0;
for (int j = 0; j < 64; j++) {
try {
// if (BB.fileOf(i)[j] && BB.pawnsW[j]) // on a closed file
// rEval -= j * 4;
if (BB.rMovesW[j] && BB.rooks[j] && BB.piecesW[j]) // rooks are doubled / connected
rEval += 10;
// if (BB.rankOf(i)[j] && BB.pawnsB[j]) // Opponent pawns on same rank as rook
// rEval+=5;
if ("p".equals(Board.chessBoard[r][j]) &&
PawnStructure.isBackward(j*8+c)) // backward pawn on semi-open file AND BLACK
rEval += 20;
if ("p".equals(Board.chessBoard[r-1][c+1]) || "p".equals(Board.chessBoard[r-1][c-1])) // R attacked
rEval-=50;
} catch (Exception e) {}
}
return rEval;
}
public static int rookEvalB(int i) {
int r = i / 8;
int c = i % 8;
int rEval = 0;
for (int j = 0; j < 8; j++) {
try {
// if (BB.fileOf(i)[j] && BB.pawnsB[j]) // on a closed file
// rEval -= (7-j) * 4;
if (BB.rMovesB[j] && BB.rooks[j] && BB.piecesB[j]) // rooks are doubled / connected
rEval += 10;
// if (BB.rankOf(i)[j] && BB.pawnsW[j]) // Opponent pawns on same rank as rook
// rEval+=5;
if (PawnStructure.isBackward(j+c*8)) // backward pawn on semi-open file
rEval += 20;
if ("P".equals(Board.chessBoard[r+1][c+1]) || "P".equals(Board.chessBoard[r+1][c-1]))
rEval-=50;
} catch (Exception e) {}
}
return rEval;
}
}