Write a function make_human_move(current_player, board), which does the following:
- Print out the player's shape (e.g. if the player shape is 'X', the function prints "X's move").
- Asks the human player for his/her move. The message asked is "Enter row and column [0 - 2]: ".
- A move consists of two integer values separated by a space (e.g. '0 0'). You can assume the input will always be two integer values separated by a space.
- The function checks if the move is valid or not.
a) A valid move is when the integer value is between 0 and 2 for both row and column values.
b) It also makes sure that a valid location on the board is empty (i.e. currently an empty space character ' '). - If a move is invalid, the function prints "Illegal move. Try again." and repeats from step 2.
- Once a valid move is entered, the board state is updated.
This is how I am doing it right now.
def make_human_move(current_player, board):
"""Given a board state and the human piece ('O' or 'X')
ask the player for a location to play in. Repeat until a
valid response is given. Then make the move, i.e., update the board by setting the chosen cell to the player's piece.
"""
print(current_player + "'s move")
user_input = input("Enter row and column [0 - 2]: ")
input_list = user_input.split()
while True:
restart = False
for i in input_list:
if (int(i) > 2 or int(i) < 0) or (board[int(input_list[0])][int(input_list[1])] != " "):
print("Illegal move. Try again.")
user_input = input("Enter row and column [0 - 2]: ")
input_list = user_input.split()
restart = True
break
if restart:
continue
else:
board[int(input_list[0])][int(input_list[1])] = current_player
break