120
120
SKIP_MOVETEXT_REGEX = re .compile (r""";|\{|\}""" )
121
121
122
122
123
- CLOCK_REGEX = re .compile (r"""\[%clk\s(\d+):(\d+):(\d+(?:\.\d*)?)\]""" )
124
- EMT_REGEX = re .compile (r"""\[%emt\s(\d+):(\d+):(\d+(?:\.\d*)?)\]""" )
123
+ CLOCK_REGEX = re .compile (r"""\[%clk\s(?P<hours> \d+):(?P<minutes> \d+):(?P<seconds> \d+(?:\.\d*)?)\]""" )
124
+ EMT_REGEX = re .compile (r"""\[%emt\s(?P<hours> \d+):(?P<minutes> \d+):(?P<seconds> \d+(?:\.\d*)?)\]""" )
125
125
126
126
EVAL_REGEX = re .compile (r"""
127
127
\[%eval\s(?:
128
- \#([+-]?\d+)
129
- |([+-]?(?:\d{0,10}\.\d{1,2}|\d{1,10}\.?))
128
+ \#(?P<mate> [+-]?\d+)
129
+ |(?P<cp> [+-]?(?:\d{0,10}\.\d{1,2}|\d{1,10}\.?))
130
130
)(?:
131
- ,(\d+)
131
+ ,(?P<depth> \d+)
132
132
)?\]
133
133
""" , re .VERBOSE )
134
134
135
135
ARROWS_REGEX = re .compile (r"""
136
- \[%(?:csl|cal)\s(
136
+ \[%(?:csl|cal)\s(?P<arrows>
137
137
[RGYB][a-h][1-8](?:[a-h][1-8])?
138
138
(?:,[RGYB][a-h][1-8](?:[a-h][1-8])?)*
139
139
)\]
@@ -399,16 +399,16 @@ def eval(self) -> Optional[chess.engine.PovScore]:
399
399
400
400
turn = self .turn ()
401
401
402
- if match .group (1 ):
403
- mate = int (match .group (1 ))
402
+ if match .group ("mate" ):
403
+ mate = int (match .group ("mate" ))
404
404
score : chess .engine .Score = chess .engine .Mate (mate )
405
405
if mate == 0 :
406
406
# Resolve this ambiguity in the specification in favor of
407
407
# standard chess: The player to move after mate is the player
408
408
# who has been mated.
409
409
return chess .engine .PovScore (score , turn )
410
410
else :
411
- score = chess .engine .Cp (int (float (match .group (2 )) * 100 ))
411
+ score = chess .engine .Cp (int (float (match .group ("cp" )) * 100 ))
412
412
413
413
return chess .engine .PovScore (score if turn else - score , turn )
414
414
@@ -418,7 +418,7 @@ def eval_depth(self) -> Optional[int]:
418
418
this node and returns the corresponding depth, if any.
419
419
"""
420
420
match = EVAL_REGEX .search (self .comment )
421
- return int (match .group (3 )) if match and match .group (3 ) else None
421
+ return int (match .group ("depth" )) if match and match .group ("depth" ) else None
422
422
423
423
def set_eval (self , score : Optional [chess .engine .PovScore ], depth : Optional [int ] = None ) -> None :
424
424
"""
@@ -450,7 +450,7 @@ def arrows(self) -> List[chess.svg.Arrow]:
450
450
"""
451
451
arrows = []
452
452
for match in ARROWS_REGEX .finditer (self .comment ):
453
- for group in match .group (1 ).split ("," ):
453
+ for group in match .group ("arrows" ).split ("," ):
454
454
arrows .append (chess .svg .Arrow .from_pgn (group ))
455
455
456
456
return arrows
@@ -493,7 +493,7 @@ def clock(self) -> Optional[float]:
493
493
match = CLOCK_REGEX .search (self .comment )
494
494
if match is None :
495
495
return None
496
- return int (match .group (1 )) * 3600 + int (match .group (2 )) * 60 + float (match .group (3 ))
496
+ return int (match .group ("hours" )) * 3600 + int (match .group ("minutes" )) * 60 + float (match .group ("seconds" ))
497
497
498
498
def set_clock (self , seconds : Optional [float ]) -> None :
499
499
"""
@@ -527,7 +527,7 @@ def emt(self) -> Optional[float]:
527
527
match = EMT_REGEX .search (self .comment )
528
528
if match is None :
529
529
return None
530
- return int (match .group (1 )) * 3600 + int (match .group (2 )) * 60 + float (match .group (3 ))
530
+ return int (match .group ("hours" )) * 3600 + int (match .group ("minutes" )) * 60 + float (match .group ("seconds" ))
531
531
532
532
def set_emt (self , seconds : Optional [float ]) -> None :
533
533
"""
0 commit comments