在Python中创建类时的位置参数问题 更新
我目前正在尝试将CLAS更改为在Python中创建类时的位置参数问题 更新,python,Python,我目前正在尝试将CLAS更改为 def getPlayerMove(getNewBoard,playerTile): b=BoardHandler() b.getNewBoard # Let the player type in their move. # Returns the move as [x, y] DIGITS1TO8 = '1 2 3 4 5 6 7 8 9 10'.split() while True: print
def getPlayerMove(getNewBoard,playerTile):
b=BoardHandler()
b.getNewBoard
# Let the player type in their move.
# Returns the move as [x, y]
DIGITS1TO8 = '1 2 3 4 5 6 7 8 9 10'.split()
while True:
print('Din tur B')
move = input().lower()
您的板保存在
BoardHandler
实例的self.board
字段中,因此板上的任何操作都应通过BoardHandler
方法连接
在代码中指定mainboard=b.getNewBoard()
。该方法在BoardHandler
实例b
中操作板,并返回None
所以实际上mainboard=None
将其作为参数传递给b.resetBoard()
(不接受参数),这就是错误的来源
尝试通过
BoardHandler
方法实现所有的电路板操作。很难说没有看到drawBoard
的定义。请提供完整的错误消息和回溯。您有几个问题getNewBoard
不返回任何内容,但您使用返回值作为drawBoard
和resetBoard
的参数,这两个参数都不带参数。除了@quamrana外,请修复缩进和代码格式。请提供一个完整的示例,我建议您阅读Python中类的工作原理,特别是成员函数中self
参数的含义。您能给我一个通过类实现主板的示例吗?@Pythongirl:YourBoardHandler
代码很好。只需停止将在main1v1
中创建的mainboard
传递给BoardHandler
的所有方法即可。例如,使用b.getValidMoves(主板,可玩性)
而不是b.getValidMoves(可玩性)
Yeah^^,但问题是,我如何使用getNewBoard()操作resetBoard(),而不将其返回给None?我将添加更多的板操作方法,如make_a_move()
,print_board()
以及其他一些您认为对简化电路板处理非常有用的东西。@quamrana但如果是这样,我的整个程序将停止工作,因为需要在getNewBoard中创建列表才能放置平铺