Minimax algorithm implementation