@@ -1435,7 +1435,7 @@ def line_received(self, engine: UciProtocol, line: str) -> None:
14351435 return await self .communicate (UciPingCommand )
14361436
14371437 def _changed_options (self , options : ConfigMapping ) -> bool :
1438- return any (value is None or value != self .config .get (name ) for name , value in collections . ChainMap (options , self .target_config ). items ( ))
1438+ return any (value is None or value != self .config .get (name ) for name , value in _chain_config (options , self .target_config ))
14391439
14401440 def _setoption (self , name : str , value : ConfigValue ) -> None :
14411441 try :
@@ -1457,7 +1457,7 @@ def _setoption(self, name: str, value: ConfigValue) -> None:
14571457 self .config [name ] = value
14581458
14591459 def _configure (self , options : ConfigMapping ) -> None :
1460- for name , value in collections . ChainMap (options , self .target_config ). items ( ):
1460+ for name , value in _chain_config (options , self .target_config ):
14611461 if name .lower () in MANAGED_OPTIONS :
14621462 raise EngineError ("cannot set {} which is automatically managed" .format (name ))
14631463 self ._setoption (name , value )
@@ -1845,6 +1845,14 @@ def _parse_uci_bestmove(board: chess.Board, args: str) -> BestMove:
18451845 return BestMove (move , ponder )
18461846
18471847
1848+ def _chain_config (a : ConfigMapping , b : ConfigMapping ) -> Iterator [Tuple [str , ConfigValue ]]:
1849+ for name , value in a .items ():
1850+ yield name , value
1851+ for name , value in b .items ():
1852+ if name not in a :
1853+ yield name , value
1854+
1855+
18481856class UciOptionMap (MutableMapping [str , T ]):
18491857 """Dictionary with case-insensitive keys."""
18501858
@@ -2348,7 +2356,7 @@ def _setoption(self, name: str, value: ConfigValue) -> None:
23482356 self .send_line (f"option { name } ={ value } " )
23492357
23502358 def _configure (self , options : ConfigMapping ) -> None :
2351- for name , value in collections . ChainMap (options , self .target_config ). items ( ):
2359+ for name , value in _chain_config (options , self .target_config ):
23522360 if name .lower () in MANAGED_OPTIONS :
23532361 raise EngineError (f"cannot set { name } which is automatically managed" )
23542362 self ._setoption (name , value )
0 commit comments