-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathEnv.py
70 lines (54 loc) · 2.45 KB
/
Env.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import logging
from pymongo import MongoClient
from chess import uci
from modules.fishnet.fishnet import stockfish_command
from modules.lichess.Api import Api
from modules.game.Game import GameDB
from modules.game.AnalysedGame import AnalysedGameDB
from modules.game.Player import PlayerDB
from modules.game.AnalysedPosition import AnalysedPositionDB
from modules.queue.IrwinQueue import IrwinQueueDB
from modules.queue.EngineQueue import EngineQueueDB
from modules.irwin.training.AnalysedGameActivation import AnalysedGameActivationDB
from modules.irwin.training.BasicGameActivation import BasicGameActivationDB
from modules.irwin.AnalysisReport import PlayerReportDB, GameReportDB
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 = engine
if self.engine:
self.engine = uci.popen_engine(stockfish_command(config['stockfish']['update']))
self.engine.setoption({'Threads': config['stockfish']['threads'], 'Hash': config['stockfish']['memory']})
self.engine.uci()
self.infoHandler = uci.InfoHandler()
self.engine.info_handlers.append(self.infoHandler)
self.api = Api(config['api']['url'], config['api']['token'])
# Set up mongodb
self.client = MongoClient(config['db']['host'])
self.db = self.client.irwin
if config['db']['authenticate']:
self.db.authenticate(
config['db']['authentication']['username'],
config['db']['authentication']['password'], mechanism='MONGODB-CR')
# Irwin
self.irwinEnv = IrwinEnv(config, self.db)
self.irwin = Irwin(self.irwinEnv, newmodel)
def restartEngine(self):
if self.engine:
self.engine.kill()
self.engine = uci.popen_engine(stockfish_command(self.config['stockfish']['update']))
self.engine.setoption({'Threads': self.config['stockfish']['threads'], 'Hash': self.config['stockfish']['memory']})
self.engine.uci()
self.infoHandler = uci.InfoHandler()
self.engine.info_handlers.append(self.infoHandler)
def __del__(self):
logging.warning("Removing Env")
self.engine.kill()
try:
del self.irwin
except TypeError:
pass