|
44 | 44 |
|
45 | 45 | try: |
46 | 46 | from typing import Literal |
47 | | - _WdlModel = Literal["sf", "sf15.1", "sf15", "sf14", "sf12", "lichess"] |
| 47 | + _WdlModel = Literal["sf", "sf16", "sf15.1", "sf15", "sf14", "sf12", "lichess"] |
48 | 48 | except ImportError: |
49 | 49 | # Before Python 3.8. |
50 | 50 | _WdlModel = str # type: ignore |
@@ -637,11 +637,20 @@ def __ge__(self, other: object) -> bool: |
637 | 637 | else: |
638 | 638 | return NotImplemented |
639 | 639 |
|
| 640 | +def _sf16_wins(cp: int, *, ply: int) -> int: |
| 641 | + # https://github.com/official-stockfish/Stockfish/blob/sf_16/src/uci.h#L38 |
| 642 | + NormalizeToPawnValue = 328 |
| 643 | + # https://github.com/official-stockfish/Stockfish/blob/sf_16/src/uci.cpp#L200-L224 |
| 644 | + m = min(240, max(ply, 0)) / 64 |
| 645 | + a = (((0.38036525 * m + -2.82015070) * m + 23.17882135) * m) + 307.36768407 |
| 646 | + b = (((-2.29434733 * m + 13.27689788) * m + -14.26828904) * m) + 63.45318330 |
| 647 | + x = min(4000, max(cp * NormalizeToPawnValue / 100, -4000)) |
| 648 | + return int(0.5 + 1000 / (1 + math.exp((a - x) / b))) |
640 | 649 |
|
641 | 650 | def _sf15_1_wins(cp: int, *, ply: int) -> int: |
642 | | - # https://github.com/official-stockfish/Stockfish/blob/sf_15.1/src/uci.cpp#L200-L224 |
643 | 651 | # https://github.com/official-stockfish/Stockfish/blob/sf_15.1/src/uci.h#L38 |
644 | 652 | NormalizeToPawnValue = 361 |
| 653 | + # https://github.com/official-stockfish/Stockfish/blob/sf_15.1/src/uci.cpp#L200-L224 |
645 | 654 | m = min(240, max(ply, 0)) / 64 |
646 | 655 | a = (((-0.58270499 * m + 2.68512549) * m + 15.24638015) * m) + 344.49745382 |
647 | 656 | b = (((-2.65734562 * m + 15.96509799) * m + -20.69040836) * m) + 73.61029937 |
@@ -703,9 +712,12 @@ def wdl(self, *, model: _WdlModel = "sf", ply: int = 30) -> Wdl: |
703 | 712 | elif model == "sf15": |
704 | 713 | wins = _sf15_wins(self.cp, ply=ply) |
705 | 714 | losses = _sf15_wins(-self.cp, ply=ply) |
706 | | - else: |
| 715 | + elif model == "sf15.1": |
707 | 716 | wins = _sf15_1_wins(self.cp, ply=ply) |
708 | 717 | losses = _sf15_1_wins(-self.cp, ply=ply) |
| 718 | + else: |
| 719 | + wins = _sf16_wins(self.cp, ply=ply) |
| 720 | + losses = _sf16_wins(-self.cp, ply=ply) |
709 | 721 | draws = 1000 - wins - losses |
710 | 722 | return Wdl(wins, draws, losses) |
711 | 723 |
|
|
0 commit comments