so I tried to implement a tic tac toe game using minimax and alpha beta pruning
this is my code for the available moves
def get_available_moves(board):
moves = []
for i in range(BOARD_SIZE):
for j in range(BOARD_SIZE):
if board[i][j] == ' ':
moves.append((i, j))
return moves
I wrote this code to check for win in all three status (horizontally, virtually, diagonally) and to check for draw
def check_win(board, symbol):
if all(board[i][j] != ' ' for i in range(BOARD_SIZE) for j in range(BOARD_SIZE)):
return None # Return None to indicate a draw
return False
this one to evaluate the board whether its a win loss or draw
def evaluate_board(board):
elif len(get_available_moves(board)) == 0:
return DRAW_SCORE
else:
return 0
and the last one to print the draw result
elif len(get_available_moves(board)) == 0:
print("It's a draw!")
return
New contributor
monster 123 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.