"At the end when all board is filled check either the solution is valid or not. If valid user win else loose. Count the number of moves as well." code example
Example: preventing players from changing existing entries in tic tac toe game
# Checking whether the position on the tic tac board is occupied or not.
def place_marker(board, marker, position):
if board[position] == ' ':
board[position] = marker
else:
print("That space is already occupied.")