implementing minimax