'rock', 'B' => 'paper', 'C' => 'scissor', 'X' => 'lose', 'Y' => 'draw', 'Z' => 'win', ]; $shapes = [ 'rock' => 1, 'paper' => 2, 'scissor' => 3, ]; foreach ($rounds as $round) { [$opponent, $needs_to_end] = explode(' ', $round); $opponent = $types[$opponent]; $needs_to_end = $types[$needs_to_end]; switch ($needs_to_end) { case 'draw': $total_score += 3; $total_score += $shapes[$opponent]; break; case 'win': $total_score += 6; switch ($opponent) { case 'rock': $total_score += $shapes['paper']; break; case 'paper': $total_score += $shapes['scissor']; break; case 'scissor': $total_score += $shapes['rock']; break; } break; case 'lose': switch ($opponent) { case 'rock': $total_score += $shapes['scissor']; break; case 'paper': $total_score += $shapes['rock']; break; case 'scissor': $total_score += $shapes['paper']; break; } } } echo $total_score;