私は、タスクを勝ち取ろうとする 2 つの「チーム」として最もよく説明される論理的な状況を持っています。このタスクの結果は、1 人の勝者、同点 (引き分け)、または勝者なし (膠着状態) のいずれかです。
現在、ネストされた if/else ステートメントを次のように使用しています。
// using PHP, but the concept seems language agnostic.
if ($team_a->win()) {
if ($team_b->win()) {
// this is a draw
} else {
// team_a is the winner
}
} else {
if ($team_b->win()) {
// team_b is the winner
} else {
// This is a stalemate, no winner.
}
}
これはかなりスパゲッティのようで、繰り返しのようです。もっと論理的で DRY なパターンはありますか?