|
44 | 44 |
|
45 | 45 | try: |
46 | 46 | from typing import Literal |
47 | | - _WdlModel = Literal["sf", "sf15", "sf14", "sf12", "lichess"] |
| 47 | + _WdlModel = Literal["sf", "sf15.1", "sf15", "sf14", "sf12", "lichess"] |
48 | 48 | except ImportError: |
49 | 49 | # Before Python 3.8. |
50 | 50 | _WdlModel = str # type: ignore |
@@ -564,7 +564,8 @@ def wdl(self, *, model: _WdlModel = "sf", ply: int = 30) -> Wdl: |
564 | 564 |
|
565 | 565 | :param model: |
566 | 566 | * ``sf``, the WDL model used by the latest Stockfish |
567 | | - (currently ``sf15``). |
| 567 | + (currently ``sf15.1``). |
| 568 | + * ``sf15.1``, the WDL model used by Stockfish 15.1. |
568 | 569 | * ``sf15``, the WDL model used by Stockfish 15. |
569 | 570 | * ``sf14``, the WDL model used by Stockfish 14. |
570 | 571 | * ``sf12``, the WDL model used by Stockfish 12. |
@@ -628,6 +629,16 @@ def __ge__(self, other: object) -> bool: |
628 | 629 | return NotImplemented |
629 | 630 |
|
630 | 631 |
|
| 632 | +def _sf15_1_wins(cp: int, *, ply: int) -> int: |
| 633 | + # https://github.com/official-stockfish/Stockfish/blob/sf_15.1/src/uci.cpp#L200-L224 |
| 634 | + # https://github.com/official-stockfish/Stockfish/blob/sf_15.1/src/uci.h#L38 |
| 635 | + NormalizeToPawnValue = 361 |
| 636 | + m = min(240, max(ply, 0)) / 64 |
| 637 | + a = (((-0.58270499 * m + 2.68512549) * m + 15.24638015) * m) + 344.49745382 |
| 638 | + b = (((-2.65734562 * m + 15.96509799) * m + -20.69040836) * m) + 73.61029937 |
| 639 | + x = min(4000, max(cp * NormalizeToPawnValue / 100, -4000)) |
| 640 | + return int(0.5 + 1000 / (1 + math.exp((a - x) / b))) |
| 641 | + |
631 | 642 | def _sf15_wins(cp: int, *, ply: int) -> int: |
632 | 643 | # https://github.com/official-stockfish/Stockfish/blob/sf_15/src/uci.cpp#L200-L220 |
633 | 644 | m = min(240, max(ply, 0)) / 64 |
@@ -678,9 +689,12 @@ def wdl(self, *, model: _WdlModel = "sf", ply: int = 30) -> Wdl: |
678 | 689 | elif model == "sf14": |
679 | 690 | wins = _sf14_wins(self.cp, ply=ply) |
680 | 691 | losses = _sf14_wins(-self.cp, ply=ply) |
681 | | - else: |
| 692 | + elif model == "sf15": |
682 | 693 | wins = _sf15_wins(self.cp, ply=ply) |
683 | 694 | losses = _sf15_wins(-self.cp, ply=ply) |
| 695 | + else: |
| 696 | + wins = _sf15_1_wins(self.cp, ply=ply) |
| 697 | + losses = _sf15_1_wins(-self.cp, ply=ply) |
684 | 698 | draws = 1000 - wins - losses |
685 | 699 | return Wdl(wins, draws, losses) |
686 | 700 |
|
|
0 commit comments