Skip to content

Commit

Permalink
BugFix for PicoTutor engines running
Browse files Browse the repository at this point in the history
Although PicoCoach AND PicWatcher were switched off there were still the tutor engines running in background. This has been fixed (hopefully)
  • Loading branch information
tosca07 authored Sep 9, 2024
1 parent 7664c60 commit ad5f024
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 44 deletions.
28 changes: 2 additions & 26 deletions picochess.py
Original file line number Diff line number Diff line change
Expand Up @@ -4272,12 +4272,6 @@ def takeback(state: PicochessState):
DisplayMsg.show(Message.ALTMOVES(altmoves=event.altmoves))

elif isinstance(event, Event.PICOWATCHER):
if state.dgtmenu.get_picowatcher() or (
state.dgtmenu.get_picocoach() != PicoCoach.COACH_OFF
):
pico_calc = True
else:
pico_calc = False
state.picotutor.set_status(
state.dgtmenu.get_picowatcher(),
state.dgtmenu.get_picocoach(),
Expand All @@ -4297,19 +4291,10 @@ def takeback(state: PicochessState):
state.flag_picotutor = True
else:
state.flag_picotutor = False
if pico_calc:
state.picotutor.stop()

DisplayMsg.show(Message.PICOWATCHER(picowatcher=event.picowatcher))

elif isinstance(event, Event.PICOCOACH):
pico_calc = False
if state.dgtmenu.get_picowatcher() or (
state.dgtmenu.get_picocoach() != PicoCoach.COACH_OFF
):
pico_calc = True
else:
pico_calc = False

state.picotutor.set_status(
state.dgtmenu.get_picowatcher(),
state.dgtmenu.get_picocoach(),
Expand All @@ -4330,8 +4315,6 @@ def takeback(state: PicochessState):
state.flag_picotutor = True
else:
state.flag_picotutor = False
if pico_calc:
state.picotutor.stop()

if state.dgtmenu.get_picocoach() == PicoCoach.COACH_OFF:
DisplayMsg.show(Message.PICOCOACH(picocoach=False))
Expand All @@ -4347,12 +4330,6 @@ def takeback(state: PicochessState):
call_pico_coach(state)

elif isinstance(event, Event.PICOEXPLORER):
if state.dgtmenu.get_picowatcher() or (
state.dgtmenu.get_picocoach() != PicoCoach.COACH_OFF
):
pico_calc = True
else:
pico_calc = False
state.picotutor.set_status(
state.dgtmenu.get_picowatcher(),
state.dgtmenu.get_picocoach(),
Expand All @@ -4368,8 +4345,7 @@ def takeback(state: PicochessState):
state.flag_picotutor = True
else:
state.flag_picotutor = False
if pico_calc:
state.picotutor.stop()

DisplayMsg.show(Message.PICOEXPLORER(picoexplorer=event.picoexplorer))

elif isinstance(event, Event.RSPEED):
Expand Down
70 changes: 52 additions & 18 deletions picotutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,25 +130,17 @@ def set_status(self, watcher=False, coach=PicoCoach.COACH_OFF, explorer=False, c
b_coach = False
else:
b_coach = True
if self.watcher_on or self.coach_on:
self.watcher_on = watcher
self.coach_on = b_coach
self.explorer_on = explorer
self.comments_on = comments
if watcher or coach:
self.reset()
else:
self.stop()
else:
self.watcher_on = watcher
self.coach_on = b_coach
self.explorer_on = explorer
self.comments_on = comments
if watcher or coach:
self.reset()
else:
pass

self.watcher_on = watcher
self.coach_on = b_coach
self.explorer_on = explorer
self.comments_on = comments

self.stop()

if watcher or b_coach:
self._reset_int()

def get_game_comment(self, pico_comment=PicoComment.COM_OFF, com_factor=0):
max_range = 0
max_range_all = 0
Expand Down Expand Up @@ -282,6 +274,48 @@ def reset(self):

self.stop()

if self.watcher_on or self.coach_on:
self.engine = chess.uci.popen_engine(self.engine_path)
self.engine2 = chess.uci.popen_engine(self.engine_path)
self.engine.uci()
self.engine2.uci()
self.engine.setoption({"MultiPV": self.max_valid_moves})
self.engine.setoption({"Contempt": 0})
self.engine.setoption({"Threads": c.NUM_THREADS})
self.engine2.setoption({"MultiPV": self.max_valid_moves})
self.engine2.setoption({"Contempt": 0})
self.engine2.setoption({"Threads": c.NUM_THREADS})
self.engine.isready()
self.engine2.isready()
self.info_handler = chess.uci.InfoHandler()
self.info_handler2 = chess.uci.InfoHandler()
self.engine.info_handlers.append(self.info_handler)
self.engine2.info_handlers.append(self.info_handler2)
self.engine.position(self.board)
self.engine2.position(self.board)

self.history = []
self.history2 = []
self.history.append((0, chess.Move.null(), 0.00, 0))
self.history2.append((0, chess.Move.null(), 0.00, 0))

self.alt_best_moves = []
self.pv_best_move = []
self.pv_user_move = []
self.hint_move = chess.Move.null()
self.mate = 0
self.expl_start_position = True#

def _reset_int(self):
self.pos = False
self.legal_moves = []
self.legal_moves2 = []
self.op = []
self.user_color = chess.WHITE
self.board = chess.Board()

self.stop()

self.engine = chess.uci.popen_engine(self.engine_path)
self.engine2 = chess.uci.popen_engine(self.engine_path)
self.engine.uci()
Expand Down

0 comments on commit ad5f024

Please sign in to comment.