我目前正在编写一个名为 Othello 的游戏版本,您可以在其中选择棋盘的大小(从 4x4 到 10x10 交替)。现在,当我尝试插入错误消息时,当您输入棋盘区域之外的坐标时,它不起作用。目前,当您将瓷砖放置在非法移动中时的输入以及您仅输入 1 个坐标或多个坐标(对于 x 和 y 坐标应该只有两个作为一个)
(对不起,我知道我已经发布了一个非常相似的问题,但是当我解决了这个问题时,当我继续我的工作时,问题又出现了)
def isOnBoard(self, x, y):
return x >= 0 and x <= self.size-1 and y >= 0 and y <= self.size-1
def legalMove(self, tile, startX, startY):
if not self.isOnBoard(startX, startY) == False\
or self.board[startX][startY] != ' '\
or not self.isOnBoard(startX, startY):
return False
#(lots more down here that checks if the placed move is legal but nonrelevant to the question)
def playerMove(self,tile):
while True:
move = input().lower()
if self.legalMove(tile, x, y) == False:
print('Wrong input, try again') #<--- checks that the input coordinate is legal
else:
break
else:
print('this was wrong try again!.') #<-- checks that input coordinate just consists of two characters
return [x, y]
if self.board[startX][startY] != ' ' or not self.isOnBoard(startX, startY): IndexError: list index out of range