Change UI
This commit is contained in:
@@ -75,23 +75,36 @@ export default function SnakeAI() {
|
||||
const animate = (timestamp: number) => {
|
||||
const elapsed = timestamp - lastUpdateRef.current;
|
||||
|
||||
// Non-linear speed scaling:
|
||||
// Speed 1: ~5000ms (5s) per generation - Observation mode
|
||||
// Speed 5: ~1000ms (1s)
|
||||
// Speed 20: ~50ms - Turbo training
|
||||
// Formula: Base delay divided by speed, with a visual observation bias
|
||||
// Speed handling logic:
|
||||
// 1-20: Visual speeds (delay between generations)
|
||||
// 21-100: Turbo speeds (multiple generations per frame)
|
||||
|
||||
let updateInterval;
|
||||
if (speed <= 5) {
|
||||
// Speeds 1-5: 10s down to 2s
|
||||
updateInterval = 12000 / speed;
|
||||
if (speed <= 20) {
|
||||
// Standard visual mode
|
||||
let updateInterval;
|
||||
if (speed <= 5) {
|
||||
// Speeds 1-5: Very slow observation
|
||||
updateInterval = 12000 / speed;
|
||||
} else {
|
||||
// Speeds 6-20: 62.5ms to 1000ms
|
||||
// speed 20 -> 1000/16 = 62.5ms
|
||||
// speed 6 -> 1000/2 = 500ms
|
||||
updateInterval = 1000 / (speed - 4);
|
||||
}
|
||||
|
||||
if (elapsed >= updateInterval) {
|
||||
runGeneration();
|
||||
lastUpdateRef.current = timestamp;
|
||||
}
|
||||
} else {
|
||||
// Speeds 6-20: Linear fast
|
||||
updateInterval = 1000 / (speed - 4);
|
||||
}
|
||||
// Turbo mode: Run multiple generations per frame
|
||||
// Speed 21 -> 1 gen per frame (~60 eps)
|
||||
// Speed 100 -> 10 gens per frame (~600 eps)
|
||||
const gensPerFrame = Math.floor((speed - 10) / 10);
|
||||
|
||||
if (elapsed >= updateInterval) {
|
||||
runGeneration();
|
||||
for (let i = 0; i < gensPerFrame; i++) {
|
||||
runGeneration();
|
||||
}
|
||||
lastUpdateRef.current = timestamp;
|
||||
}
|
||||
|
||||
@@ -118,7 +131,7 @@ export default function SnakeAI() {
|
||||
};
|
||||
|
||||
return (
|
||||
<AppContainer title="Neural Network Snake Evolution">
|
||||
<AppContainer title="Snake Evolution">
|
||||
<div className="snake-ai-layout">
|
||||
<div className="left-panel">
|
||||
<BestSnakeDisplay
|
||||
|
||||
Reference in New Issue
Block a user