Skip to content

Keep engine process alive between moves#56

Merged
fsmosca merged 1 commit intomasterfrom
copilot/implement-engine-quit-logic
Mar 28, 2026
Merged

Keep engine process alive between moves#56
fsmosca merged 1 commit intomasterfrom
copilot/implement-engine-quit-logic

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 28, 2026

The engine spawns a new process and quits after every single move. This change persists the engine process across moves within a game, quitting only on game over or mode exit (Neutral, New Game, Resign, etc.).

Changes

  • RunEngine.__init__: Accept optional existing_engine parameter to reuse a running engine instance
  • RunEngine.run(): Skip popen_uci spawn and configure_engine when an existing engine is provided
  • RunEngine.get_engine(): New method — returns the engine instance without quitting, enabling hand-off between moves
  • RunEngine.quit_engine(): Guard against None, set self.engine = None after quit
  • play_game(): Track persistent_engine across the game loop; retrieve via get_engine() after each move, quit once on loop exit

Usage pattern

# Before: engine quit after every move
search.join()
search.quit_engine()

# After: engine handed off for reuse, quit only at end of game
search.join()
persistent_engine = search.get_engine()

# On next engine turn, reuse it
search = RunEngine(..., existing_engine=persistent_engine)

# Quit only when game loop exits (game over, neutral, resign, etc.)
if persistent_engine is not None:
    persistent_engine.quit()

@fsmosca fsmosca marked this pull request as ready for review March 28, 2026 20:25
@fsmosca fsmosca merged commit 0623d86 into master Mar 28, 2026
@fsmosca fsmosca deleted the copilot/implement-engine-quit-logic branch April 18, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants