与字典的片断运动

时间:2018-04-10 02:34:14

标签: python list dictionary

所以我目前有一个字典,其中包含多个棋子作为值,而位置作为键。我现在可以根据国际象棋规则移动每件作品,但我正在努力确保作品不能相互跳过。

这是我当前代码的一部分,允许女王移动。

QueenRow = int(self.UI_entry2.get()) #mighht not be needed
QueenColumn = int(self.UI_entry3.get())
QueenMoves = self.QueenMoves(QueenRow,QueenColumn)
QueenTuple.append(QueenRow) # Add to list to tuple
QueenTuple.append(QueenColumn) # Add to list to tuple
QueenRowColumn = tuple(QueenTuple) # Tuple the numbers
for piece,position in list(self.pieces.items()): # Get the Key from the values
       if position == QueenRowColumn: # if the tupled numbers equals the key
              print("Piece:",piece,"|","Old Position:",position)   # Print the key and position
              MoveRow = int(self.UI_entry4.get()) #then get the row and column they can move to
              MoveColumn = int(self.UI_entry5.get())
              QueenTuple2.append(MoveRow)
              QueenTuple2.append(MoveColumn)
              TheComparison = tuple(QueenTuple2)
              for TheQueenMoves in QueenMoves: #loop through all the kings moves
                    for a,b in list(self.pieces.items()):    
                      # Move Piece!
                      if TheComparison == TheQueenMoves and TheComparison[0] >= 0 and TheComparison[1] <= 7 and TheComparison[1] >= 0 and TheComparison[0] <= 7:
                      self.placepiece(piece, row = MoveRow, column = MoveColumn)
                      print("Piece:",piece,"|","Current Position:",TheComparison)                                                   print("Possible Moves in current position:",QueenMoves)
                      break
                      del QueenTuple[:]
                      del QueenTuple2[:]

(我没有添加完整的代码,因为它太长而且很难通读)

此代码允许女王移动但也允许该片跳过其他片段。有什么方法可以阻止这种情况发生吗?

0 个答案:

没有答案