home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / python-support / gnome-games-data / glchess / player.py < prev    next >
Encoding:
Python Source  |  2009-04-14  |  2.6 KB  |  86 lines

  1. # -*- coding: utf-8 -*-
  2. __author__ = 'Robert Ancell <bob27@users.sourceforge.net>'
  3. __license__ = 'GNU General Public License Version 2'
  4. __copyright__ = 'Copyright 2005-2006  Robert Ancell'
  5.  
  6. import game
  7. import ai
  8.  
  9. class MovePlayer(game.ChessPlayer):
  10.     """This class provides a pseudo-player to watch for piece movements"""
  11.  
  12.     def __init__(self, chessGame):
  13.         """Constructor for a move player.
  14.         
  15.         'chessGame' is the game to make changes to (ChessGame).
  16.         """
  17.         self.__game = chessGame
  18.         game.ChessPlayer.__init__(self, '@move')
  19.         
  20.     # Extended methods
  21.         
  22.     def onPlayerMoved(self, p, move):
  23.         """Called by chess.board.ChessPlayer"""
  24.         self.__game.setNeedsSaving(True)
  25.  
  26.         # Update clocks
  27.         if p is self.__game.getWhite():
  28.             if self.__game.wT is not None:
  29.                 self.__game.wT.controller.pause()
  30.             if self.__game.bT is not None:
  31.                 self.__game.bT.controller.run()
  32.         else:
  33.             if self.__game.bT is not None:
  34.                 self.__game.bT.controller.pause()
  35.             if self.__game.wT is not None:
  36.                 self.__game.wT.controller.run()
  37.         
  38.         # Complete move if not waiting for visual indication of move end
  39.         if self.__game.view.moveNumber != -1:
  40.             p.endMove()
  41.             
  42.         self.__game.view.controller.addMove(move)
  43.         
  44.     def onUndoMove(self):
  45.         self.__game.view.controller.undoMove()
  46.  
  47.     def onGameEnded(self, game):
  48.         """Called by chess.board.ChessPlayer"""
  49.         self.__game.setNeedsSaving(True)
  50.         self.__game.view.controller.endGame(game)
  51.  
  52. class HumanPlayer(game.ChessPlayer):
  53.     """
  54.     """    
  55.     __game = None
  56.     
  57.     def __init__(self, chessGame, name):
  58.         """Constructor.
  59.         
  60.         'chessGame' is the game this player is in (game.ChessGame).
  61.         'name' is the name of this player (string).
  62.         """
  63.         game.ChessPlayer.__init__(self, name)
  64.         self.__game = chessGame
  65.  
  66.     def readyToMove(self):
  67.         # FIXME: ???
  68.         self.__game.view.controller.setAttention(True)
  69.  
  70. class AIPlayer(ai.Player):
  71.     """
  72.     """
  73.     
  74.     def __init__(self, application, name, profile, level, description):
  75.         """
  76.         """
  77.         executable = profile.path
  78.         for arg in profile.arguments[1:]:
  79.             executable += ' ' + arg
  80.         self.window = application.ui.controller.addLogWindow(profile.name, executable, description)
  81.         ai.Player.__init__(self, name, profile, level)
  82.         
  83.     def logText(self, text, style):
  84.         """Called by ai.Player"""
  85.         self.window.addText(text, style)
  86.