Skip to content

Commit

Permalink
restart engine in case of termination
Browse files Browse the repository at this point in the history
  • Loading branch information
dkappe committed Mar 22, 2019
1 parent eb0c6c6 commit ddbe862
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions ender_match/ender_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class Engine:
def __init__(self, name=None, cmd=None, options=None):
super().__init__()
self.name = name
self.engine = chess.uci.popen_engine(cmd)
self.engine.setoption(options)
self.cmd = cmd
self.options = options
self.start_engine()
log("name = {}".format(name))
wfile = options.get("WeightsFile")
if not wfile == None:
Expand All @@ -30,6 +31,10 @@ def __init__(self, name=None, cmd=None, options=None):
self.engine.isready()


def start_engine(self):
self.engine = chess.uci.popen_engine(self.cmd)
self.engine.setoption(self.options)


class Openings:
def __init__(self, pgnfile=None):
Expand Down Expand Up @@ -131,13 +136,26 @@ def play(self, movetime=1000, enemytime=1000, opening=None):
self.populate_headers(game)
return game
if self.board.turn: #white
self.white.engine.position(self.board)
best, ponder = self.white.engine.go(movetime=white_time)
self.board.push(best)
try:
self.white.engine.position(self.board)
best, ponder = self.white.engine.go(movetime=white_time)
self.board.push(best)
except:
self.white.start_engine()
self.white.engine.position(self.board)
best, ponder = self.white.engine.go(movetime=white_time)
self.board.push(best)
else:
self.black.engine.position(self.board)
best, ponder = self.black.engine.go(movetime=black_time)
self.board.push(best)
try:
self.black.engine.position(self.board)
best, ponder = self.black.engine.go(movetime=black_time)
self.board.push(best)
except:
self.black.start_engine()
self.black.engine.position(self.board)
best, ponder = self.black.engine.go(movetime=black_time)
self.board.push(best)

log(best)

def doctor_game(game, side, piece_count):
Expand Down

0 comments on commit ddbe862

Please sign in to comment.