|
44 | 44 |
|
45 | 45 | try: |
46 | 46 | from typing import Literal |
47 | | - _WdlModel = Literal["sf12", "lichess"] |
| 47 | + _WdlModel = Literal["sf14", "sf12", "lichess"] |
48 | 48 | except ImportError: |
49 | 49 | # Before Python 3.8. |
50 | 50 | _WdlModel = str # type: ignore |
@@ -559,6 +559,8 @@ def wdl(self, *, model: _WdlModel = "sf12", ply: int = 30) -> Wdl: |
559 | 559 | 0.015... |
560 | 560 |
|
561 | 561 | :param model: |
| 562 | + * ``sf14``, the WDL model used by the current development version |
| 563 | + of Stockfish. Still subject to change or removal. |
562 | 564 | * ``sf12``, the WDL model used by Stockfish 12. |
563 | 565 | * ``lichess``, the win rate model used by Lichess. |
564 | 566 | Does not use *ply*, and does not consider drawing chances. |
@@ -620,6 +622,15 @@ def __ge__(self, other: object) -> bool: |
620 | 622 | return NotImplemented |
621 | 623 |
|
622 | 624 |
|
| 625 | +def _sf14_wins(cp: int, *, ply: int) -> int: |
| 626 | + # TODO: When released, add permalink and update documentation. |
| 627 | + m = min(240, max(ply, 0)) / 64 |
| 628 | + a = (((-3.68389304 * m + 30.07065921) * m + -60.52878723) * m) + 149.53378557 |
| 629 | + b = (((-2.01818570 * m + 15.85685038) * m + -29.83452023) * m) + 47.59078827 |
| 630 | + pawn_value_eg = 208 |
| 631 | + x = min(2000, max(cp * 100 / pawn_value_eg, -2000)) |
| 632 | + return int(0.5 + 1000 / (1 + math.exp((a - x) / b))) |
| 633 | + |
623 | 634 | def _sf12_wins(cp: int, *, ply: int) -> int: |
624 | 635 | # https://github.com/official-stockfish/Stockfish/blob/sf_12/src/uci.cpp#L198-L218 |
625 | 636 | m = min(240, max(ply, 0)) / 64 |
@@ -649,6 +660,9 @@ def wdl(self, *, model: _WdlModel = "sf12", ply: int = 30) -> Wdl: |
649 | 660 | if model == "lichess": |
650 | 661 | wins = _lichess_raw_wins(max(-1000, min(self.cp, 1000))) |
651 | 662 | losses = 1000 - wins |
| 663 | + elif model == "sf14": |
| 664 | + wins = _sf14_wins(self.cp, ply=ply) |
| 665 | + losses = _sf14_wins(-self.cp, ply=ply) |
652 | 666 | else: |
653 | 667 | wins = _sf12_wins(self.cp, ply=ply) |
654 | 668 | losses = _sf12_wins(-self.cp, ply=ply) |
|
0 commit comments