gnome-games r7574 - in branches/gnome-2-22/glchess: . src/lib
- From: rancell svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r7574 - in branches/gnome-2-22/glchess: . src/lib
- Date: Sat, 5 Apr 2008 08:11:49 +0100 (BST)
Author: rancell
Date: Sat Apr 5 08:11:49 2008
New Revision: 7574
URL: http://svn.gnome.org/viewvc/gnome-games?rev=7574&view=rev
Log:
Handle AI players dying before the game starts (Bug #522341)
Modified:
branches/gnome-2-22/glchess/ChangeLog
branches/gnome-2-22/glchess/src/lib/game.py
Modified: branches/gnome-2-22/glchess/src/lib/game.py
==============================================================================
--- branches/gnome-2-22/glchess/src/lib/game.py (original)
+++ branches/gnome-2-22/glchess/src/lib/game.py Sat Apr 5 08:11:49 2008
@@ -81,6 +81,7 @@
'name' is the name of the player.
"""
self.__name = str(name)
+ self.isAlive = True
# Methods to extend
@@ -185,7 +186,9 @@
def die(self):
"""Report this player has died"""
- self.__game.killPlayer(self)
+ self.isAlive = False
+ if self.__game is not None:
+ self.__game.killPlayer(self)
# Private methods
@@ -409,7 +412,15 @@
self.__currentPlayer = self.__whitePlayer
self.__started = True
-
+
+ # Stop if both players aren't alive
+ if not self.__whitePlayer.isAlive:
+ self.killPlayer(self.__whitePlayer)
+ return
+ if not self.__blackPlayer.isAlive:
+ self.killPlayer(self.__blackPlayer)
+ return
+
self.startLock()
# Get the next player to move
@@ -660,13 +671,16 @@
else:
assert(False)
self.endGame(result, RULE_TIMEOUT)
-
+
def endGame(self, result, rule):
+ if self.result != RESULT_IN_PROGRESS:
+ return
self.result = result
self.rule = rule
- self.__currentPlayer._setReadyToMove(False)
- for player in self.__players:
- player.onGameEnded(self)
+ if self.isStarted():
+ self.__currentPlayer._setReadyToMove(False)
+ for player in self.__players:
+ player.onGameEnded(self)
def getMoves(self):
"""
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]