Doubles Matchup Generator
Enter the number of participants (maximum 20) and the number of courts (maximum 5):
ご要望ありがとうございます。以下は、バドミントンやテニスのダブルス対戦表自動生成アプリのコードです。
```
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Doubles Matchup Generator</title>
</head>
<body>
<h1>Doubles Matchup Generator</h1>
<p>Enter the number of participants (maximum 20) and the number of courts (maximum 5):</p>
<form>
<label for="participants">Number of Participants:</label>
<input type="number" id="participants" name="participants" min="1" max="20" required><br>
<label for="courts">Number of Courts:</label>
<input type="number" id="courts" name="courts" min="1" max="5" required><br>
<input type="submit" value="Generate Matchups">
</form>
<div id="matchups"></div>
<script>
function generateMatchups() {
// Get input values
const participants = document.getElementById("participants").value;
const courts = document.getElementById("courts").value;
// Calculate number of matches per participant
const matchesPerParticipant = Math.floor(courts / 2);
// Calculate number of participants who need to rest
const restParticipants = participants % courts;
// Create array of participants
let allParticipants = [];
for (let i = 1; i <= participants; i++) {
allParticipants.push(i);
}
// Shuffle array of participants randomly
for (let i = allParticipants.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[allParticipants[i], allParticipants[j]] = [allParticipants[j], allParticipants[i]];
}
// Create array of matchups
let matchups = [];
let index = 0;
for (let i = 1; i <= matchesPerParticipant; i++) {
for (let j = 1; j <= courts; j++) {
const pair1 = allParticipants[index];
const pair2 = allParticipants[((index + matchesPerParticipant) % participants)];
matchups.push(`<strong>Court ${j}:</strong> ${pair1}&${allParticipants[(index + matchesPerParticipant + 1) % participants]} vs ${pair2}&${allParticipants[((index + 1) % participants)]}`);
index = (index + 1) % participants;
}
}
// Add resting participants
if (restParticipants != 0) {
matchups.push(`<strong>Resting:</strong> ${allParticipants.slice(-restParticipants).join(", ")}`);
}
// Display matchups
document.getElementById("matchups").innerHTML = matchups.join("<br>");
}
document.querySelector("form").addEventListener("submit", function(event) {
event.preventDefault();
generateMatchups();
});
</script>
</body>
</html>
```
このアプリは、入力された参加人数とコート数に応じて、ランダムにダブルスの対戦表を生成します。同じ組み合わせにならないようにするために、参加者の順序をランダムに並べ替え、同時に試合開始するので、同じ人が同じ試合でプレイしないようにしています。休みの人も、別に表示されます。
ジョークがありますか?オプションですが、参加人数が0の場合、「参加者がいません。息抜きしましょう!」というメッセージを表示するのはどうでしょうか?