def next()

in pachi_py/pachi/tools/sgflib/sgflib.py [0:0]


	def next(self, varnum=0):
		"""
			Moves the 'Cursor' to & returns the next 'Node'. Raises
			'GameTreeEndError' if the end of a branch is exceeded. Raises
			'GameTreeNavigationError' if a non-existent variation is accessed.
			Argument:
			- varnum : integer, default 0 -- Variation number. Non-zero only
			  valid at a branching, where variations exist."""
		if self.index + 1 < len(self.gametree):	# more main line?
			if varnum != 0:
				raise GameTreeNavigationError("Nonexistent variation.")
			self.index = self.index + 1
		elif self.gametree.variations:			# variations exist?
			if varnum < len(self.gametree.variations):
				self.stack.append(self.gametree)
				self.gametree = self.gametree.variations[varnum]
				self.index = 0
			else:
				raise GameTreeNavigationError("Nonexistent variation.")
		else:
			raise GameTreeEndError
		self.node = self.gametree[self.index]
		self.nodenum = self.nodenum + 1
		self._setChildren()
		self._setFlags()
		return self.node