61 lines
2.5 KiB
TypeScript
61 lines
2.5 KiB
TypeScript
// Test asteroid destruction mechanics
|
|
import { AsteroidsSimulation } from './AsteroidsSimulation';
|
|
|
|
console.log('=== ASTEROID DESTRUCTION TEST ===\n');
|
|
|
|
// Test: How many hits does it take to destroy asteroids?
|
|
const sim = new AsteroidsSimulation(42);
|
|
|
|
console.log('Initial asteroids:', sim.asteroids.length);
|
|
console.log('Initial asteroid sizes:', sim.asteroids.map(a => a.size));
|
|
|
|
// Fire 100 shots in a circle to hit asteroids
|
|
for (let i = 0; i < 200; i++) {
|
|
// Rotate and shoot constantly
|
|
const rotation = Math.sin(i * 0.1);
|
|
sim.update([rotation, 1, 1]); // Rotate, thrust, shoot
|
|
|
|
if (i % 20 === 0) {
|
|
console.log(`\nStep ${i}:`);
|
|
console.log(` Asteroids: ${sim.asteroids.length}`);
|
|
console.log(` Destroyed: ${sim.asteroidsDestroyed}`);
|
|
console.log(` Shots fired: ${sim.shotsFired}`);
|
|
console.log(` Shots hit: ${sim.shotsHit}`);
|
|
console.log(` Bullets active: ${sim.bullets.length}`);
|
|
console.log(` Hit rate: ${sim.shotsFired > 0 ? ((sim.shotsHit / sim.shotsFired) * 100).toFixed(1) : 0}%`);
|
|
}
|
|
}
|
|
|
|
console.log('\n=== FINAL RESULTS ===');
|
|
console.log(`Total asteroids destroyed: ${sim.asteroidsDestroyed}`);
|
|
console.log(`Total shots fired: ${sim.shotsFired}`);
|
|
console.log(`Total hits: ${sim.shotsHit}`);
|
|
console.log(`Hit rate: ${((sim.shotsHit / sim.shotsFired) * 100).toFixed(1)}%`);
|
|
console.log(`Asteroids per hit: ${(sim.asteroidsDestroyed / sim.shotsHit).toFixed(2)}`);
|
|
console.log(`\nExpected: 1 hit = 1 asteroid destroyed (they should split, not take multiple hits)`);
|
|
|
|
// Test 2: Single asteroid, single bullet
|
|
console.log('\n=== SINGLE HIT TEST ===');
|
|
const sim2 = new AsteroidsSimulation(100);
|
|
const initialCount = sim2.asteroids.length;
|
|
const initialDestroyed = sim2.asteroidsDestroyed;
|
|
|
|
// Position ship to face an asteroid and shoot
|
|
for (let i = 0; i < 50; i++) {
|
|
sim2.update([0, 0, i === 20 ? 1 : 0]); // Shoot once at step 20
|
|
}
|
|
|
|
console.log(`Initial asteroids: ${initialCount}`);
|
|
console.log(`Final asteroids: ${sim2.asteroids.length}`);
|
|
console.log(`Destroyed: ${sim2.asteroidsDestroyed - initialDestroyed}`);
|
|
console.log(`Shots fired: ${sim2.shotsFired}`);
|
|
console.log(`Hits: ${sim2.shotsHit}`);
|
|
|
|
if (sim2.shotsHit > 0 && sim2.asteroidsDestroyed > initialDestroyed) {
|
|
console.log('✓ One hit destroys one asteroid (correct!)');
|
|
} else if (sim2.shotsHit === 0) {
|
|
console.log('⚠ No hits registered (might need better aim)');
|
|
} else {
|
|
console.log('✗ Hit registered but no destruction (BUG!)');
|
|
}
|