|
5 | 5 |
|
6 | 6 | public class WDLModel
|
7 | 7 | {
|
8 |
| - private final static double[] as = {-40.00676365, 98.77222217, -182.08209988, 340.61197659}; |
9 |
| - private final static double[] bs = {62.18462409, -195.09918531, 258.58208433, 1.29372611}; |
10 |
| - |
| 8 | + private final static double[] as = { -117.29796837, 388.52982654, -512.96172771, 477.99147478 }; |
| 9 | + private final static double[] bs = { -47.75093113, 118.81734426, -33.05800930, 94.01690687 }; |
| 10 | + |
11 | 11 | @SuppressWarnings("unused")
|
12 |
| - private final static int NormalizeToPawnValue = 217; |
| 12 | + private final static int NormalizeToPawnValue = 236; |
13 | 13 |
|
14 | 14 | private final static int PAWN_VALUE = 1;
|
15 | 15 | private final static int KNIGHT_VALUE = 3;
|
16 | 16 | private final static int BISHOP_VALUE = 3;
|
17 | 17 | private final static int ROOK_VALUE = 5;
|
18 | 18 | private final static int QUEEN_VALUE = 9;
|
19 |
| - |
| 19 | + |
20 | 20 | private static int countMaterial(Board board)
|
21 | 21 | {
|
22 | 22 | return Long.bitCount(board.getBitboard(Piece.WHITE_PAWN)) * PAWN_VALUE
|
23 |
| - + Long.bitCount(board.getBitboard(Piece.WHITE_KNIGHT)) * KNIGHT_VALUE |
24 |
| - + Long.bitCount(board.getBitboard(Piece.WHITE_BISHOP)) * BISHOP_VALUE |
25 |
| - + Long.bitCount(board.getBitboard(Piece.WHITE_ROOK)) * ROOK_VALUE |
26 |
| - + Long.bitCount(board.getBitboard(Piece.WHITE_QUEEN)) * QUEEN_VALUE |
27 |
| - + Long.bitCount(board.getBitboard(Piece.BLACK_PAWN)) * PAWN_VALUE |
28 |
| - + Long.bitCount(board.getBitboard(Piece.BLACK_KNIGHT)) * KNIGHT_VALUE |
29 |
| - + Long.bitCount(board.getBitboard(Piece.BLACK_BISHOP)) * BISHOP_VALUE |
30 |
| - + Long.bitCount(board.getBitboard(Piece.BLACK_ROOK)) * ROOK_VALUE |
31 |
| - + Long.bitCount(board.getBitboard(Piece.BLACK_QUEEN)) * QUEEN_VALUE; |
| 23 | + + Long.bitCount(board.getBitboard(Piece.WHITE_KNIGHT)) * KNIGHT_VALUE |
| 24 | + + Long.bitCount(board.getBitboard(Piece.WHITE_BISHOP)) * BISHOP_VALUE |
| 25 | + + Long.bitCount(board.getBitboard(Piece.WHITE_ROOK)) * ROOK_VALUE |
| 26 | + + Long.bitCount(board.getBitboard(Piece.WHITE_QUEEN)) * QUEEN_VALUE |
| 27 | + + Long.bitCount(board.getBitboard(Piece.BLACK_PAWN)) * PAWN_VALUE |
| 28 | + + Long.bitCount(board.getBitboard(Piece.BLACK_KNIGHT)) * KNIGHT_VALUE |
| 29 | + + Long.bitCount(board.getBitboard(Piece.BLACK_BISHOP)) * BISHOP_VALUE |
| 30 | + + Long.bitCount(board.getBitboard(Piece.BLACK_ROOK)) * ROOK_VALUE |
| 31 | + + Long.bitCount(board.getBitboard(Piece.BLACK_QUEEN)) * QUEEN_VALUE; |
32 | 32 | }
|
33 |
| - |
| 33 | + |
34 | 34 | private static double[] calculateParameters(Board board)
|
35 | 35 | {
|
36 | 36 | int material = countMaterial(board);
|
37 |
| - |
| 37 | + |
38 | 38 | material = Math.max(material, 17);
|
39 | 39 | material = Math.min(material, 78);
|
40 |
| - |
| 40 | + |
41 | 41 | double m = material / 58.0;
|
42 |
| - |
| 42 | + |
43 | 43 | double a = (((as[0] * m + as[1]) * m + as[2]) * m) + as[3];
|
44 |
| - double b = (((bs[0] * m + bs[1]) * m + bs[2]) * m) + bs[3]; |
45 |
| - |
46 |
| - return new double[]{a, b}; |
| 44 | + double b = (((bs[0] * m + bs[1]) * m + bs[2]) * m) + bs[3]; |
| 45 | + |
| 46 | + return new double[] { a, b }; |
47 | 47 | }
|
48 |
| - |
| 48 | + |
49 | 49 | private static int calculateWinRate(int v, Board board)
|
50 | 50 | {
|
51 | 51 | double[] parameters = calculateParameters(board);
|
52 |
| - |
53 |
| - return (int)(0.5 + 1000 / (1 + Math.exp((parameters[0] - (double) v) / parameters[1]))); |
| 52 | + |
| 53 | + return (int) (0.5 + 1000 / (1 + Math.exp((parameters[0] - (double) v) / parameters[1]))); |
54 | 54 | }
|
55 |
| - |
| 55 | + |
56 | 56 | public static int[] calculateWDL(int v, Board board)
|
57 | 57 | {
|
58 | 58 | int winRate = calculateWinRate(v, board);
|
59 | 59 | int lossRate = calculateWinRate(-v, board);
|
60 | 60 | int drawRate = 1000 - winRate - lossRate;
|
61 |
| - |
62 |
| - return new int[] {winRate, drawRate, lossRate}; |
| 61 | + |
| 62 | + return new int[] { winRate, drawRate, lossRate }; |
63 | 63 | }
|
64 |
| - |
| 64 | + |
65 | 65 | public static int normalizeEval(int v, Board board)
|
66 | 66 | {
|
67 | 67 | double a = calculateParameters(board)[0];
|
68 |
| - |
| 68 | + |
69 | 69 | return (int) Math.round((100 * v) / a);
|
70 | 70 | }
|
71 | 71 | }
|
0 commit comments