~ubuntu-branches/ubuntu/intrepid/gnome-games/intrepid

« back to all changes in this revision

Viewing changes to glchess/src/lib/ai.py

  • Committer: Package Import Robot
  • Author(s): Didier Roche
  • Date: 2008-10-21 00:30:34 UTC
  • mfrom: (1.1.58)
  • Revision ID: package-import@ubuntu.com-20081021003034-cb0iknvzten935zn
Tags: 1:2.24.1-0ubuntu1
* New upstream release (LP: #286667)
  - General:
    - Fix up compatiblity with Gtk/Glib 2.14
    - Reclassify Gnibbles as Arcade game not logic game
    - Read saved window configuration from correct GConf group (affects
      gnometris, gnibbles, gnobots)
  - Aisleriot:
    - Remove vestigal flowRoot elements from solitaire svg icons. They
      caused a black box when rendering.
    - Don't crash when the session manager terminates aisleriot
  - GLChess:
    - Fix crash in error handler when GGZ connection closed
    - Fix crash in empty scene when no AI engines available
    - Fix crash when have OpenGL libraries but cannot get valid display
    - Implement GGZ config parser instead of using Python config parser
      which does not handle '%' characters as GGZ does
    - Ignore GGZ server remove player/table for unknown players/tables
    - Handle exceptions loading OpenGL textures
    - Reset pause menu when starting new game
    - Only allow one new/load game dialog to be visible at once
    - Fix incorrect function call for single buffered 3D display
    - Handle fork() errors in AI processes
    - Fixes to compile in Solaris
    - Print failure to start message to stdout if cannot import GTK+
    - Handle invalid response from glRenderMode(GL_RENDER) and print
      debugging information
    - More logging messages about selection rendering bugs
    - After looking at failure case in PyOpenGL code we don't need to change
      render modes after failed to change to GL_SELECT
    - Fix potential bugs found by PyChecker
    - Fix crash when validly claiming a draw
    - Don't display failed to claim draw dialog when successfully claimed
      draw
  - GTali:
    - Undoing 5 of a kind reduces the score by 50 as there might be multiple
      scores (LP: #238978)
  - Sudoku:
    - Add not overwrite time and also remember to actually save the time in
      the file (LP: #279616)
    - Correct typo in error message that led to an exception
  - Gnotravex:
    - Stop paused tiles becoming visible after changing colour settings
  - Blackjack:
    - Fix compiler warnings

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
import select
8
8
import signal
9
9
import xml.dom.minidom
 
10
import xml.parsers.expat
10
11
 
11
12
import game
12
13
import cecp
238
239
        self.__fromEngineFd = fromManagerOutput
239
240
 
240
241
        # Fork off a child process to manage the engine
241
 
        self.__pid = os.fork()
242
 
        if self.__pid == 0:
 
242
        try:
 
243
            self.__pid = os.fork()
 
244
        except OSError, e:
 
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
 
252
        else:
 
253
            if self.__pid == 0:
 
254
                os.close(toManagerInput)
 
255
                os.close(fromManagerOutput)
 
256
                self._runMonitor(fromManagerInput, toManagerOutput)
 
257
                os.close(toManagerOutput)
 
258
                os.close(fromManagerInput)
 
259
                os._exit(0)
 
260
 
246
261
            os.close(toManagerOutput)
247
262
            os.close(fromManagerInput)
248
 
            os._exit(0)
249
 
 
250
 
        os.close(toManagerOutput)
251
 
        os.close(fromManagerInput)
252
 
 
253
 
        if profile.protocol == CECP:
254
 
            self.connection = CECPConnection(self)
255
 
        elif profile.protocol == UCI:
256
 
            self.connection = UCIConnection(self)
257
 
        else:
258
 
            assert(False)
 
263
 
 
264
            if profile.protocol == CECP:
 
265
                self.connection = CECPConnection(self)
 
266
            elif profile.protocol == UCI:
 
267
                self.connection = UCIConnection(self)
 
268
            else:
 
269
                assert(False)
259
270
            
260
 
        self.connection.start()
261
 
        self.connection.startGame()
262
 
        try:
263
 
            level = self.__profile.levels[self.__level]
264
 
        except KeyError:
265
 
            self.connection.configure()
266
 
        else:
267
 
            self.connection.configure(level.options)
 
271
            self.connection.start()
 
272
            self.connection.startGame()
 
273
            try:
 
274
                level = self.__profile.levels[self.__level]
 
275
            except KeyError:
 
276
                self.connection.configure()
 
277
            else:
 
278
                self.connection.configure(level.options)
268
279
 
269
280
    # Methods to extend
270
281
    
342
353
    
343
354
    def onPlayerMoved(self, player, move):
344
355
        """Called by game.ChessPlayer"""
 
356
        if self.__toEngineFd == None:
 
357
            return
345
358
        isSelf = player is self and self.moving
346
359
        self.moving = False
347
360
        self.connection.reportMove(move.canMove, isSelf)
348
361
 
349
362
    def readyToMove(self):
350
363
        """Called by game.ChessPlayer"""
 
364
        if self.__toEngineFd == None:
 
365
            self.die()
 
366
            return
351
367
        game = self.getGame()
352
368
        whiteTime = game.getWhite().getRemainingTime()
353
369
        blackTime = game.getBlack().getRemainingTime()
403
419
        (fromEngineOutput, fromEngineInput) = os.pipe()
404
420
 
405
421
        # Fork and execute the child
406
 
        enginePID = os.fork()
 
422
        try:
 
423
            enginePID = os.fork()
 
424
        except OSError, e:
 
425
            print 'Monitor failed to fork: %s' % e.message
 
426
            os._exit(1);
407
427
        if enginePID == 0:
408
428
            os.close(toApplicationFd)
409
429
            os.close(fromApplicationFd)