completed minimax algorithm