在Python中创建类时的位置参数问题 更新

在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

我目前正在尝试将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('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:Your
BoardHandler
代码很好。只需停止将在
main1v1
中创建的
mainboard
传递给
BoardHandler
的所有方法即可。例如,使用
b.getValidMoves(主板,可玩性)
而不是
b.getValidMoves(可玩性)
Yeah^^,但问题是,我如何使用getNewBoard()操作resetBoard(),而不将其返回给None?我将添加更多的板操作方法,如
make_a_move()
print_board()
以及其他一些您认为对简化电路板处理非常有用的东西。@quamrana但如果是这样,我的整个程序将停止工作,因为需要在getNewBoard中创建列表才能放置平铺