我需要帮助才能让这个功能阻止人们超越坐标,其他玩家已经进入了他们的游戏中并且已经进入了
def CheckValidMove(XCoordinate, YCoordinate, Board):
ValidMove = True
'''This function makes sure the coordinate inputed
by the user is valid, e.g. from 1 - 3 displayed on the board'''
if (XCoordinate < 1) or (XCoordinate > 3):
ValidMove = False
if (YCoordinate < 1) or (YCoordinate > 3):
ValidMove = False
return ValidMove
答案 0 :(得分:2)
您需要跟踪网格上每个位置的状态。如果玩家选择了一个位置,请将该位置标记为已占用。
您可以使用dictionary来实现此目标,例如:
board = dict()
board[(x,y)] = "occupied"
然后你可以很容易地发现它是否被占用了:
if board[(x,y)] == "occupied":
print " this move is unfortunately not available! "