-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpawnStructure.java
More file actions
92 lines (75 loc) · 2.22 KB
/
pawnStructure.java
File metadata and controls
92 lines (75 loc) · 2.22 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
/*
* Space: encourage cramping
* Structure: encourage pawn duo, discourage backward pawn & isolated pawn
* Implement basic plans (minority attack, creating OPP)
* Center: factor in moves like c5, judge tension
*/
public class PawnStructure {
public static boolean isBackward(int i)
{
int r = i / 8;
int c = i % 8;
boolean flag = true;
try{
if(BB.pawnsW[i] && !"p".equals(Board.chessBoard[r-1][c]))
for (int j = 7; j >= r; j--)
if (!"P".equals(Board.chessBoard[j][c + 1]) && !"P".equals(Board.chessBoard[j][c - 1]))
flag = false;
if ("p".equals(Board.chessBoard[r][c]) && !"P".equals(Board.chessBoard[r+1][c]))
for (int k = 0; k <= r; k++)
if(!"p".equals(Board.chessBoard[k][c + 1]) && !"p".equals(Board.chessBoard[k][c - 1]))
flag=false;
}catch(Exception e){/* Outside pawns will never be backward */}
return flag;
}
public static int spaceW(String[][] pos) {
int spaceEvalW = 0;
for (int i = 0; i < 64; i++) {
int r = i / 8;
if (BB.pawnsW[i])
try {
if (BB.pawnsW[i+7] || BB.pawnsW[i+9] && r < 6) // protected
spaceEvalW += 3 * (-(r - 7));
if (BB.pawnsW[i+1] || BB.pawnsW[i-1] && r < 6) // pawn duo
spaceEvalW += 6 * (-(r - 7));
if(BB.center()[i])
spaceEvalW += 20;
} catch (Exception e) {}
}
return spaceEvalW;
}
public static int spaceB(String[][] pos) {
int spaceEvalB = 0;
for (int i = 0; i < 64; i++) {
int r = i / 8;
if (BB.pawnsB[i])
try {
if ((BB.pawnsB[i-7] || BB.pawnsB[i-9]) && r > 2) // protected
spaceEvalB += 3 * r;
if ((BB.pawnsB[i+1] || BB.pawnsB[i-1]) && r > 2) // pawn duo
spaceEvalB += 6 * r;
if(BB.center()[i])
spaceEvalB += 20;
} catch (Exception e) {}
}
return spaceEvalB;
}
public static int pawnCenter(String[][] pos) {
int centerEval = 0;
int centerEvalW = 0;
int centerEvalB = 0;
int[] center = { 27, 28, 35, 36 };
for (int i = 0; i < 4; i++) {
if (BB.pawnsW[center[i]])
centerEvalW += 200;
if (BB.pawnsB[center[i]])
centerEvalB += 200;
if(BB.controlW()[center[i]])
centerEvalW += 50;
if(BB.controlB()[center[i]])
centerEvalB += 50;
}
centerEval = (centerEvalW - centerEvalB);
return centerEval;
}
}