-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnv.py
More file actions
41 lines (33 loc) · 1.44 KB
/
Env.py
File metadata and controls
41 lines (33 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import logging
import chess.engine
from modules.fishnet.fishnet import stockfish_command
from modules.irwin.Env import Env as IrwinEnv
from modules.irwin.Irwin import Irwin
class Env:
def __init__(self, config, engine=True, newmodel: bool = False):
logging.debug('newmodel')
logging.debug(newmodel)
self.config = config
self._engine_enabled = engine
if self._engine_enabled:
self.engine = chess.engine.SimpleEngine.popen_uci(stockfish_command(config['stockfish']['update']))
self.engine.configure({'Threads': config['stockfish']['threads'], 'Hash': config['stockfish']['memory']})
# Irwin (no database needed for inference-only mode)
self.irwinEnv = IrwinEnv(config)
self.irwin = Irwin(self.irwinEnv, newmodel)
def restartEngine(self):
if self._engine_enabled and hasattr(self, 'engine'):
self.engine.quit()
self.engine = chess.engine.SimpleEngine.popen_uci(stockfish_command(self.config['stockfish']['update']))
self.engine.configure({'Threads': self.config['stockfish']['threads'], 'Hash': self.config['stockfish']['memory']})
def __del__(self):
logging.warning("Removing Env")
if hasattr(self, 'engine') and self.engine:
try:
self.engine.quit()
except Exception:
pass
try:
del self.irwin
except TypeError:
pass