Nonfunctional changes, update ratings (bench 5736541)
This commit is contained in:
12
README.md
12
README.md
@@ -200,17 +200,17 @@ me if you want me to add yours)
|
||||
| 0.1 | 2531 | - | 2436 | - | - | N/A | N/A | - | - | - | - | - | - |
|
||||
| 0.2 | 2706 | - | 2669 | - | - | N/A | N/A | - | - | - | - | - | - |
|
||||
| 0.3 | 2837 | - | - | - | - | N/A | N/A | - | - | - | - | - | - |
|
||||
| 0.4 | 2888 | - | 2857 | - | - | 2928 | - | - | - | - | - | - | - |
|
||||
| 0.4 | 2888 | - | 2859 | - | - | 2928 | - | - | - | - | - | - | - |
|
||||
| 1.0 | 3230 | 3163* | 3193 | - | - | 3374 | - | - | - | - | - | - | - |
|
||||
| 1.1 | 3370 | - | - | - | - | - | - | - | - | - | - | - | - |
|
||||
| 1.1.1 | 3390** | - | 3363 | - | - | 3560 | - | 3386 | - | 3456 | - | 3283 | 3266 |
|
||||
| 1.1.1 | 3390** | - | 3364 | - | - | 3560 | - | 3386 | - | 3456 | - | 3283 | 3266 |
|
||||
| 1.2 | 3490 | - | - | - | - | - | - | - | - | 3470 | - | - | - |
|
||||
| 1.2.{1,2} | 3500 | - | 3376 | 3440 | - | 3622 | - | 3469 | - | 3479 | 3297 | - | |
|
||||
| 1.2.{1,2} | 3500 | - | 3377 | 3440 | - | 3622 | - | 3469 | - | 3479 | 3297 | - | |
|
||||
| 1.3 | 3548*** | - | 3419 | - | - | - | - | 3512 | - | - | 3341 | - | 3373 |
|
||||
| 1.3.{1,2} | 3530 | 3307**** | 3423 | - | - | 3717 | - | - | 3581 | - | - | - | - |
|
||||
| 1.4 | 3626 | - | 3493 | 3549 | - | 3818 | 3482\*\*\*\*\* | - | - | - | 3439 | - | - |
|
||||
| 1.4.1 | 3659 | - | 3514 | - | - | - | - | 3622 | - | - | 3468 | - | - |
|
||||
| 1.4.2 | 3660 | - | 3502 | 3569 | 3542 | - | - | - | - | - | - | - | - |
|
||||
| 1.4 | 3626 | - | 3494 | 3550 | - | 3818 | 3481\*\*\*\*\* | - | - | - | 3439 | - | - |
|
||||
| 1.4.1 | 3659 | - | 3515 | - | - | - | - | 3622 | - | - | 3468 | - | - |
|
||||
| 1.4.2 | 3660 | - | 3502 | 3565 | 3542 | - | - | - | - | - | - | - | - |
|
||||
|
||||
*: Beta version, not final 1.0 release
|
||||
|
||||
|
||||
@@ -82,17 +82,14 @@ func lowestBit*(self: Bitboard): Bitboard {.inline.} =
|
||||
func createMove*(startSquare: Bitboard, targetSquare: Square, flag: MoveFlag = Normal): Move {.inline, noinit.} =
|
||||
result = createMove(startSquare.toSquare(), targetSquare, flag)
|
||||
|
||||
|
||||
func createMove*(startSquare: Square, targetSquare: Bitboard, flag: MoveFlag = Normal): Move {.inline, noinit.} =
|
||||
result = createMove(startSquare, targetSquare.toSquare(), flag)
|
||||
|
||||
|
||||
func createMove*(startSquare, targetSquare: Bitboard, flag: MoveFlag = Normal): Move {.inline, noinit.} =
|
||||
result = createMove(startSquare.toSquare(), targetSquare.toSquare(), flag)
|
||||
|
||||
|
||||
func toBin*(x: Bitboard, b: Positive = 64): string {.inline.} = toBin(BiggestInt(x), b)
|
||||
func toBin*(x: uint64, b: Positive = 64): string {.inline.} = toBin(Bitboard(x), b)
|
||||
func toBin*(x: Bitboard, b: Positive = 64): string {.inline.} = toBin(BiggestInt(x), b)
|
||||
func toBin*(x: uint64, b: Positive = 64): string {.inline.} = toBin(Bitboard(x), b)
|
||||
func contains*(self: Bitboard, square: Square): bool {.inline.} = not (self and square.toBitboard()).isEmpty()
|
||||
|
||||
|
||||
@@ -127,22 +124,19 @@ iterator pairs*(self: Bitboard): tuple[i: int, sq: Square] =
|
||||
|
||||
|
||||
func pretty*(self: Bitboard): string =
|
||||
## Returns a prettyfied version of
|
||||
## the given bitboard
|
||||
|
||||
iterator items(self: Bitboard): uint8 =
|
||||
## Iterates over all the bits in the
|
||||
## given bitboard
|
||||
for i in 0..63:
|
||||
yield self.uint64.bitsliced(i..i).uint8
|
||||
|
||||
|
||||
iterator pairs(self: Bitboard): (int, uint8) =
|
||||
var i = 0
|
||||
for bit in self:
|
||||
yield (i, bit)
|
||||
inc(i)
|
||||
|
||||
## Returns a prettyfied version of
|
||||
## the given bitboard
|
||||
result &= "- - - - - - - -\n"
|
||||
for i, bit in self:
|
||||
if i > 0 and i mod 8 == 0:
|
||||
@@ -177,10 +171,11 @@ const shifters: array[White..Black, array[Direction, (Bitboard) {.noSideEffect.}
|
||||
|
||||
|
||||
func directionMask*(bitboard: Bitboard, color: PieceColor, direction: Direction): Bitboard {.inline.} =
|
||||
## Get a bitmask relative to the given bitboard
|
||||
## for the given direction for a piece of the
|
||||
## given color
|
||||
return shifters[color][direction](bitboard)
|
||||
shifters[color][direction](bitboard)
|
||||
|
||||
func directionMask*(square: Square, color: PieceColor, direction: Direction): Bitboard {.inline.} =
|
||||
directionMask(square.toBitboard(), color, direction)
|
||||
|
||||
|
||||
const relativeRanks: array[White..Black, array[Rank, Rank]] = [[Rank(7), Rank(6), Rank(5), Rank(4), Rank(3), Rank(2), Rank(1), Rank(0)], [Rank(0), Rank(1), Rank(2), Rank(3), Rank(4), Rank(5), Rank(6), Rank(7)]]
|
||||
|
||||
@@ -196,27 +191,21 @@ const
|
||||
rightmostFiles: array[White..Black, Bitboard] = [fileMask(pieces.File(7)), fileMask(pieces.File(0))]
|
||||
|
||||
|
||||
func eighthRank*(color: PieceColor): Bitboard {.inline.} = eighthRanks[color]
|
||||
func firstRank*(color: PieceColor): Bitboard {.inline.} = firstRanks[color]
|
||||
func seventhRank*(color: PieceColor): Bitboard {.inline.} = seventhRanks[color]
|
||||
func secondRank*(color: PieceColor): Bitboard {.inline.} = secondRanks[color]
|
||||
func leftmostFile*(color: PieceColor): Bitboard {.inline.}= leftmostFiles[color]
|
||||
func eighthRank*(color: PieceColor): Bitboard {.inline.} = eighthRanks[color]
|
||||
func firstRank*(color: PieceColor): Bitboard {.inline.} = firstRanks[color]
|
||||
func seventhRank*(color: PieceColor): Bitboard {.inline.} = seventhRanks[color]
|
||||
func secondRank*(color: PieceColor): Bitboard {.inline.} = secondRanks[color]
|
||||
func leftmostFile*(color: PieceColor): Bitboard {.inline.} = leftmostFiles[color]
|
||||
func rightmostFile*(color: PieceColor): Bitboard {.inline.} = rightmostFiles[color]
|
||||
|
||||
|
||||
func directionMask*(square: Square, color: PieceColor, direction: Direction): Bitboard {.inline.} =
|
||||
## Get a bitmask for the given direction for a piece
|
||||
## of the given color located at the given square
|
||||
result = directionMask(square.toBitboard(), color, direction)
|
||||
|
||||
|
||||
func forward*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = directionMask(self, side, Forward)
|
||||
func doubleForward*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.forward(side).forward(side)
|
||||
|
||||
func backward*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = directionMask(self, side, Backward)
|
||||
func doubleBackward*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.backward(side).backward(side)
|
||||
|
||||
func left*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = directionMask(self, side, Left) and not rightmostFile(side)
|
||||
func left*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = directionMask(self, side, Left) and not rightmostFile(side)
|
||||
func right*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = directionMask(self, side, Right) and not leftmostFile(side)
|
||||
|
||||
|
||||
@@ -225,34 +214,30 @@ func right*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = directionMa
|
||||
func forwardRight*(self: Bitboard, side: PieceColor): Bitboard {.inline.} =
|
||||
directionMask(self, side, ForwardRight) and not leftmostFile(side)
|
||||
|
||||
|
||||
func forwardLeft*(self: Bitboard, side: PieceColor): Bitboard {.inline.} =
|
||||
directionMask(self, side, ForwardLeft) and not rightmostFile(side)
|
||||
|
||||
|
||||
func backwardRight*(self: Bitboard, side: PieceColor): Bitboard {.inline.} =
|
||||
directionMask(self, side, BackwardRight) and not leftmostFile(side)
|
||||
|
||||
|
||||
func backwardLeft*(self: Bitboard, side: PieceColor): Bitboard {.inline.} =
|
||||
directionMask(self, side, BackwardLeft) and not rightmostFile(side)
|
||||
|
||||
# Knight move helpers
|
||||
|
||||
func longKnightUpLeft*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.doubleForward(side).left(side)
|
||||
func longKnightUpRight*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.doubleForward(side).right(side)
|
||||
func longKnightDownLeft*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.doubleBackward(side).left(side)
|
||||
func longKnightUpLeft*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.doubleForward(side).left(side)
|
||||
func longKnightUpRight*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.doubleForward(side).right(side)
|
||||
func longKnightDownLeft*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.doubleBackward(side).left(side)
|
||||
func longKnightDownRight*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.doubleBackward(side).right(side)
|
||||
|
||||
func shortKnightUpLeft*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.forward(side).left(side).left(side)
|
||||
func shortKnightUpRight*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.forward(side).right(side).right(side)
|
||||
func shortKnightDownLeft*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.backward(side).left(side).left(side)
|
||||
func shortKnightUpLeft*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.forward(side).left(side).left(side)
|
||||
func shortKnightUpRight*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.forward(side).right(side).right(side)
|
||||
func shortKnightDownLeft*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.backward(side).left(side).left(side)
|
||||
func shortKnightDownRight*(self: Bitboard, side: PieceColor): Bitboard {.inline.} = self.backward(side).right(side).right(side)
|
||||
|
||||
# We precompute as much stuff as possible: lookup tables are fast!
|
||||
|
||||
|
||||
func computeKingBitboards: array[Square.smallest()..Square.biggest(), Bitboard] {.compileTime.} =
|
||||
## Precomputes all the movement bitboards for the king
|
||||
for i in Square.all():
|
||||
let king = i.toBitboard()
|
||||
# It doesn't really matter which side we generate
|
||||
@@ -274,7 +259,6 @@ func computeKingBitboards: array[Square.smallest()..Square.biggest(), Bitboard]
|
||||
|
||||
|
||||
func computeKnightBitboards: array[Square.smallest()..Square.biggest(), Bitboard] {.compileTime.} =
|
||||
## Precomputes all the movement bitboards for knights
|
||||
for i in Square.all():
|
||||
let knight = i.toBitboard()
|
||||
# It doesn't really matter which side we generate
|
||||
@@ -292,29 +276,32 @@ func computeKnightBitboards: array[Square.smallest()..Square.biggest(), Bitboard
|
||||
|
||||
|
||||
func computePawnAttackers(color: PieceColor): array[Square.smallest()..Square.biggest(), Bitboard] {.compileTime.} =
|
||||
## Precomputes all the attacker bitboards for pawns
|
||||
## of the given color
|
||||
for i in Square.all():
|
||||
let pawn = i.toBitboard()
|
||||
result[i] = pawn.backwardLeft(color) or pawn.backwardRight(color)
|
||||
|
||||
|
||||
func computePawnAttacks(color: PieceColor): array[Square.smallest()..Square.biggest(), Bitboard] {.compileTime.} =
|
||||
## Precomputes all the attack bitboards for pawns
|
||||
## of the given color
|
||||
for i in Square.all():
|
||||
let pawn = i.toBitboard()
|
||||
result[i] = pawn.forwardLeft(color) or pawn.forwardRight(color)
|
||||
|
||||
func computePawnAttackers: array[White..Black, array[Square.smallest()..Square.biggest(), Bitboard]] {.compileTime.} =
|
||||
for color in White..Black:
|
||||
result[color] = computePawnAttackers(color)
|
||||
|
||||
func computePawnAttacks: array[White..Black, array[Square.smallest()..Square.biggest(), Bitboard]] {.compileTime.} =
|
||||
for color in White..Black:
|
||||
result[color] = computePawnAttacks(color)
|
||||
|
||||
|
||||
const
|
||||
KING_BITBOARDS = computeKingBitboards()
|
||||
KING_BITBOARDS = computeKingBitboards()
|
||||
KNIGHT_BITBOARDS = computeKnightBitboards()
|
||||
PAWN_ATTACKERS: array[White..Black, array[Square.smallest()..Square.biggest(), Bitboard]] = [computePawnAttackers(White), computePawnAttackers(Black)]
|
||||
PAWN_ATTACKS: array[White..Black, array[Square.smallest()..Square.biggest(), Bitboard]] = [computePawnAttacks(White), computePawnAttacks(Black)]
|
||||
PAWN_ATTACKERS = computePawnAttackers()
|
||||
PAWN_ATTACKS = computePawnAttacks()
|
||||
|
||||
|
||||
func kingMoves*(square: Square): Bitboard {.inline.} = KING_BITBOARDS[square]
|
||||
func knightMoves*(square: Square): Bitboard {.inline.} = KNIGHT_BITBOARDS[square]
|
||||
func kingMoves*(square: Square): Bitboard {.inline.} = KING_BITBOARDS[square]
|
||||
func knightMoves*(square: Square): Bitboard {.inline.} = KNIGHT_BITBOARDS[square]
|
||||
func pawnAttackers*(color: PieceColor, square: Square): Bitboard {.inline.} = PAWN_ATTACKERS[color][square]
|
||||
func pawnAttacks*(color: PieceColor, square: Square): Bitboard {.inline.} = PAWN_ATTACKS[color][square]
|
||||
func pawnAttacks*(color: PieceColor, square: Square): Bitboard {.inline.} = PAWN_ATTACKS[color][square]
|
||||
|
||||
@@ -95,7 +95,7 @@ proc newEvalState*(networkPath: string = "", verbose: static bool = true): EvalS
|
||||
network = loadNet(networkPath)
|
||||
|
||||
|
||||
func shouldMirror(kingSq: Square): bool =
|
||||
func shouldMirror(kingSq: Square): bool {.inline.} =
|
||||
## Returns whether the king being on this location
|
||||
## would cause horizontal mirroring of the board
|
||||
when MIRRORED:
|
||||
@@ -104,7 +104,7 @@ func shouldMirror(kingSq: Square): bool =
|
||||
return false
|
||||
|
||||
|
||||
proc kingBucket*(side: PieceColor, square: Square): int =
|
||||
proc kingBucket*(side: PieceColor, square: Square): int {.inline.} =
|
||||
## Returns the input bucket associated with the king
|
||||
## of the given side located at the given square
|
||||
|
||||
@@ -147,7 +147,7 @@ func feature(perspective: PieceColor, color: PieceColor, piece: PieceKind, squar
|
||||
result += bucket * FT_SIZE
|
||||
|
||||
|
||||
proc mustRefresh(self: EvalState, side: PieceColor, prevKingSq, currKingSq: Square): bool =
|
||||
proc mustRefresh(self: EvalState, side: PieceColor, prevKingSq, currKingSq: Square): bool {.inline.} =
|
||||
## Returns whether an accumulator refresh is required for the given side
|
||||
## as opposed to an efficient update
|
||||
if shouldMirror(prevKingSq) != shouldMirror(currKingSq):
|
||||
@@ -266,7 +266,7 @@ func getNextKingSquare(move: Move, piece: PieceKind, sideToMove: PieceColor, pre
|
||||
return previousKingSq
|
||||
|
||||
|
||||
proc update*(self: EvalState, move: Move, sideToMove: PieceColor, piece: PieceKind, captured=Empty, kingSq: Square) =
|
||||
proc update*(self: EvalState, move: Move, sideToMove: PieceColor, piece: PieceKind, captured=Empty, kingSq: Square) {.inline.} =
|
||||
## Enqueues an accumulator update with the given data
|
||||
let nextKingSq = move.getNextKingSquare(piece, sideToMove, kingSq)
|
||||
let needsRefresh = [self.mustRefresh(White, kingSq, nextKingSq), self.mustRefresh(Black, kingSq, nextKingSq)]
|
||||
@@ -384,4 +384,4 @@ proc evaluate*(position: Position, state: EvalState): Score {.inline.} =
|
||||
|
||||
proc evaluate*(board: Chessboard, state: EvalState): Score {.inline.} =
|
||||
## Evaluates the current position in the chessboard
|
||||
return board.position.evaluate(state)
|
||||
return board.position.evaluate(state)
|
||||
@@ -119,7 +119,7 @@ proc newTunableParameter*(name: string, min, max, default: int): TunableParamete
|
||||
result.default = default
|
||||
|
||||
|
||||
# Paste here the SPSA output from openbench and the values
|
||||
# Paste here the SPSA output from OpenBench and the values
|
||||
# will be loaded automatically into the default field of each
|
||||
# parameter
|
||||
const SPSA_OUTPUT = """
|
||||
|
||||
@@ -23,7 +23,6 @@ when sum != SCORE_NORMALIZATION_FACTOR:
|
||||
proc getWDLParameters(material: int): tuple[a, b: float64] =
|
||||
# Returns the parameters to be used for WDL estimation
|
||||
# and score normalization
|
||||
|
||||
let m = material.clamp(17, 78).float64 / 58.0
|
||||
|
||||
result.a = (((A_s[0] * m + A_s[1]) * m + A_s[2]) * m) + A_s[3]
|
||||
@@ -35,7 +34,6 @@ proc getExpectedWDL*(score: Score, material: int): tuple[win, draw, loss: int] =
|
||||
## Returns the expected win, loss and draw
|
||||
## probabilities (multiplied by a thousand)
|
||||
## with the given score and material values
|
||||
|
||||
let
|
||||
(a, b) = material.getWDLParameters()
|
||||
x = score.float
|
||||
|
||||
Reference in New Issue
Block a user