Esempio n. 1
0
    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)
Esempio n. 2
0
    def new(conf: ConfigWrapper):
        engine = uci.popen_engine(stockfish_command(conf['stockfish update']))
        engine.setoption({
            'Threads': conf['stockfish threads'],
            'Hash': conf['stockfish memory']
        })
        engine.uci()

        infoHandler = uci.InfoHandler()

        engine.info_handlers.append(infoHandler)

        return EngineTools(engine=engine, infoHandler=infoHandler)
Esempio n. 3
0
 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)
Esempio n. 4
0
    def __init__(self, settings):
        self.settings = settings

        self.engine = chess.uci.popen_engine(
            stockfish_command(settings['stockfish']['update']))
        self.engine.setoption({
            'Threads': settings['stockfish']['threads'],
            'Hash': settings['stockfish']['memory']
        })
        self.engine.uci()
        self.infoHandler = chess.uci.InfoHandler()
        self.engine.info_handlers.append(self.infoHandler)

        self.api = Api(settings['api']['url'], settings['api']['token'])

        # Set up mongodb
        self.client = MongoClient(settings['db']['host'])
        self.db = self.client.irwin
        if settings['db']['authenticate']:
            self.db.authenticate(settings['db']['authentication']['username'],
                                 settings['db']['authentication']['password'],
                                 mechanism='MONGODB-CR')

        # Colls
        self.playerColl = self.db.player
        self.GameAnalysisColl = self.db.gameAnalysis
        self.gameColl = self.db.game
        self.playerAssessmentColl = self.db.playerAssessment
        self.playerAnalysisColl = self.db.playerAnalysis
        self.trainingStatsColl = self.db.trainingStats
        self.falseReportsColl = self.db.falseReports

        # database abstraction
        self.gameDB = GameDB(self.gameColl)
        self.playerAssessmentDB = PlayerAssessmentDB(self.playerAssessmentColl)
        self.gameAnalysisDB = GameAnalysisDB(self.GameAnalysisColl,
                                             self.gameDB,
                                             self.playerAssessmentDB)
        self.playerAnalysisDB = PlayerAnalysisDB(self.playerAnalysisColl,
                                                 self.gameAnalysisDB)
        self.trainingStatsDB = TrainingStatsDB(self.trainingStatsColl)
        self.falseReportsDB = FalseReportsDB(self.falseReportsColl)

        # Irwin
        self.irwin = Irwin(api=self.api,
                           learner=settings['irwin']['learn'],
                           trainingStatsDB=self.trainingStatsDB,
                           playerAnalysisDB=self.playerAnalysisDB,
                           falseReportsDB=self.falseReportsDB,
                           settings=settings['irwin'])
Esempio n. 5
0
File: Env.py Progetto: isaacl/irwin
    def __init__(self, settings):
        self.settings = settings

        self.engine = chess.uci.popen_engine(stockfish_command())
        self.engine.setoption({
            'Threads': settings.threads,
            'Hash': settings.memory
        })
        self.engine.uci()
        self.infoHandler = chess.uci.InfoHandler()
        self.engine.info_handlers.append(self.infoHandler)

        self.api = Api(settings.token)

        # Set up mongodb
        self.client = MongoClient()
        self.db = self.client.irwin

        # Colls
        self.playerColl = self.db.player
        self.GameAnalysisColl = self.db.gameAnalysis
        self.gameColl = self.db.game
        self.playerAssessmentColl = self.db.playerAssessment
        self.playerAnalysisColl = self.db.playerAnalysis
        self.trainingStatsColl = self.db.trainingStats

        # database abstraction
        self.gameDB = GameDB(self.gameColl)
        self.playerAssessmentDB = PlayerAssessmentDB(self.playerAssessmentColl)
        self.gameAnalysisDB = GameAnalysisDB(self.GameAnalysisColl,
                                             self.gameDB,
                                             self.playerAssessmentDB)
        self.playerAnalysisDB = PlayerAnalysisDB(self.playerAnalysisColl,
                                                 self.gameAnalysisDB)
        self.trainingStatsDB = TrainingStatsDB(self.trainingStatsColl)

        # Irwin
        self.irwin = Irwin(api=self.api,
                           learner=settings.learn,
                           trainingStatsDB=self.trainingStatsDB,
                           playerAnalysisDB=self.playerAnalysisDB)
Esempio n. 6
0
try:
    # Optionally fix colors on Windows and in journals if the colorama module
    # is available.
    import colorama
    wrapper = colorama.AnsiToWin32(sys.stdout)
    if wrapper.should_wrap():
        sys.stdout = wrapper.stream
except ImportError:
    pass

logging.basicConfig(format="%(message)s", level=settings.loglevel, stream=sys.stdout)
logging.getLogger("requests.packages.urllib3").setLevel(logging.WARNING)
logging.getLogger("chess.uci").setLevel(logging.WARNING)

engine = chess.uci.popen_engine(stockfish_command())
engine.setoption({'Threads': settings.threads, 'Hash': settings.memory})
engine.uci()
info_handler = chess.uci.InfoHandler()
engine.info_handlers.append(info_handler)

while True:
    pgn = get_pgn(settings.token)
    game = chess.pgn.read_game(pgn)
    pgn.close()

    node = game

    game_id = game.headers["Site"].split('/')[-1:][0]
    logging.debug(bcolors.WARNING + "Game ID: " + game_id + bcolors.ENDC)
Esempio n. 7
0
def get_stockfish_command(path: str):
    return path if path else stockfish_command()