238
239
self.__fromEngineFd = fromManagerOutput
240
241
# Fork off a child process to manage the engine
241
self.__pid = os.fork()
243
self.__pid = os.fork()
245
print 'Monitor failed to fork: %s' % e.message
243
246
os.close(toManagerInput)
247
os.close(toManagerOutput)
248
os.close(fromManagerInput)
244
249
os.close(fromManagerOutput)
245
self._runMonitor(fromManagerInput, toManagerOutput)
250
self.__toEngineFd = None
251
self.__fromEngineFd = None
254
os.close(toManagerInput)
255
os.close(fromManagerOutput)
256
self._runMonitor(fromManagerInput, toManagerOutput)
257
os.close(toManagerOutput)
258
os.close(fromManagerInput)
246
261
os.close(toManagerOutput)
247
262
os.close(fromManagerInput)
250
os.close(toManagerOutput)
251
os.close(fromManagerInput)
253
if profile.protocol == CECP:
254
self.connection = CECPConnection(self)
255
elif profile.protocol == UCI:
256
self.connection = UCIConnection(self)
264
if profile.protocol == CECP:
265
self.connection = CECPConnection(self)
266
elif profile.protocol == UCI:
267
self.connection = UCIConnection(self)
260
self.connection.start()
261
self.connection.startGame()
263
level = self.__profile.levels[self.__level]
265
self.connection.configure()
267
self.connection.configure(level.options)
271
self.connection.start()
272
self.connection.startGame()
274
level = self.__profile.levels[self.__level]
276
self.connection.configure()
278
self.connection.configure(level.options)
269
280
# Methods to extend
343
354
def onPlayerMoved(self, player, move):
344
355
"""Called by game.ChessPlayer"""
356
if self.__toEngineFd == None:
345
358
isSelf = player is self and self.moving
346
359
self.moving = False
347
360
self.connection.reportMove(move.canMove, isSelf)
349
362
def readyToMove(self):
350
363
"""Called by game.ChessPlayer"""
364
if self.__toEngineFd == None:
351
367
game = self.getGame()
352
368
whiteTime = game.getWhite().getRemainingTime()
353
369
blackTime = game.getBlack().getRemainingTime()
403
419
(fromEngineOutput, fromEngineInput) = os.pipe()
405
421
# Fork and execute the child
406
enginePID = os.fork()
423
enginePID = os.fork()
425
print 'Monitor failed to fork: %s' % e.message
407
427
if enginePID == 0:
408
428
os.close(toApplicationFd)
409
429
os.close(fromApplicationFd)