本文整理匯總了Python中util.Stack.redo方法的典型用法代碼示例。如果您正苦於以下問題:Python Stack.redo方法的具體用法?Python Stack.redo怎麽用?Python Stack.redo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類util.Stack
的用法示例。
在下文中一共展示了Stack.redo方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from util import Stack [as 別名]
# 或者: from util.Stack import redo [as 別名]
#.........這裏部分代碼省略.........
return ()
if self.grid[cord1][cord2].clickIn(x, y):
return (cord1, cord2)
elif cord1 + 1 < self.size and self.grid[cord1 + 1][cord2].clickIn(x, y):
return (cord1 + 1, cord2)
elif cord2 + 1 < self.size and self.grid[cord1][cord2 + 1].clickIn(x, y):
return (cord1, cord2 + 1)
elif cord1 + 1 < self.size and cord2 + 1 < self.size and self.grid[cord1 + 1][cord2 + 1].clickIn(x, y):
return (cord1 + 1, cord2 + 1)
else:
return ()
def placePiece(self, cord, player):
success = self.grid[cord[0]][cord[1]].placePiece(player)
if not success:
return False
n = player.getNum()
if n == 1:
self.mark1[cord[0]] += 1
elif n == 2:
self.mark2[cord[1]] += 1
self.moveStack.push(HexMove(player, cord))
return success
def removePiece(self):
cord = self.moveStack.pop()
if cord != None:
cord = cord.getPos()
else:
return False
n = self.grid[cord[0]][cord[1]].getPlayer()
success = self.grid[cord[0]][cord[1]].removePiece()
if not success:
return False
if n == 1:
self.mark1[cord[0]] -= 1
elif n == 2:
self.mark2[cord[1]] = -1
return success
def redo(self):
item = self.moveStack.redo()
if item != None:
player = item.getPlayer()
cord = item.getPos()
success = self.grid[cord[0]][cord[1]].placePiece(player)
if not success:
return False
n = player.getNum()
if n == 1:
self.mark1[cord[0]] += 1
elif n == 2:
self.mark2[cord[1]] += 1
return False
def winner(self):
if 0 in self.mark1 and 0 in self.mark2:
return None
if self.scan(1):
return 1
elif self.scan(2):
return 2
else:
return None
def inRange(self, pos):
return 0 <= pos[0] < self.size and 0 <= pos[1] < self.size
def getAdjacent(self, iset):
adjacent = set()
for item in iset:
for v in HexBoard.adVec:
candidate = tuple(map(sum, zip(item, v)))
if self.inRange(candidate):
adjacent.add(candidate)
return adjacent
def scan(self, player):
adjacent = set()
for j in range(self.size):
iset = set()
for i in range(self.size):
if player == 1:
p = self.grid[j][i].getPlayer()
additem = (j, i)
elif player == 2:
p = self.grid[i][j].getPlayer()
additem = (i, j)
if player == p:
iset.add(additem)
if iset.isdisjoint(adjacent) and j > 0:
return False
adjacent = self.getAdjacent(iset)
return True
def getGrid(self):
return self.grid
def getStack(self):
return self.moveStack