Skip to content

Commit

Permalink
Merge branch 'taperedEvalParameters' into 'master'
Browse files Browse the repository at this point in the history
Tapered eval parameters

See merge request tsoj/Nalwald!3
  • Loading branch information
tsoj committed Jul 3, 2021
2 parents 4f3f22b + 323a63b commit 66f5de0
Show file tree
Hide file tree
Showing 18 changed files with 553 additions and 16,285 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ nim c -d:danger -d:lto --passC:"-mbmi2 -mpopcnt" --passL:"-static" --cc:clang --
- mobility
- sliding pieces attacking area around king
- rook on open file
- tapered parameters
- optimized using gradient descent
- search:
- principle variation search
Expand All @@ -52,8 +53,8 @@ nim c -d:danger -d:lto --passC:"-mbmi2 -mpopcnt" --passL:"-static" --cc:clang --
- late move reductions
- check extensions
- delta pruning
- fail high delta pruning
- futility pruning
- fail-high delta pruning
- futility reductions

#### License

Expand Down
80 changes: 68 additions & 12 deletions evalParameters.nim
Original file line number Diff line number Diff line change
@@ -1,28 +1,84 @@
import types

type OpeningOrEndGame* = enum
type Phase* = enum
opening, endgame

type OurKingOrEnemyKing* = enum
ourKing, enemyKing

type EvalParametersTemplate*[ValueType] = object
pst*: array[opening..endgame, array[ourKing..enemyKing, array[a1..h8, array[pawn..king, array[a1..h8, ValueType]]]]]
passedPawnTable*: array[opening..endgame, array[8, ValueType]]
type SinglePhaseEvalParametersTemplate*[ValueType] = object
pst*: array[ourKing..enemyKing, array[a1..h8, array[pawn..king, array[a1..h8, ValueType]]]]
passedPawnTable*: array[8, ValueType]
bonusIsolatedPawn*: ValueType
bonusPawnHasTwoNeighbors*: ValueType
bonusBothBishops*: ValueType
bonusRookOnOpenFile*: ValueType
mobilityMultiplierKnight*: float32
mobilityMultiplierBishop*: float32
mobilityMultiplierRook*: float32
mobilityMultiplierQueen*: float32
mobilityMultiplierKnight*: float
mobilityMultiplierBishop*: float
mobilityMultiplierRook*: float
mobilityMultiplierQueen*: float
bonusBishopTargetingKingArea*: ValueType
bonusRookTargetingKingArea*: ValueType
bonusQueenTargetingKingArea*: ValueType
bonusRookSecondRankFromKing*: ValueType
kingSafetyMultiplier*: float32
kingSafetyMultiplier*: float

type EvalParametersFloat* = EvalParametersTemplate[float32]
type EvalParametersTemplate[ValueType] = array[Phase, SinglePhaseEvalParametersTemplate[ValueType]]

type EvalParameters* = EvalParametersTemplate[Value]
type EvalParametersFloat* = EvalParametersTemplate[float]

type EvalParameters* = EvalParametersTemplate[Value]

func convertTemplate[InValueType, OutValueType](
a: SinglePhaseEvalParametersTemplate[InValueType]
): SinglePhaseEvalParametersTemplate[OutValueType] =
for whoseKing in ourKing..enemyKing:
for kingSquare in a1..h8:
for piece in pawn..king:
for square in a1..h8:
result.pst[whoseKing][kingSquare][piece][square] =
a.pst[whoseKing][kingSquare][piece][square].OutValueType
for i in 0..7:
result.passedPawnTable[i] = a.passedPawnTable[i].OutValueType
result.bonusIsolatedPawn = a.bonusIsolatedPawn.OutValueType
result.bonusPawnHasTwoNeighbors = a.bonusPawnHasTwoNeighbors.OutValueType
result.bonusBothBishops = a.bonusBothBishops.OutValueType
result.bonusRookOnOpenFile = a.bonusRookOnOpenFile.OutValueType
result.mobilityMultiplierKnight = a.mobilityMultiplierKnight
result.mobilityMultiplierBishop = a.mobilityMultiplierBishop
result.mobilityMultiplierRook = a.mobilityMultiplierRook
result.mobilityMultiplierQueen = a.mobilityMultiplierQueen
result.bonusBishopTargetingKingArea = a.bonusBishopTargetingKingArea.OutValueType
result.bonusRookTargetingKingArea = a.bonusRookTargetingKingArea.OutValueType
result.bonusQueenTargetingKingArea = a.bonusQueenTargetingKingArea.OutValueType
result.kingSafetyMultiplier = a.kingSafetyMultiplier

func convertTemplate[InValueType, OutValueType](a: EvalParametersTemplate[InValueType]): EvalParametersTemplate[OutValueType] =
for phase in Phase:
result[phase] = a[phase].convertTemplate[:InValueType, OutValueType]

func convert*(a: EvalParameters): EvalParametersFloat =
a.convertTemplate[:Value, float]

func convert*(a: EvalParametersFloat): EvalParameters =
a.convertTemplate[:float, Value]

func `*=`*(a: var SinglePhaseEvalParametersTemplate[float], b: float) =
for whoseKing in ourKing..enemyKing:
for kingSquare in a1..h8:
for piece in pawn..king:
for square in a1..h8:
a.pst[whoseKing][kingSquare][piece][square] *= b
for i in 0..7:
a.passedPawnTable[i] *= b
a.bonusIsolatedPawn *= b
a.bonusPawnHasTwoNeighbors *= b
a.bonusBothBishops *= b
a.bonusRookOnOpenFile *= b
a.mobilityMultiplierKnight *= b
a.mobilityMultiplierBishop *= b
a.mobilityMultiplierRook *= b
a.mobilityMultiplierQueen *= b
a.bonusBishopTargetingKingArea *= b
a.bonusRookTargetingKingArea *= b
a.bonusQueenTargetingKingArea *= b
a.kingSafetyMultiplier *= b
Loading

0 comments on commit 66f5de0

Please sign in to comment.