I am trying to make a tic tac toe AI and ran into this little problem.
def tic_tac_toe_AI(board):
...
if board[5] == '':
return 5
...
This appears in a function where board is a dicitionary. But I get this message and I dont know why:
if board[5] == '':
^
IndentationError: expected an indented block
Ok so the full code snippet is here:
def AI_easy(board, symbol):
if symbol == 'X':
computer = 'X'
player = 'O'
else:
computer = 'O'
player = 'X'
possible_win_moves = test_win(board, computer)
if len(possible_win_moves) > 0:
print(possible_win_moves)
return random_move(possible_win_moves)
possible_lose_moves = test_win(board, player)
if len(possible_lose_moves) > 0:
return random_move(possible_lose_moves)
possible_moves = []
for i in [1,3,7,9]:
if board[i] == '':
possible_moves.append(i)
if i == 9:
if board[5] == '':
return 5
possible_moves = []
for i in [2,4,6,8]:
if board[i] == '':
possible_moves.append(i)
if i == 8:
return random_move(possible_moves)
And I use an editor were 4 spaces are automatically replaced by one tab. So this is not the problem.
In such problems you should provide the entire block of code so others can help you properly,
This error occurs because python makes use of procedural language, if you miss out on adding tabs or spaces between your lines of code, then you will most likely experience this error.
you should try online code formatter such as this,
https://www.tutorialspoint.com/online_python_formatter.htm
also have a look at this website,
The problem is the if i == 9:
2 lines above where the error says it's from
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.