Given your infinitely powerful computer, you can enumerate all of the move trees starting from a given position until the end of the game, and see how they end up.
If there are multiple moves you could make leaving a position such that you can force a win no matter how the opponent plays, then it doesn't matter which one of them you take, except as a matter of style.
Likewise, if there's no way that you can possibly win, but you can force a draw, it doesn't matter how you do so. And if there is no possibility for you to even draw, then it's time to resign.
The remaining "interesting" positions are the ones where the opponent's skill actually matters — that is, there are legal sequences of moves where you win (or at least draw), but only if your opponent responds to your moves in a certain (suboptimal for them) way.
To choose a best play in those positions, you have to have a model of what the opponent will do, assigning a probability to each possible opponent move in each position — and it has to be a model other than "they play optimally every time", because if they played optimally they would deny you the win! This goes beyond the realm of classical chess engines, and if your opponent is human, it goes into the realm of psychology. But if you had such a model, you could assign every node in the game tree a probability of reaching it, and then maximize your expectation (of chances to win, or of wins minus losses, or whatever).
You could model the opponent as moving randomly — not very realistic at all, but it corresponds to an intuitive policy of "keep your options open", i.e. choose the move that has the greatest number of descendants in which you win.
You could model the opponent as having a fixed chance of making a random mistake (say, they choose the optimal move 90% of the time, and a random legal move the other 10%), in which case your algorithm will assign a high score to trees that give them many chances to make a mistake — e.g. endgames in which a long series of perfect moves on your opponent's part will let them force a draw, but any one wrong move lets you checkmate.
Or you could model the opponent as having a fixed "search depth" (for instance, suppose they can see perfectly up to five moves ahead, but if that's not decisive, they resort to well-known heuristics about material and position). Then you will favor gambits where the opponent seems to be gaining something, only to find out more than five moves later that a given move was fatal.
All of these are wrong, but all of them resemble in some way aspects of the way actual humans play — without access to infinitely powerful computers, and with a recognition that both they and their opponents are imperfect.
with best play
from both players? $\endgroup$