const ausXI = [ "Travis Head", "Sam Konstas", "Marnus Labuschagne", "Steve Smith", "Cameron Green", "Alex Carey", "Patrick Cummins", "Mitchell Starc", "Josh Hazlewood", "Nathan Lyon", "Scott Boland" ]; const worldXI = [ "Chris Gayle", "Virender Sehwag", "Sachin Tendulkar", "Kumar Sangakkara", "Michael Clarke", "Shane Watson", "Adam Gilchrist", "Shane Warne", "Dale Steyn", "Wasim Akram", "James Anderson" ]; // Assign basic random stats function makeTeam(playerList) { return playerList.map((name, i) => ({ name: name, batting: Math.floor(Math.random() * 36) + 60, // 60–95 bowling: i >= 5 ? Math.floor(Math.random() * 51) + 40 : 0, fielding: Math.floor(Math.random() * 36) + 50 })); } const australia = makeTeam(ausXI); const world = makeTeam(worldXI); // Ball-by-ball sim function simulateInnings(team, overs = 10) { let runs = 0, wickets = 0; const log = []; for (let over = 0; over < overs; over++) { for (let ball = 0; ball < 6; ball++) { if (wickets >= 10) break; const batter = team[wickets]; const runChance = batter.batting + (Math.floor(Math.random() * 21) - 10); let probs; if (runChance < 70) { probs = [0.25, 0.2, 0.15, 0.05, 0.2, 0.05, 0.1]; } else if (runChance < 85) { probs = [0.25, 0.2, 0.15, 0.05, 0.25, 0.07, 0.03]; } else { probs = [0.2, 0.2, 0.15, 0.05, 0.3, 0.08, 0.02]; } const outcome = weightedChoice(["dot", "1", "2", "3", "4", "6", "W"], probs); if (outcome === "W") { log.push(`${batter.name} is OUT!`); wickets++; } else { runs += parseInt(outcome) || 0; log.push(`${batter.name} scores ${outcome} run(s)`); } } } return { runs, wickets, log }; } // Weighted random picker function weightedChoice(items, weights) { let r = Math.random(), sum = 0; for (let i = 0; i < items.length; i++) { sum += weights[i]; if (r <= sum) return items[i]; } return items[items.length - 1]; } // Display on button click function simulateMatch() { const logDiv = document.getElementById("match-log"); logDiv.innerHTML = "
Click "Simulate Match" to see the result!
`; };