The World’s Largest Online Community for Developers

'; python - I am getting TypeError: 'NoneType' object is not subscriptable in tictactoe but I tried solving from similar problems online but didn't work - LavOzs.Com

In result method we give input board which is list of list of 3 elements like in tictactoe and action as in a place where we want to keep X or O in tuple form eg. if we put X in centre and board is completely empty then it will look like;

 result([[None, None, None], [None, None, None], [None, None, None]], (1,1))

So initially in first step it is not showing any error when we make move for first time but secong time it is showing error.

Code of method:

def result(board, action):
Returns the board that results from making move (i, j) on the board.
#play = player(board)
tempboard = board
print("board...........", board)
print("Action[0] ===> ", action[0])
print("Action[1] ===> ", action[1])
if board[action[0]][action[1]] == EMPTY:
    tempboard[action[0]][action[1]] = player(board)
    return tempboard
    raise NotImplementedError('Invalid Action')

While the error being: -

board........... [[None, None, None], [None, None, None], [None, None, None]]
Action[0] ===>  1
Action[1] ===>  2
[[None, None, None], [None, None, 'X'], [None, None, None]]
board........... [[None, None, None], [None, None, 'X'], [None, None, None]]
Traceback (most recent call last):
  File "C:/Users/hkfghdk/Google Drive/VIT/Harvard/CS50 AI/week0/tictactoe/", line 116, in <module>
    board = ttt.result(board, move)
  File "C:\Users\hkfghdk\Google Drive\VIT\Harvard\CS50 AI\week0\tictactoe\", line 68, in result
    print("Action[0] ===> ", action[0])
TypeError: 'NoneType' object is not subscriptable

I think it is because of input is not valid from action try and print action it will be out of range or something