Skip to content

Commit 007e23d

Browse files
committed
Check board validity for fromPosition challenges
1 parent ae10f8e commit 007e23d

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

challenge_validator.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from typing import Any
22

3+
import chess
4+
35
from config import Config
46
from enums import DeclineReason
57
from game_manager import GameManager
@@ -38,6 +40,13 @@ def get_decline_reason(self, challenge_event: dict[str, Any]) -> DeclineReason |
3840
print(f'Variant "{challenge_event["variant"]["key"]}" is not allowed according to config.')
3941
return DeclineReason.VARIANT
4042

43+
if (
44+
challenge_event["variant"]["key"] == "fromPosition"
45+
and not chess.Board(challenge_event["initialFen"]).is_valid()
46+
):
47+
print("Invalid start position.")
48+
return DeclineReason.VARIANT
49+
4150
if (
4251
len(self.game_manager.tournaments) + len(self.game_manager.tournaments_to_join)
4352
) >= self.config.challenge.concurrency:

0 commit comments

Comments
 (0)