Add threats (13.63 +/- 7.48)

This commit is contained in:
Mattia Giambirtone 2024-06-18 22:56:24 +02:00
parent 26e2fad184
commit e4a96ccdce
Signed by: nocturn9x
GPG Key ID: B6025DD9B4458B69
6 changed files with 189 additions and 165 deletions

17
Makefile Normal file
View File

@ -0,0 +1,17 @@
.SUFFIXES:
CC := clang
GDB := gdb
LD := lld
SRCDIR := src
BUILDDIR := bin
CFLAGS := -flto -Ofast -mtune=native -march=native
LFLAGS := -flto -fuse-ld=$(LD)
NFLAGS := --cc:$(CC) --mm:arc -d:useMalloc -o:$(BUILDDIR)/heimdall --passC:"$(CFLAGS)" --passL:"$(LFLAGS)"
release:
nim c $(NFLAGS) -d:danger heimdall/heimdall
debug:
nim c $(NFLAGS) -d:debug heimdall/heimdall

View File

@ -15,7 +15,7 @@ Just run `nimble test`: sit back, relax, get yourself a cup of coffee and wait f
## Features
List of features that are either already implemented or planned
List of features that are either already implemented ([X]) or planned ([ ])
### Search
@ -32,8 +32,8 @@ List of features that are either already implemented or planned
- [X] Principal variation search
- [X] Iterative deepening
- [X] Transposition table
- [X] Cutoffs
- [X] Move ordering
- [X] TT Cutoffs
- [X] TT Move ordering
- [X] MVV-LVA
- [X] Static exchange evaluation
- [X] History heuristic
@ -44,14 +44,15 @@ List of features that are either already implemented or planned
- [X] Null-window search
- [X] Parallel search (lazy SMP)
- [X] Pondering
- [X] Counter moves
- [ ] Capture history
- [ ] Continuation history
- [ ] Mate distance pruning
- [ ] Late move pruning
- [X] Counter moves
- [ ] Razoring
- [ ] Internal iterative reductions
- [ ] Internal iterative deepening
- [ ] SEE pruning
### Eval
@ -59,8 +60,8 @@ List of features that are either already implemented or planned
- [X] Piece-square tables
- [X] Material
- [X] Tempo
- [ ] King safety
- [X] Virtual queen mobility
- [X] King safety
- [X] Virtual king mobility
- [ ] Pawn shield
- [ ] Pawn storm
- [X] King zone attacks
@ -72,10 +73,10 @@ List of features that are either already implemented or planned
- [X] Rook on (semi-)open file
- [ ] Queen on (semi-)open file
- [ ] Connected rooks
- [ ] Threats
- [ ] Pieces attacked by pawns
- [ ] Major pieces attacked by minor pieces
- [ ] Queens attacked by rooks
- [X] Threats
- [X] Pieces attacked by pawns
- [X] Major pieces attacked by minor pieces
- [X] Queens attacked by rooks
- [X] Pawn structure
- [X] Isolated pawns
- [X] Strong (aka protected) pawns

View File

@ -267,10 +267,8 @@ proc evaluate*(position: Position, mode: static EvalMode, features: Features = F
of Knight:
features.knightMobility[mobilityMoves].mg += scaledMiddleGame * side
features.knightMobility[mobilityMoves].eg += scaledEndGame * side
#[
features.minorMajorThreats.mg += side * attacksOnMajors.float * scaledMiddleGame
features.minorMajorThreats.eg += side * attacksOnMajors.float * scaledEndGame
]#
of Rook:
features.rookMobility[mobilityMoves].mg += scaledMiddleGame * side
features.rookMobility[mobilityMoves].eg += scaledEndGame * side

View File

