tic_tac_toe/tic_tac_toe.py
def minimax(self, board, move, computerChar, playerChar, depth=0):
		"""
		Implements the minimax algorithm. Returns 1 : computer has won.
		Returns -1 when player wins.
		When it's the computer's turn and it has to return a value to its parent,
		the maximum value from the array is chosen else, the minimum value.
		"""
		[is_win, who_won] = utils.check_win(board, computerChar, playerChar)
		if is_win == 2:			   
			return 0
		if is_win == 1:
			if who_won == computerChar:
				return 1
			if who_won == playerChar:
				return -1
		ret_list = []
		for i in range(9):
			if board[i] == '-':
				if move == computerChar:
					next_move = playerChar
				else:
					next_move = computerChar
				board[i] = move
				minimax_val = self.minimax(board, next_move, computerChar, playerChar, depth + 1)
				board[i] = '-'
				ret_list.append(minimax_val)
		if depth == 0:
			return ret_list
		if move == computerChar:
			return max(ret_list)
		else:
			return min(ret_list)

		Implements the minimax algorithm. Returns 1 : computer has won.
		Returns -1 when player wins.
		When it's the computer's turn and it has to return a value to its parent,
		the maximum value from the array is chosen else, the minimum value.
		
Implements the minimax algorithm. Returns 1 : computer has won.
Returns -1 when player wins.
When it's the computer's turn and it has to return a value to its parent,
the maximum value from the array is chosen else, the minimum value.
Implements the minimax algorithm . Returns 1 : computer has won . Returns - 1 when player wins . When it ' s the computer ' s turn and it has to return a value to its parent the maximum value from the array is chosen else the minimum value .
def minimax(self, board, move, computerChar, playerChar, depth=0):
		[is_win, who_won] = utils.check_win(board, computerChar, playerChar)
		if is_win == 2:			   
			return 0
		if is_win == 1:
			if who_won == computerChar:
				return 1
			if who_won == playerChar:
				return -1
		ret_list = []
		for i in range(9):
			if board[i] == '-':
				if move == computerChar:
					next_move = playerChar
				else:
					next_move = computerChar
				board[i] = move
				minimax_val = self.minimax(board, next_move, computerChar, playerChar, depth + 1)
				board[i] = '-'
				ret_list.append(minimax_val)
		if depth == 0:
			return ret_list
		if move == computerChar:
			return max(ret_list)
		else:
			return min(ret_list)
def minimax ( self , board , move , computerChar , playerChar , depth = 0 ) : [ is_win , who_won ] = utils . check_win ( board , computerChar , playerChar ) if is_win == 2 : return 0 if is_win == 1 : if who_won == computerChar : return 1 if who_won == playerChar : return - 1 ret_list = [ ] for i in range ( 9 ) : if board [ i ] == '-' : if move == computerChar : next_move = playerChar else : next_move = computerChar board [ i ] = move minimax_val = self . minimax ( board , next_move , computerChar , playerChar , depth + 1 ) board [ i ] = '-' ret_list . append ( minimax_val ) if depth == 0 : return ret_list if move == computerChar : return max ( ret_list ) else : return min ( ret_list )
Implements the minimax algorithm.
Implements the minimax algorithm .
"""
		Implements the minimax algorithm. Returns 1 : computer has won.
		Returns -1 when player wins.
		When it's the computer's turn and it has to return a value to its parent,
		the maximum value from the array is chosen else, the minimum value.
		"""
self
board
move
computerChar
playerChar
depth