@ -662,13 +662,20 @@ proc search(self: SearchManager, depth, ply: int, alpha, beta: Score, isPV: bool
var
bestMove = nullMove()
bestScore = lowestEval()
skipQuiets = false
# playedMoves counts how many moves we called makeMove() on, while i is more like an
# index in the move list (even though that's really not an explicit list anymore)
playedMoves = 0
i = 0
alpha = alpha
failedLow: seq[Move] = @[]
var i = 0
for move in self.pickMoves(hashMove, ply):
if ply == 0 and self.searchMoves.len() > 0 and move notin self.searchMoves:
inc(i)
continue
if skipQuiets and move.isQuiet():
inc(i)
continue
# Ensures we don't prune moves that stave off checkmate
let isNotMated = bestScore > -mateScore() + MAX_DEPTH
if not isPV and move.isQuiet() and depth <= FP_DEPTH_LIMIT and staticEval + FP_EVAL_MARGIN * (depth + improving.int) < alpha and isNotMated:
@ -680,8 +687,8 @@ proc search(self: SearchManager, depth, ply: int, alpha, beta: Score, isPV: bool
inc(i)
continue
when defined(LMP):
if ply > 0 and move.isQuiet() and isNotMated and i >= (LMP_DEPTH_OFFSET + depth * depth) #[div (2 - improving.int)]#:
# Late move pruning: prune quiets when we've analyzed enough moves. Since the optimization
if ply > 0 and move.isQuiet() and isNotMated and playedMoves >= (LMP_DEPTH_OFFSET + depth * depth) #[div (2 - improving.int)]#:
# Late move pruning: prune quiets when we've played enough moves. Since the optimization
# is unsound, we want to make sure we don't accidentally miss a move that staves off
# checkmate
inc(i)
@ -726,6 +733,7 @@ proc search(self: SearchManager, depth, ply: int, alpha, beta: Score, isPV: bool
# since there's no value between alpha and beta (which is alpha + 1)
score = -self.search(depth - 1, ply + 1, -beta, -alpha, isPV)
inc(i)
inc(playedMoves)
self.board.unmakeMove()
# When a search is cancelled or times out, we need
# to make sure the entire call stack unwinds back

View File

@ -27,210 +27,210 @@ const
PAWN_MIDDLEGAME_SCORES: array[Square(0)..Square(63), Weight] = [
0, 0, 0, 0, 0, 0, 0, 0,
150, 180, 136, 154, 205, 161, 95, -23,
24, 34, 124, 111, 161, 212, 143, 82,
-12, 23, 28, 53, 94, 80, 32, 29,
-25, -3, 26, 54, 60, 44, 2, -1,
-35, -20, -1, 8, 32, 19, 29, 11,
-14, 7, 10, 16, 36, 49, 52, 18,
135, 188, 150, 157, 201, 150, 79, -43,
29, 33, 134, 109, 161, 218, 129, 85,
-16, 17, 32, 43, 89, 80, 29, 25,
-26, -7, 22, 53, 60, 45, 3, -2,
-39, -18, -1, 4, 31, 23, 28, 12,
-10, 0, 13, 19, 39, 51, 51, 14,
0, 0, 0, 0, 0, 0, 0, 0
]
PAWN_ENDGAME_SCORES: array[Square(0)..Square(63), Weight] = [
0, 0, 0, 0, 0, 0, 0, 0,
273, 296, 273, 202, 249, 199, 209, 236,
180, 251, 193, 217, 167, 110, 198, 176,
130, 112, 89, 63, 61, 55, 97, 89,
77, 80, 50, 43, 44, 33, 55, 40,
61, 51, 51, 70, 70, 45, 41, 33,
90, 77, 78, 84, 126, 68, 55, 39,
269, 308, 275, 206, 249, 193, 208, 232,
176, 238, 189, 208, 171, 112, 198, 182,
126, 114, 90, 58, 59, 53, 90, 90,
77, 84, 45, 48, 46, 34, 56, 35,
64, 59, 54, 73, 70, 43, 40, 31,
88, 77, 73, 84, 125, 73, 55, 37,
0, 0, 0, 0, 0, 0, 0, 0
]
PASSED_PAWN_MIDDLEGAME_BONUSES: array[Square(0)..Square(63), Weight] = [
0, 0, 0, 0, 0, 0, 0, 0,
43, 92, 89, 92, 16, 67, 81, 51,
65, 93, -6, 35, 24, -12, 35, -46,
43, 30, 43, 12, -6, 15, -8, 4,
25, 1, -20, -29, -52, -16, 13, 5,
5, -29, -30, -30, -30, -22, -21, 39,
-18, -8, -41, -15, 0, -33, 14, 20,
42, 91, 83, 97, -4, 55, 60, 61,
88, 110, 15, 35, 3, -5, 2, -47,
46, 30, 36, 9, -10, 18, -14, -1,
12, 5, -13, -31, -52, -14, 5, 12,
3, -34, -40, -25, -38, -23, -25, 22,
-18, -2, -33, -37, 10, -24, 20, 14,
0, 0, 0, 0, 0, 0, 0, 0
]
PASSED_PAWN_ENDGAME_BONUSES: array[Square(0)..Square(63), Weight] = [
0, 0, 0, 0, 0, 0, 0, 0,
220, 215, 190, 146, 110, 172, 253, 238,
279, 260, 182, 70, 88, 206, 208, 273,
177, 192, 120, 94, 107, 131, 169, 156,
110, 102, 78, 65, 77, 83, 124, 107,
18, 58, 44, -2, 16, 30, 71, 18,
13, 15, 13, -33, -39, 1, 11, 7,
220, 214, 185, 152, 114, 178, 244, 247,
269, 260, 192, 65, 98, 189, 214, 281,
174, 191, 123, 97, 105, 121, 168, 170,
107, 110, 74, 62, 86, 85, 116, 105,
19, 58, 37, 2, 17, 21, 69, 17,
16, 19, 14, -14, -52, -2, 5, 17,
0, 0, 0, 0, 0, 0, 0, 0
]
ISOLATED_PAWN_MIDDLEGAME_BONUSES: array[Square(0)..Square(63), Weight] = [
0, 0, 0, 0, 0, 0, 0, 0,
37, 42, 52, 66, 18, 4, -52, -50,
13, 20, 5, 12, -11, -8, 51, -21,
22, 5, -5, -9, -11, 30, 53, 14,
-1, -7, -50, -46, -32, -23, -8, -8,
-14, -21, -44, -18, -58, -31, -37, -47,
-27, -42, -27, -76, -76, -35, -22, -55,
22, 42, 41, 84, 16, 3, -43, -58,
22, 23, 5, 4, -15, 2, 41, -15,
12, 8, 0, -4, -11, 37, 57, 12,
-3, -15, -55, -49, -40, -21, 6, -15,
-17, -16, -46, -14, -63, -27, -44, -48,
-24, -39, -28, -81, -67, -31, -28, -58,
0, 0, 0, 0, 0, 0, 0, 0
]
ISOLATED_PAWN_ENDGAME_BONUSES: array[Square(0)..Square(63), Weight] = [
0, 0, 0, 0, 0, 0, 0, 0,
52, -49, 49, 51, 57, 79, 94, 89,
-7, -69, -18, 5, -1, -11, -22, -32,
-31, -64, -43, -40, -46, -46, -67, -45,
-17, -40, -25, -36, -54, -34, -40, -17,
-15, -28, -31, -26, -37, -32, -22, -9,
-17, -4, -36, -4, -39, -19, -27, 1,
51, -50, 56, 50, 56, 67, 71, 87,
-7, -68, -25, 8, -5, -8, -22, -44,
-30, -66, -40, -42, -52, -57, -66, -38,
-7, -34, -19, -44, -48, -32, -40, -19,
-12, -26, -20, -31, -36, -28, -26, -10,
-23, -10, -36, -2, -41, -19, -32, 0,
0, 0, 0, 0, 0, 0, 0, 0
]
KNIGHT_MIDDLEGAME_SCORES: array[Square(0)..Square(63), Weight] = [
-176, -111, -19, 66, 87, 37, -8, -92,
28, 71, 130, 146, 102, 214, 78, 102,
56, 131, 169, 169, 220, 211, 159, 96,
81, 99, 135, 210, 142, 194, 80, 146,
56, 78, 118, 127, 148, 135, 142, 93,
2, 52, 78, 96, 131, 106, 104, 65,
-4, 14, 48, 91, 91, 55, 37, 58,
-82, 22, -12, 40, 52, 43, 39, -40
-187, -123, -35, 62, 88, 38, -3, -85,
-2, 43, 81, 111, 95, 192, 92, 97,
47, 128, 151, 175, 185, 198, 133, 103,
74, 94, 142, 207, 147, 192, 71, 148,
51, 71, 116, 130, 146, 141, 145, 91,
10, 61, 86, 101, 133, 108, 103, 71,
-10, 22, 50, 93, 101, 63, 43, 56,
-76, 26, -8, 33, 54, 44, 45, -9
]
KNIGHT_ENDGAME_SCORES: array[Square(0)..Square(63), Weight] = [
-16, 55, 82, 61, 85, 24, 62, -81,
69, 93, 93, 93, 81, 60, 83, 40,
100, 93, 144, 136, 111, 110, 76, 72,
101, 126, 165, 159, 169, 153, 138, 97,
128, 130, 173, 163, 162, 131, 117, 115,
92, 102, 117, 149, 132, 97, 84, 110,
111, 99, 98, 104, 92, 91, 83, 126,
76, 80, 80, 96, 90, 60, 89, 115
-35, 49, 83, 53, 87, 13, 28, -99,
65, 83, 99, 82, 74, 49, 64, 35,
83, 89, 148, 136, 124, 111, 79, 71,
99, 123, 167, 156, 161, 157, 128, 95,
132, 123, 167, 153, 165, 145, 116, 106,
95, 94, 121, 154, 135, 94, 95, 108,
112, 103, 92, 99, 101, 87, 94, 126,
79, 77, 80, 95, 94, 68, 81, 112
]
BISHOP_MIDDLEGAME_SCORES: array[Square(0)..Square(63), Weight] = [
46, 6, 2, -64, -7, 8, 31, -3,
73, 122, 84, 74, 118, 97, 76, 84,
84, 130, 134, 154, 140, 168, 141, 117,
72, 119, 132, 177, 170, 133, 116, 72,
80, 77, 117, 169, 155, 103, 101, 116,
80, 136, 126, 130, 132, 133, 132, 124,
117, 128, 148, 101, 132, 120, 147, 127,
89, 152, 96, 69, 70, 67, 95, 122
71, 0, -21, -35, -6, 9, 32, -7,
77, 71, 80, 77, 71, 82, 48, 83,
77, 118, 118, 145, 129, 169, 127, 115,
56, 124, 118, 180, 166, 138, 118, 81,
86, 65, 112, 163, 154, 110, 98, 109,
80, 136, 130, 134, 130, 133, 126, 128,
107, 128, 152, 106, 134, 127, 149, 127,
91, 159, 102, 67, 76, 65, 92, 127
]
BISHOP_ENDGAME_SCORES: array[Square(0)..Square(63), Weight] = [
135, 147, 141, 142, 147, 122, 138, 109,
105, 132, 135, 134, 125, 132, 150, 98,
145, 150, 161, 125, 143, 158, 142, 150,
141, 157, 159, 176, 161, 160, 149, 138,
141, 170, 170, 165, 171, 164, 150, 104,
137, 149, 155, 155, 174, 151, 137, 124,
153, 113, 103, 138, 134, 123, 125, 118,
124, 130, 123, 123, 122, 152, 135, 85
137, 139, 141, 153, 150, 126, 133, 115,
110, 140, 128, 132, 115, 124, 146, 96,
160, 135, 154, 128, 128, 161, 136, 153,
152, 159, 160, 174, 153, 166, 146, 139,
136, 167, 174, 172, 163, 150, 139, 115,
149, 149, 153, 163, 175, 155, 137, 128,
158, 111, 115, 136, 133, 118, 128, 109,
125, 119, 122, 125, 114, 161, 129, 89
]
ROOK_MIDDLEGAME_SCORES: array[Square(0)..Square(63), Weight] = [
149, 125, 132, 125, 135, 165, 153, 182,
138, 135, 170, 209, 178, 233, 206, 229,
125, 194, 185, 201, 248, 246, 323, 247,
113, 153, 157, 173, 190, 206, 218, 191,
95, 88, 113, 150, 144, 119, 191, 158,
99, 108, 119, 134, 149, 161, 229, 187,
101, 109, 143, 158, 164, 159, 195, 135,
146, 147, 155, 169, 172, 145, 178, 153
147, 119, 129, 117, 140, 158, 124, 179,
151, 132, 178, 207, 173, 219, 214, 243,
134, 193, 185, 187, 262, 250, 343, 246,
110, 165, 149, 172, 190, 202, 212, 203,
96, 97, 107, 142, 145, 126, 185, 161,
100, 101, 120, 145, 149, 163, 230, 174,
102, 113, 141, 151, 167, 151, 196, 137,
147, 152, 158, 165, 174, 145, 174, 151
]
ROOK_ENDGAME_SCORES: array[Square(0)..Square(63), Weight] = [
333, 329, 340, 327, 316, 323, 333, 310,
318, 343, 341, 318, 314, 313, 307, 274,
318, 306, 307, 298, 271, 271, 256, 266,
311, 312, 321, 303, 267, 269, 266, 270,
304, 315, 304, 292, 283, 281, 254, 262,
285, 287, 279, 267, 250, 234, 193, 222,
271, 270, 261, 256, 242, 240, 201, 236,
293, 285, 279, 271, 253, 271, 250, 259
314, 333, 340, 338, 321, 323, 329, 312,
315, 336, 343, 310, 312, 294, 297, 273,
310, 307, 304, 293, 266, 263, 251, 259,
326, 303, 325, 300, 263, 267, 267, 261,
309, 309, 300, 283, 283, 272, 256, 254,
290, 292, 276, 268, 239, 243, 190, 217,
274, 276, 261, 257, 241, 237, 216, 222,
296, 277, 289, 275, 254, 274, 246, 263
]
QUEEN_MIDDLEGAME_SCORES: array[Square(0)..Square(63), Weight] = [
303, 323, 410, 437, 409, 443, 450, 371,
362, 292, 303, 329, 310, 359, 323, 443,
353, 348, 360, 360, 376, 422, 426, 396,
342, 348, 337, 335, 346, 370, 387, 380,
349, 337, 341, 356, 364, 359, 382, 391,
345, 365, 357, 350, 357, 378, 408, 394,
368, 369, 387, 396, 398, 388, 401, 425,
336, 347, 366, 384, 373, 324, 356, 372
308, 349, 401, 428, 423, 447, 453, 378,
356, 297, 307, 340, 321, 363, 352, 440,
365, 367, 361, 357, 389, 421, 427, 400,
336, 350, 346, 338, 353, 369, 382, 371,
341, 334, 339, 363, 366, 358, 373, 393,
342, 364, 359, 361, 364, 387, 405, 396,
366, 359, 383, 393, 396, 389, 410, 420,
327, 341, 359, 380, 380, 325, 368, 357
]
QUEEN_ENDGAME_SCORES: array[Square(0)..Square(63), Weight] = [
633, 625, 661, 639, 664, 622, 601, 603,
630, 694, 753, 734, 775, 730, 699, 685,
632, 654, 721, 752, 755, 728, 680, 690,
667, 694, 717, 759, 782, 737, 764, 721,
665, 703, 713, 749, 736, 742, 719, 699,
632, 676, 692, 698, 706, 692, 654, 654,
615, 597, 610, 629, 630, 570, 517, 514,
607, 601, 600, 628, 580, 565, 549, 576
625, 635, 634, 642, 658, 630, 575, 609,
630, 692, 736, 733, 789, 721, 689, 676,
634, 641, 714, 753, 750, 723, 673, 687,
657, 697, 724, 759, 769, 761, 762, 731,
668, 712, 724, 742, 734, 735, 718, 714,
620, 674, 704, 693, 715, 697, 651, 648,
614, 609, 609, 628, 633, 566, 525, 524,
623, 603, 613, 640, 569, 576, 566, 561
]
KING_MIDDLEGAME_SCORES: array[Square(0)..Square(63), Weight] = [
-156, -114, -89, -113, -99, -33, 63, -25,
-134, 42, -22, 58, -1, 55, 126, 21,
-152, 114, -8, -13, 72, 156, 77, -49,
-117, -32, -41, -128, -99, -40, -69, -214,
-106, -35, -67, -150, -138, -61, -103, -251,
-53, 41, -33, -49, -36, -38, 1, -123,
42, 43, 28, -28, -30, -4, 78, 17,
-20, 100, 52, -114, -3, -83, 50, -13
-116, -122, -68, -138, -102, -23, 48, 4,
-138, 43, -45, 82, 14, 37, 138, 56,
-162, 103, -2, -22, 55, 172, 79, -54,
-128, -8, -18, -112, -96, -30, -58, -197,
-129, -23, -50, -151, -138, -61, -105, -260,
-74, 40, -25, -62, -31, -43, -2, -126,
59, 42, 36, -34, -33, -8, 75, 13,
-14, 109, 49, -117, -7, -78, 53, -11
]
KING_ENDGAME_SCORES: array[Square(0)..Square(63), Weight] = [
-198, -89, -75, -6, -9, -3, -33, -199,
-67, 29, 67, 85, 107, 97, 66, -11,
-29, 55, 123, 156, 160, 140, 101, -3,
-42, 59, 128, 198, 209, 150, 90, 6,
-62, 23, 119, 186, 179, 113, 48, -12,
-81, -10, 55, 97, 90, 56, -6, -43,
-95, -33, -4, 25, 31, 9, -41, -96,
-160, -136, -78, -51, -87, -58, -116, -177
-204, -108, -75, -3, -24, -19, -36, -197,
-65, 36, 75, 79, 92, 116, 70, -12,
-28, 57, 126, 169, 166, 151, 98, -4,
-50, 56, 136, 202, 193, 157, 87, 11,
-65, 31, 109, 178, 182, 107, 47, -14,
-83, -8, 60, 97, 92, 53, -8, -45,
-105, -32, -7, 19, 27, 7, -42, -93,
-166, -138, -80, -46, -87, -55, -109, -184
]
# Piece weights
MIDDLEGAME_WEIGHTS: array[PieceKind.Bishop..PieceKind.Rook, Weight] = [387, 0, 389, 123, 929, 496]
ENDGAME_WEIGHTS: array[PieceKind.Bishop..PieceKind.Rook, Weight] = [418, 0, 422, 173, 1004, 671]
MIDDLEGAME_WEIGHTS: array[PieceKind.Bishop..PieceKind.Rook, Weight] = [387, 0, 387, 123, 928, 497]
ENDGAME_WEIGHTS: array[PieceKind.Bishop..PieceKind.Rook, Weight] = [416, 0, 424, 174, 1004, 668]
# Flat bonuses (middlegame, endgame)
ROOK_OPEN_FILE_BONUS*: tuple[mg, eg: Weight] = (81, 26)
ROOK_SEMI_OPEN_FILE_BONUS*: tuple[mg, eg: Weight] = (32, 23)
ROOK_OPEN_FILE_BONUS*: tuple[mg, eg: Weight] = (83, 27)
ROOK_SEMI_OPEN_FILE_BONUS*: tuple[mg, eg: Weight] = (29, 28)
DOUBLED_PAWNS_BONUS*: tuple[mg, eg: Weight] = (0, 0)
BISHOP_PAIR_BONUS*: tuple[mg, eg: Weight] = (62, 147)
BISHOP_PAIR_BONUS*: tuple[mg, eg: Weight] = (62, 146)
CONNECTED_ROOKS_BONUS*: tuple[mg, eg: Weight] = (0, 0)
STRONG_PAWNS_BONUS*: tuple[mg, eg: Weight] = (22, 24)
PAWN_THREATS_MINOR_BONUS*: tuple[mg, eg: Weight] = (0, 0)
PAWN_THREATS_MAJOR_BONUS*: tuple[mg, eg: Weight] = (0, 0)
MINOR_THREATS_MAJOR_BONUS*: tuple[mg, eg: Weight] = (0, 0)
ROOK_THREATS_QUEEN_BONUS*: tuple[mg, eg: Weight] = (0, 0)
STRONG_PAWNS_BONUS*: tuple[mg, eg: Weight] = (24, 19)
PAWN_THREATS_MINOR_BONUS*: tuple[mg, eg: Weight] = (17, -43)
PAWN_THREATS_MAJOR_BONUS*: tuple[mg, eg: Weight] = (10, -29)
MINOR_THREATS_MAJOR_BONUS*: tuple[mg, eg: Weight] = (91, -8)
ROOK_THREATS_QUEEN_BONUS*: tuple[mg, eg: Weight] = (182, -152)
# Tapered mobility bonuses
BISHOP_MOBILITY_MIDDLEGAME_BONUS: array[14, Weight] = [106, 132, 158, 171, 193, 199, 210, 213, 217, 226, 238, 257, 247, 183]
BISHOP_MOBILITY_ENDGAME_BONUS: array[14, Weight] = [88, 121, 159, 191, 220, 248, 260, 263, 264, 263, 258, 258, 282, 249]
KNIGHT_MOBILITY_MIDDLEGAME_BONUS: array[9, Weight] = [95, 137, 161, 172, 182, 199, 210, 224, 244]
KNIGHT_MOBILITY_ENDGAME_BONUS: array[9, Weight] = [74, 137, 188, 215, 243, 258, 254, 245, 224]
ROOK_MOBILITY_MIDDLEGAME_BONUS: array[15, Weight] = [171, 193, 195, 206, 196, 213, 216, 218, 224, 224, 238, 231, 237, 229, 169]
ROOK_MOBILITY_ENDGAME_BONUS: array[15, Weight] = [288, 347, 361, 370, 388, 400, 409, 420, 426, 437, 435, 441, 441, 434, 462]
QUEEN_MOBILITY_MIDDLEGAME_BONUS: array[28, Weight] = [411, 446, 428, 435, 438, 445, 453, 456, 465, 463, 468, 473, 476, 477, 479, 496, 498, 513, 546, 583, 617, 701, 700, 698, 732, 686, 555, 560]
QUEEN_MOBILITY_ENDGAME_BONUS: array[28, Weight] = [314, 401, 523, 580, 647, 672, 709, 764, 780, 786, 806, 829, 832, 854, 854, 866, 877, 865, 849, 838, 812, 800, 773, 779, 756, 739, 607, 571]
KING_MOBILITY_MIDDLEGAME_BONUS: array[28, Weight] = [0, 0, 0, 140, 156, 112, 82, 59, 40, 20, 20, -12, -19, -42, -65, -99, -132, -167, -199, -217, -226, -249, -246, -251, -319, -272, -285, -248]
KING_MOBILITY_ENDGAME_BONUS: array[28, Weight] = [0, 0, 0, -11, -53, 5, 3, -8, -4, -6, -9, 15, 8, 21, 19, 29, 30, 27, 27, 10, 9, -9, -31, -44, -52, -98, -108, -152]
BISHOP_MOBILITY_MIDDLEGAME_BONUS: array[14, Weight] = [103, 130, 159, 173, 191, 197, 208, 213, 216, 223, 239, 237, 205, 203]
BISHOP_MOBILITY_ENDGAME_BONUS: array[14, Weight] = [89, 125, 161, 191, 217, 246, 250, 261, 268, 266, 255, 259, 272, 257]
KNIGHT_MOBILITY_MIDDLEGAME_BONUS: array[9, Weight] = [90, 136, 157, 169, 182, 192, 207, 227, 246]
KNIGHT_MOBILITY_ENDGAME_BONUS: array[9, Weight] = [57, 136, 187, 216, 235, 254, 256, 249, 214]
ROOK_MOBILITY_MIDDLEGAME_BONUS: array[15, Weight] = [164, 193, 197, 206, 199, 213, 216, 212, 229, 229, 232, 233, 235, 230, 184]
ROOK_MOBILITY_ENDGAME_BONUS: array[15, Weight] = [281, 343, 357, 372, 390, 399, 411, 415, 423, 434, 437, 447, 449, 432, 459]
QUEEN_MOBILITY_MIDDLEGAME_BONUS: array[28, Weight] = [386, 439, 420, 427, 437, 445, 454, 451, 466, 463, 469, 472, 485, 483, 489, 492, 502, 518, 552, 574, 627, 702, 677, 685, 739, 701, 552, 549]
QUEEN_MOBILITY_ENDGAME_BONUS: array[28, Weight] = [280, 366, 528, 597, 656, 673, 720, 762, 779, 795, 817, 823, 831, 845, 850, 857, 875, 868, 851, 838, 822, 794, 791, 772, 758, 737, 615, 568]
KING_MOBILITY_MIDDLEGAME_BONUS: array[28, Weight] = [0, 0, 0, 127, 163, 112, 81, 61, 39, 23, 16, -5, -17, -45, -68, -94, -125, -162, -205, -226, -237, -238, -243, -261, -304, -269, -290, -221]
KING_MOBILITY_ENDGAME_BONUS: array[28, Weight] = [0, 0, 0, -31, -52, 3, -1, -14, -4, -3, -4, 19, 10, 21, 24, 31, 28, 25, 27, 19, 4, -10, -27, -48, -68, -96, -116, -147]
KING_ZONE_ATTACKS_MIDDLEGAME_BONUS*: array[9, Weight] = [97, 87, 47, -30, -135, -232, -322, -361, -459]
KING_ZONE_ATTACKS_ENDGAME_BONUS*: array[9, Weight] = [-27, -16, -13, -12, 1, 20, 43, 33, 43]
KING_ZONE_ATTACKS_MIDDLEGAME_BONUS*: array[9, Weight] = [102, 86, 43, -30, -132, -233, -326, -372, -465]
KING_ZONE_ATTACKS_ENDGAME_BONUS*: array[9, Weight] = [-29, -27, -8, -9, 6, 23, 42, 46, 38]
MIDDLEGAME_PSQ_TABLES: array[PieceKind.Bishop..PieceKind.Rook, array[Square(0)..Square(63), Weight]] = [
BISHOP_MIDDLEGAME_SCORES,

24
tune.py
View File

@ -59,9 +59,9 @@ type
const
TEMPO_BONUS* = Weight(10)
PAWN_MIDDLEGAME_WeightS: array[Square(0)..Square(63), Weight] = {pawn_mg}
PAWN_MIDDLEGAME_SCORES: array[Square(0)..Square(63), Weight] = {pawn_mg}
PAWN_ENDGAME_WeightS: array[Square(0)..Square(63), Weight] = {pawn_eg}
PAWN_ENDGAME_SCORES: array[Square(0)..Square(63), Weight] = {pawn_eg}
PASSED_PAWN_MIDDLEGAME_BONUSES: array[Square(0)..Square(63), Weight] = {passed_pawns_mg}
@ -71,25 +71,25 @@ const
ISOLATED_PAWN_ENDGAME_BONUSES: array[Square(0)..Square(63), Weight] = {isolated_pawns_eg}
KNIGHT_MIDDLEGAME_WeightS: array[Square(0)..Square(63), Weight] = {knight_mg}
KNIGHT_MIDDLEGAME_SCORES: array[Square(0)..Square(63), Weight] = {knight_mg}
KNIGHT_ENDGAME_WeightS: array[Square(0)..Square(63), Weight] = {knight_eg}
KNIGHT_ENDGAME_SCORES: array[Square(0)..Square(63), Weight] = {knight_eg}
BISHOP_MIDDLEGAME_WeightS: array[Square(0)..Square(63), Weight] = {bishop_mg}
BISHOP_MIDDLEGAME_SCORES: array[Square(0)..Square(63), Weight] = {bishop_mg}
BISHOP_ENDGAME_WeightS: array[Square(0)..Square(63), Weight] = {bishop_eg}
BISHOP_ENDGAME_SCORES: array[Square(0)..Square(63), Weight] = {bishop_eg}
ROOK_MIDDLEGAME_WeightS: array[Square(0)..Square(63), Weight] = {rook_mg}
ROOK_MIDDLEGAME_SCORES: array[Square(0)..Square(63), Weight] = {rook_mg}
ROOK_ENDGAME_WeightS: array[Square(0)..Square(63), Weight] = {rook_eg}
ROOK_ENDGAME_SCORES: array[Square(0)..Square(63), Weight] = {rook_eg}
QUEEN_MIDDLEGAME_WeightS: array[Square(0)..Square(63), Weight] = {queen_mg}
QUEEN_MIDDLEGAME_SCORES: array[Square(0)..Square(63), Weight] = {queen_mg}
QUEEN_ENDGAME_WeightS: array[Square(0)..Square(63), Weight] = {queen_eg}
QUEEN_ENDGAME_SCORES: array[Square(0)..Square(63), Weight] = {queen_eg}
KING_MIDDLEGAME_WeightS: array[Square(0)..Square(63), Weight] = {king_mg}
KING_MIDDLEGAME_SCORES: array[Square(0)..Square(63), Weight] = {king_mg}
KING_ENDGAME_WeightS: array[Square(0)..Square(63), Weight] = {king_eg}
KING_ENDGAME_SCORES: array[Square(0)..Square(63), Weight] = {king_eg}
# Piece weights
MIDDLEGAME_WEIGHTS: array[PieceKind.Bishop..PieceKind.Rook, Weight] = {pieces_mg}