Overview › Code › R81
Code · blind round

R81 · Flocking birds with three rules

blind round 8/11 local models answered

Every answer below carries the name of the model that wrote it. Blind refers to the scoring: the review was done without knowing which model produced which answer — the published result names them.

2 of the 11 local models delivered nothing through our test harness in this round — for reasons that lie with our setup, not with the models. Those cards are marked DNF like any other, but they are not evidence about those models — the reason is noted on the card itself.

Show task
Create ONE self-contained HTML file (STRICT LIMIT: max 7000 characters in total — this is a budget on characters, not on lines, so removing line breaks does not help) that simulates 200 flocking birds on a <canvas> using the three classic rules: separation, alignment and cohesion. Draw each bird as a small triangle pointing in its direction of travel, let flocks form, split and merge on their own, and wrap the birds around the edges. Show the current number of distinct flocks and the average speed. Smooth requestAnimationFrame animation, NO user input, starts immediately and keeps running (restart with a fresh random instance when finished). No external libraries, no comments needed. Output ONLY the HTML file content, nothing else.

The answers

Local models (Brain cluster) — identical prompt, shuffled order (the sequence is not a ranking)
deepseek-r1:14bBLANKFORMAT
Show code
```html
<!DOCTYPE html>
<html>
<head>
    <style>body{margin:0;padding:0;display:flex;justify-content:center;align-items:center;height:100vh;background:#fff}.canvas-container{position:relative}.info{position:absolute;top-left:5px;color:black;font-family:sans-serif}</style>
</head>
<body>
    <div class="info">
        <div id="flocks">Flocks: 0</div>
        <div id="speed">Speed: 0</div>
    </div>
    <canvas class="canvas-container" width="800" height="600"></canvas>

    <script>
        const canvas = document.querySelector('canvas');
        const ctx = canvas.getContext('2d');
        const birds = [];
        const flocks = [];
        const maxBirds = 200;
        let frameCount = 0;

        class Bird {
            constructor() {
                this.reset();
            }

            reset() {
                this.x = Math.random() * canvas.width;
                this.y = Math.random() * canvas.height;
                this.vx = (Math.random() - 0.5) * 2;
                this.vy = (Math.random() - 0.5) * 2;
                this.speed = 1;
                this.angle = 0;
            }

            update() {
                const separationForce = this.applySeparation();
                const alignmentForce = this.applyAlignment();
                const cohesionForce = this.applyCohesion();

                let forceX = (separationForce.x + alignmentForce.x + cohesionForce.x) * 0.1;
                let forceY = (separationForce.y + alignmentForce.y + cohesionForce.y) * 0.1;

                this.vx += forceX;
                this.vy += forceY;

                const speedLimit = Math.sqrt(this.vx ** 2 + this.vy ** 2);
                if (speedLimit > 3) {
                    this.vx *= 0.8;
                    this.vy *= 0.8;
                }

                this.x += this.vx;
                this.y += this.vy;

                if (this.x < 0) this.x = canvas.width;
                if (this.x > canvas.width) this.x = 0;
                if (this.y < 0) this.y = canvas.height;
                if (this.y > canvas.height) this.y = 0;
            }

            applySeparation() {
                let sumX = 0, sumY = 0;
                for (let bird of birds) {
                    if (bird !== this && distance(this, bird) < 30) {
                        sumX += (this.x - bird.x);
                        sumY += (this.y - bird.y);
                    }
                }
                return {x: sumX * 0.1, y: sumY * 0.1};
            }

            applyAlignment() {
                let sumX = 0, sumY = 0, count = 0;
                for (let bird of birds) {
                    if (bird !== this && distance(this, bird) < 80) {
                        sumX += bird.vx;
                        sumY += bird.vy;
                        count++;
                    }
                }
                return {x: (sumX / count || 0) * 0.1, y: (sumY / count || 0) * 0.1};
            }

            applyCohesion() {
                let sumX = 0, sumY = 0;
                for (let bird of birds) {
                    if (bird !== this && distance(this, bird) < 80) {
                        sumX += bird.x;
                        sumY += bird.y;
                    }
                }
                const count = birds.length - 1;
                return {x: (sumX / count - this.x) * 0.3, y: (sumY / count - this.y) * 0.3};
            }

            draw() {
                ctx.beginPath();
                ctx.fillStyle = '#F00';
                ctx.moveTo(this.x, this.y);
                ctx.lineTo(this.x + Math.cos(this.angle) * 5, this.y + Math.sin(this.angle) * 8);
                ctx.lineTo(this.x - Math.cos(this.angle) * 3, this.y + Math.sin(this.angle) * 8);
                ctx.fill();
            }
        }

        function distance(bird1, bird2) {
            return Math.sqrt((bird1.x - bird2.x)**2 + (bird1.y - bird2.y)**2);
        }

        function findFlocks() {
            if (!birds.length) return [];
            const newFlocks = [];
            let currentFlock = [birds[0]];
            
            for (let bird of birds.slice(1)) {
                let minDist = Infinity;
                let nearestBird = null;

                for (let f in newFlocks) {
                    const flockBirds = newFlocks[f];
                    let distToFirst = distance(bird, flockBirds[0]);
                    if (distToFirst < 25 && distToFirst < minDist) {
                        minDist = distToFirst;
                        nearestBird = flockBirds[0];
                    }
                }

                if (!nearestBird || distance(bird, nearestBird) > 25) {
                    currentFlock.push(bird);
                } else {
                    newFlocks[newFlocks.length - 1] = [...newFlocks[newFlocks.length - 1], ...currentFlock];
                    currentFlock = [bird];
                }
            }

            if (currentFlock.length > 0) {
                newFlocks.push(currentFlock);
            }

            return newFlocks;
        }

        function animate() {
            ctx.clearRect(0, 0, canvas.width, canvas.height);

            for (let bird of birds) bird.update();
            
            flocks.value = findFlocks().length;

            let totalSpeed = 0;
            for (let bird of birds) {
                totalSpeed += Math.sqrt(bird.vx ** 2 + bird.vy ** 2);
                bird.draw();
            }

            document.getElementById('flocks').textContent = `Flocks: ${flocks.value}`;
            document.getElementById('speed').textContent = `Speed: ${(totalSpeed / birds.length).toFixed(1)}`;

            if (++frameCount % 60 === 59) {
                // Every second, update speeds
                for (let bird of birds) {
                    bird.speed *= 1 + Math.random() * 0.4 - 0.2;
                    if (bird.speed < 0.5) bird.speed = 0.5;
                }
            }

            requestAnimationFrame(animate);
        }

        function init() {
            for (let i = 0; i < maxBirds; i++) {
                birds.push(new Bird());
            }
            animate();
        }

        // Start fresh simulation
        init();

        window.addEventListener('resize', () => {
            canvas.width = window.innerWidth;
            canvas.height = window.innerHeight;
        });
    </script>
</body>
</html>
```
gemma4:26bharness
No answer reached us (THIN) — and the reason lies with our setup, not with the model: reasoning consumed the entire token budget (3 min 28 s, zero characters of answer); larger budgets are refused by the gateway Counted as a did-not-finish, but it is not evidence about this model.
No usable answer reached the harness (ERR). Counted as a did-not-finish.
qwen3:8bharness
No answer reached us (ERR) — and the reason lies with our setup, not with the model: reasoning consumed the entire token budget and the answer stayed empty; the gateway rejects budgets above 3000 tokens Counted as a did-not-finish, but it is not evidence about this model.
mistral-small:24bERRBLANKLIMFORMAT
Show code
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flocking Birds</title>
<style>
body { margin: 0; overflow: hidden; }
canvas { display: block; }

#info {
    position: absolute;
    top: 10px;
    left: 10px;
    color: white;
    font-family: Arial, sans-serif;
    background-color: rgba(0, 0, 0, 0.5);
    padding: 10px;
    border-radius: 5px;
}
</style>
</head>
<body>
<canvas id="birdCanvas"></canvas>
<div id="info">Flocks: 0 Average Speed: 0</div>
<script>
const canvas = document.getElementById('birdCanvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

class Bird {
    constructor(x, y) {
        this.pos = { x, y };
        this.vel = { x: Math.random() - 0.5, y: Math.random() - 0.5 };
        this.acc = { x: 0, y: 0 };
        this.maxSpeed = 2;
    }

    update() {
        this.pos.x += this.vel.x;
        this.pos.y += this.vel.y;

        if (this.pos.x > canvas.width) this.pos.x = 0;
        if (this.pos.x < 0) this.pos.x = canvas.width;
        if (this.pos.y > canvas.height) this.pos.y = 0;
        if (this.pos.y < 0) this.pos.y = canvas.height;

        this.vel.x += this.acc.x;
        this.vel.y += this.acc.y;

        const speed = Math.sqrt(this.vel.x * this.vel.x + this.vel.y * this.vel.y);
        if (speed > this.maxSpeed) {
            const limitingFactor = this.maxSpeed / speed;
            this.vel.x *= limitingFactor;
            this.vel.y *= limitingFactor;
        }

        this.acc.x = 0;
        this.acc.y = 0;
    }

    applyForce(force) {
        this.acc.x += force.x;
        this.acc.y += force.y;
    }

    edges() {
        if (this.pos.x > canvas.width + 10) this.pos.x = -10;
        if (this.pos.x < -10) this.pos.x = canvas.width + 10;
        if (this.pos.y > canvas.height + 10) this.pos.y = -10;
        if (this.pos.y < -10) this.pos.y = canvas.height + 10;
    }

    flock(birds) {
        const sep = this.separate(birds);
        const ali = this.align(birds);
        const coh = this.cohesion(birds);

        sep.mult(1.5);
        ali.mult(1.0);
        coh.mult(1.0);

        this.applyForce(sep);
        this.applyForce(ali);
        this.applyForce(coh);
    }

    separate(birds) {
        let desiredSeparation = 25;
        const steering = { x: 0, y: 0 };
        let total = 0;

        for (let other of birds) {
            const d = dist(this.pos, other.pos);
            if ((d > 0) && (d < desiredSeparation)) {
                const diff = {x: this.pos.x - other.pos.x, y: this.pos.y - other.pos.y};
                diff.mult(1 / d);
                steering.add(diff);
                total++;
            }
        }

        if (total > 0) {
            steering.div(total);
            steering.normalize();
            steering.mult(this.maxSpeed);

            const steer = { x: steering.x - this.vel.x, y: steering.y - this.vel.y };
            return steer;
        } else {
            return {x: 0, y: 0};
        }
    }

    align(birds) {
        let perceptionRadius = 50;
        const sum = { x: 0, y: 0 };
        let count = 0;

        for (let other of birds) {
            const d = dist(this.pos, other.pos);
            if ((d > 0) && (d < perceptionRadius)) {
                sum.add(other.vel);
                count++;
            }
        }

        if (count > 0) {
            sum.div(count);
            sum.normalize();
            sum.mult(this.maxSpeed);

            const steer = { x: sum.x - this.vel.x, y: sum.y - this.vel.y };
            return steer;
        } else {
            return {x: 0, y: 0};
        }
    }

    cohesion(birds) {
        let perceptionRadius = 50;
        const sum = { x: 0, y: 0 };
        let count = 0;

        for (let other of birds) {
            const d = dist(this.pos, other.pos);
            if ((d > 0) && (d < perceptionRadius)) {
                sum.add(other.pos);
                count++;
            }
        }

        if (count > 0) {
            sum.div(count);

            return this.seek(sum);
        } else {
            return {x: 0, y: 0};
        }
    }

    seek(target) {
        const desired = { x: target.x - this.pos.x, y: target.y - this.pos.y };
        desired.normalize();
        desired.mult(this.maxSpeed);

        const steer = { x: desired.x - this.vel.x, y: desired.y - this.vel.y };
        return steer;
    }

    render() {
        ctx.save();
        ctx.translate(this.pos.x, this.pos.y);
        ctx.rotate(Math.atan2(-this.vel.y, -this.vel.x));
        ctx.beginPath();
        ctx.moveTo(0, 5);
        ctx.lineTo(-3, -7);
        ctx.lineTo( 3,-7);
        ctx.closePath();
        ctx.fillStyle = 'white';
        ctx.fill();
        ctx.strokeStyle = 'black';
        ctx.stroke();
        ctx.restore();
    }
}

const birds = [];
for (let i = 0; i < 200; i++) {
    const x = Math.random() * canvas.width;
    const y = Math.random() * canvas.height;
    birds.push(new Bird(x, y));
}

function dist(a, b) {
    return Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2);
}

function runFlocking() {
    ctx.clearRect(0, 0, canvas.width, canvas.height);

    for (let bird of birds) {
        bird.flock(birds);
        bird.update();
        bird.edges();
        bird.render();
    }

    const flockCount = calculateFlocks(birds);
    const avgSpeed = calculateAverageSpeed(birds);

    document.getElementById('info').innerHTML = `Flocks: ${flockCount} Average Speed: ${avgSpeed.toFixed(2)}`;

    requestAnimationFrame(runFlocking);
}

function calculateFlocks(birds) {
    const visited = new Set();
    let flockCount = 0;

    for (let bird of birds) {
        if (!visited.has(bird)) {
            flockCount++;
            visitBird(bird, visited, birds);
        }
    }

    return flockCount;
}

function visitBird(bird, visited, birds) {
    const stack = [bird];
    while (stack.length > 0) {
        const current = stack.pop();
        if (!visited.has(current)) {
            visited.add(current);
            for (let other of birds) {
                if (dist(current.pos, other.pos) < 50 && !visited.has(other)) {
                    stack.push(other);
                }
            }
        }
    }
}

function calculateAverageSpeed(birds) {
    let totalSpeed = 0;
    for (let bird of birds) {
        const speed = Math.sqrt(bird.vel.x * bird.vel.x + bird.vel.y * bird.vel.y);
        totalSpeed += speed;
    }
    return totalSpeed / birds.length;
}

Math.prototype.add = function(v) { this.x += v.x; this.y += v.y; };
Math.prototype.subtract = function(v) { this.x -= v.x; this.y -= v.y; };
Math.prototype.mult = function(scalar) { this.x *= scalar; this.y *= scalar; };
Math.prototype.div = function(scalar) { this.x /= scalar; this.y /= scalar; };
Math.prototype.normalize = function() {
    const length = Math.sqrt(this.x * this.x + this.y * this.y);
    if (length !== 0) { this.x /= length; this.y /= length; }
};
Math.prototype.limit = function(max) {
    if (this.length > max) {
        this.normalize();
        this.mult(max);
    }
};

runFlocking();
</script>
</body>
</html>
```
qwen3-coder:30bERRBLANKLIMFORMAT
Show code
```html
<!DOCTYPE html>
<html>
<head>
<title>Flocking Simulation</title>
<style>body {margin:0;overflow:hidden;background-color:#111}canvas {display:block;}</style>
</head>
<body>
<canvas id="flockCanvas"></canvas>
<script>
const canvas = document.getElementById('flockCanvas');
const ctx = canvas.getContext('2d');

let width, height;
let birds = [];
let MAX_BIRDS = 200;

// Constants for flocking rules
const VISION_RADIUS = 50;
const SEPARATION_DISTANCE = 10;
const COHESION_WEIGHT = 0.3;
const ALIGNMENT_WEIGHT = 0.5;
const SEPARATION_WEIGHT = 1.5;
const MAX_FORCE = 0.2;
const NEIGHBOR_COUNT_THRESHOLD = 5;

function init() {
    width = window.innerWidth;
    height = window.innerHeight;
    canvas.width = width;
    canvas.height = height;
    birds = [];
    for (let i = 0; i < MAX_BIRDS; i++) {
        birds.push(new Bird(Math.random() * width, Math.random() * height));
    }
    animationLoop();
}

class Vector {
    constructor(x, y) {
        this.x = x || 0;
        this.y = y || 0;
    }
    add(v) { return new Vector(this.x + v.x, this.y + v.y); }
    sub(v) { return new Vector(this.x - v.x, this.y - v.y); }
    mult(s) { return new Vector(this.x * s, this.y * s); }
    magSq() { return this.x * this.x + this.y * this.y; }
    mag() { return Math.sqrt(this.magSq()); }
    normalize() { 
        const m = this.mag();
        return m > 0 ? this.mult(1 / m) : new Vector(0, 0);
    }
    limit(max) {
        if (this.magSq() > max * max) {
            const ratio = max / Math.sqrt(this.magSq());
            return this.mult(ratio);
        }
        return this;
    }

    static random2D() {
        return new Vector((Math.random() - 0.5) * 2, (Math.random() - 0.5) * 2);
    }
}


class Bird {
    constructor(x, y) {
        this.pos = new Vector(x, y);
        this.vel = Vector.random2D().mult(1 + Math.random());
        this.acc = new Vector();
        this.maxSpeed = 3;
        this.maxForce = 0.25;
    }

    applyForce(force) {
        this.acc = this.acc.add(force);
    }

    flock(allBirds) {
        const separation = this.separate(allBirds);
        const alignment = this.align(allBirds);
        const cohesion = this.cohere(allBirds);

        // Weighted combination of forces
        this.applyForce(separation.mult(SEPARATION_WEIGHT));
        this.applyForce(alignment.mult(ALIGNMENT_WEIGHT));
        this.applyForce(cohesion.mult(COHESION_WEIGHT));
    }

    separate(allBirds) {
        let steer = new Vector();
        let count = 0;
        for (const other of allBirds) {
            if (other === this) continue;
            const distSq = this.pos.sub(other.pos).magSq();
            if (distSq < SEPARATION_DISTANCE * SEPARATION_DISTANCE) {
                const diff = this.pos.sub(other.pos);
                diff.normalize();
                diff.div(1 / Math.sqrt(Math.PI * 2)); // Weight inversely by distance
                steer = steer.add(diff);
                count++;
            }
        }
        if (count > 0) {
             steer = steer.mult(1 / count).normalize().mult(this.maxSpeed);
             return this.seek(steer);
        }
        return new Vector();
    }

    align(allBirds) {
        let sumVel = new Vector();
        let count = 0;
        for (const other of allBirds) {
            if (other === this) continue;
            const distSq = this.pos.sub(other.pos).magSq();
            if (distSq < VISION_RADIUS * VISION_RADIUS) {
                sumVel = sumVel.add(other.vel);
                count++;
            }
        }
        if (count > 0) {
            const avg = sumVel.mult(1 / count).normalize().mult(this.maxSpeed);
            return this.seek(avg);
        }
        return new Vector();
    }

    cohere(allBirds) {
        let centerOfMass = new Vector();
        let count = 0;
        for (const other of allBirds) {
            if (other === this) continue;
            const distSq = this.pos.sub(other.pos).magSq();
            if (distSq < VISION_RADIUS * VISION_RADIUS) {
                centerOfMass = centerOfMass.add(other.pos);
                count++;
            }
        }
        if (count > 0) {
            const avgPos = centerOfMass.mult(1 / count).add(this.pos); // Adjust for seeking, but keep it simple: just the target location
            const desiredVel = new Vector(avgPos.x - this.pos.x, avgPos.y - this.pos.y).normalize().mult(this.maxSpeed);
            return this.seek(desiredVel);
        }
        return new Vector();
    }

    // Standard steering force calculation (Desired Velocity - Current Velocity)
    seek(targetVector) {
        const desired = targetVector; 
        let steer = desired.sub(this.vel).limit(this.maxForce);
        steer.normalize().mult(this.maxSpeed);
        return steer;
    }

    update() {
        // Apply forces and calculate new velocity/position
        this.applyForce(new Vector(0, 0)); // Reset acceleration before calculation (flock calls handle this)
        this.flock(birds);

        this.vel = this.vel.add(this.acc);
        this.vel = this.vel.limit(this.maxSpeed);
        this.pos = this.pos.add(this.vel);
        this.acc = new Vector(); // Reset acceleration for next frame

        // Wrap boundaries
        if (this.pos.x < 0) this.pos.x += width; else if (this.pos.x > width) this.pos.x -= width;
        if (this.pos.y < 0) this.pos.y += height; else if (this.pos.y > height) this.pos.y -= height;
    }

    draw() {
        ctx.save();
        ctx.translate(this.pos.x, this.pos.y);
        ctx.rotate(Math.atan2(this.vel.y, this.vel.x));
        ctx.fillStyle = '#FFF';
        ctx.beginPath();
        // Draw triangle (bird representation)
        ctx.moveTo(10, 0);
        ctx.lineTo(-5, -7);
        ctx.lineTo(-5, 7);
        ctx.closePath();
        ctx.fill();
        ctx.restore();
    }

    getSpeed() {
        return this.vel.mag();
    }
}


function drawFlocks(birds) {
    const occupied = new Set();
    let flockCount = 0;

    for (let i = 0; i < birds.length; i++) {
        if (occupied.has(i)) continue;

        // Simple clustering heuristic to detect flocks
        let currentBird = birds[i];
        let clusterMembers = [currentBird];
        let searchQueue = [i];
        let visitedIndices = new Set([i]);

        while (searchQueue.length > 0) {
            const index = searchQueue.shift();
            const bird = birds[index];

            for (let j = i + 1; j < birds.length; j++) {
                if (!visitedIndices.has(j)) {
                    const otherBird = birds[j];
                    const distSq = currentBird.pos.sub(otherBird.pos).magSq();
                    // Use a slightly larger radius for initial detection
                    if (distSq < 150 * 150) { 
                        clusterMembers.push(otherBird);
                        visitedIndices.add(j);
                        searchQueue.push(j);
                    }
                }
            }
        }

        // Check if the cluster is large enough to count as a flock
        if (clusterMembers.length >= NEIGHBOR_COUNT_THRESHOLD) {
             flockCount++;
        }
    }
    return flockCount;
}


function loop() {
    ctx.fillStyle = 'rgba(17, 17, 17, 0.2)';
    ctx.fillRect(0, 0, width, height);

    let totalSpeed = 0;
    const activeBirds = birds.filter(b => b !== undefined);
    for (let i = 0; i < activeBirds.length; i++) {
        activeBirds[i].update();
        activeBirds[i].draw();
        totalSpeed += activeBirds[i].getSpeed();
    }

    const avgSpeed = totalSpeed / activeBirds.length || 0;
    const flockCount = drawFlocks(activeBirds);

    // Display metrics
    ctx.fillStyle = '#FFF';
    ctx.font = '16px Arial';
    ctx.fillText(`Flocks: ${flockCount}`, 10, 25);
    ctx.fillText(`Avg Speed: ${avgSpeed.toFixed(2)}`, 10, 50);

    requestAnimationFrame(loop);
}


// Setup and run
window.addEventListener('resize', () => {
    width = window.innerWidth;
    height = window.innerHeight;
    canvas.width = width;
    canvas.height = height;
});

init();

</script>
</body>
</html>
```
qwen3:14bOKLIMFORMAT
Show code
```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Boid Simulation</title>
    <style>
        body { margin: 0; overflow: hidden; background-color: #111; }
        canvas { display: block; }
        #stats { position: absolute; top: 10px; left: 10px; color: white; font-family: monospace; z-index: 10; background: rgba(0, 0, 0, 0.5); padding: 10px; border-radius: 5px; }
    </style>
</head>
<body>
    <canvas id="boidCanvas"></canvas>
    <div id="stats">Flocks: 0 | Avg Speed: 0.0</div>

    <script>
        const canvas = document.getElementById('boidCanvas');
        const ctx = canvas.getContext('2d');
        let WIDTH, HEIGHT;

        // Simulation Parameters
        const N_BIRDS = 200;
        const MAX_SPEED = 5.0;
        const MAX_FORCE = 0.1;
        const SEPARATION_DISTANCE = 30;
        const COHESION_RADIUS = 80;

        let birds = [];
        let lastTime = 0;

        // --- Vector Helper Functions (to save space) ---
        function createVector(x, y) { return { x: x || 0, y: y || 0 }; }
        function add(v1, v2) { return createVector(v1.x + v2.x, v1.y + v2.y); }
        function sub(v1, v2) { return createVector(v1.x - v2.x, v1.y - v2.y); }
        function mult(v, s) { return createVector(v.x * s, v.y * s); }
        function magSq(v) { return v.x * v.x + v.y * v.y; }
        function magnitude(v) { return Math.sqrt(magSq(v)); }
        function normalize(v) { const m = magnitude(v); return m ? mult(v, 1 / m) : createVector(0, 0); }

        // --- Bird Class/Object Setup ---
        class Bird {
            constructor() {
                this.x = Math.random() * WIDTH;
                this.y = Math.random() * HEIGHT;
                this.vx = (Math.random() - 0.5) * MAX_SPEED;
                this.vy = (Math.random() - 0.5) * MAX_SPEED;
                this.accX = 0;
                this.accY = 0;
            }

            applyForce(force) {
                this.accX += force.x;
                this.accY += force.y;
            }

            // Calculates the desired steering force based on neighbors and rules
            flock(boids) {
                let separation = createVector(0, 0);
                let alignment = createVector(0, 0);
                let cohesion = createVector(0, 0);
                
                let neighborCount = 0;

                for (const other of boids) {
                    if (other === this) continue;

                    let d = sub(this, other);
                    let distSq = magSq(d);
                    let dist = Math.sqrt(distSq);
                    
                    // Check if within cohesion/alignment radius
                    if (neighborCount < 10 && dist < COHESION_RADIUS) { // Limit processing to keep it fast
                         neighborCount++;

                        // Separation: Steer away from nearby boids
                        if (dist < SEPARATION_DISTANCE && dist > 0.1) {
                            let strength = 1 / dist;
                            separation = add(separation, normalize(d));
                        }

                        // Alignment & Cohesion accumulation (always within COHESION_RADIUS)
                        alignment = add(alignment, other);
                        cohesion = add(cohesion, other);
                    }
                }

                // Separate and average forces
                let separationForce = mult(normalize(separation), 1 / Math.max(1, neighborCount));
                let alignmentForce = mult(normalize(alignment), neighborCount * MAX_SPEED / COHESION_RADIUS);
                let cohesionForce = mult(normalize(cohesion), 1 / Math.max(1, neighborCount)) ;

                // Apply rules (Weighted averages)
                this.applyForce(mult(separationForce, 1.5)); // Separation weight higher
                this.applyForce(mult(alignmentForce, 1.0));
                this.applyForce(mult(cohesionForce, 1.0));

                // Limit acceleration
                let acc = createVector(this.accX, this.accY);
                if (magnitude(acc) > MAX_FORCE) {
                    let factor = MAX_FORCE / magnitude(acc);
                    acc = mult(acc, factor);
                }
            }

            // Updates position and velocity using accumulated acceleration
            update() {
                this.vx += this.accX;
                this.vy += this.accY;

                // Limit speed
                let currentSpeed = Math.sqrt(this.vx * this.vx + this.vy * this.vy);
                if (currentSpeed > MAX_SPEED) {
                    let factor = MAX_SPEED / currentSpeed;
                    this.vx *= factor;
                    this.vy *= factor;
                }

                // Apply force damping to prevent infinite acceleration buildup
                this.accX *= 0.1;
                this.accY *= 0.1;


                this.x += this.vx;
                this.y += this.vy;

                // Wrap around boundaries
                if (this.x < 0) this.x = WIDTH;
                if (this.x > WIDTH) this.x = 0;
                if (this.y < 0) this.y = HEIGHT;
                if (this.y > HEIGHT) this.y = 0;
            }

            // Draws the bird as a triangle pointing in direction of travel
            draw() {
                ctx.save();
                ctx.translate(this.x, this.y);
                let angle = Math.atan2(this.vy, this.vx);
                ctx.rotate(angle);

                ctx.beginPath();
                ctx.moveTo(10, 0); // Nose point
                ctx.lineTo(-5, -5); // Wing back left
                ctx.lineTo(-5, 5);  // Wing back right
                ctx.closePath();
                
                ctx.fillStyle = 'white';
                ctx.fill();
                ctx.restore();
            }
        }

        // --- Core Simulation Logic ---

        function handleResize() {
            WIDTH = canvas.width = window.innerWidth;
            HEIGHT = canvas.height = window.innerHeight;
        }

        function initBirds() {
            birds = [];
            for (let i = 0; i < N_BIRDS; i++) {
                birds.push(new Bird());
            }
        }

        function updateSimulation(time) {
            const deltaTime = time - lastTime;
            lastTime = time;

            // 1. Apply Flocking Rules (Acceleration)
            for (let i = 0; i < N_BIRDS; i++) {
                birds[i].flock(birds);
            }

            // 2. Update Physics and Position
            for (const bird of birds) {
                bird.update();
            }

            // 3. Drawing and Stats
            ctx.clearRect(0, 0, WIDTH, HEIGHT);
            for (const bird of birds) {
                bird.draw();
            }

            // Calculate Statistics
            let totalSpeed = 0;
            let flockCount = 0; // Simplified count: Assume a cluster is formed if velocity vectors are close enough to neighbors.
                                 // A robust method requires graph theory, so we'll use a simple proximity check for visualization/estimation.

            for (const bird of birds) {
                totalSpeed += Math.sqrt(bird.vx * bird.vx + bird.vy * bird.vy);
            }
            let avgSpeed = totalSpeed / N_BIRDS;

            // Simple Flock Estimation: Use a temporary grid/distance metric to count clusters
            const visited = new Set();
            const FLOCK_SEARCH_DIST_SQ = 250 * 250; // Max distance for initial cluster check
            let currentFlocks = new Set();

            for (let i = 0; i < N_BIRDS; i++) {
                if (visited.has(i)) continue;

                const startBird = birds[i];
                let neighborsInCluster = [startBird];
                let queue = [{ b: startBird, index: i }];
                let visitedIndices = new Set([i]);

                while (queue.length > 0) {
                    let current = queue.shift();
                    const qB = current.b;
                    const qIdx = current.index;

                    // Check all remaining unvisited birds for proximity
                    for(let j=0; j<N_BIRDS; ++j) {
                        if (!visitedIndices.has(j)) {
                            const other = birds[j];
                            let dSq = (qB.x - other.x)**2 + (qB.y - other.y)**2;

                            if (dSq < FLOCK_SEARCH_DIST_SQ) {
                                neighborsInCluster.push(other);
                                visitedIndices.add(j);
                                queue.push({ b: other, index: j });
                            }
                        }
                    }
                }
                currentFlocks.add(neighborsInCluster.length > 5 ? 'Active' : 'Small'); // Count if cluster is large enough

                // Mark all birds found in this cluster as visited for the next iteration
                for (const neighbor of neighborsInCluster) {
                    visited.add(birds.indexOf(neighbor));
                }
            }
            flockCount = currentFlocks.size;


            document.getElementById('stats').innerHTML = `Flocks: ${Math.max(1, Math.round(flockCount))} | Avg Speed: ${avgSpeed.toFixed(2)}`;

            requestAnimationFrame(updateSimulation);
        }

        // --- Initialization ---
        window.addEventListener('resize', handleResize);
        handleResize();
        initBirds();
        requestAnimationFrame(updateSimulation);

    </script>
</body>
</html>
```
qwen3.5:9bOKLIMFORMAT
Show code
```html
<!DOCTYPE html>
<html>
<head>
<title>Boids Simulation</title>
<style>body { margin: 0; overflow: hidden; background-color: #111; } canvas { display: block; }</style>
</head>
<body>
<canvas id="boidCanvas"></canvas>
<script>
const canvas = document.getElementById('boidCanvas');
const ctx = canvas.getContext('2d');

let W, H;
let birds = [];

// Simulation Parameters
const NUM_BIRDS = 200;
const MAX_SPEED = 3.5;
const MAX_FORCE = 0.1;
const SEPARATION_WEIGHT = 1.5;
const ALIGNMENT_WEIGHT = 1.0;
const COHESION_WEIGHT = 1.0;

function resize() {
    W = canvas.width = window.innerWidth;
    H = canvas.height = window.innerHeight;
}
window.addEventListener('resize', resize);
resize();

class Bird {
    constructor(x, y) {
        this.pos = { x: x, y: y };
        this.vel = { x: Math.random() * 2 - 1, y: Math.random() * 2 - 1 };
        this.acc = { x: 0, y: 0 };
    }

    applyForce(force) {
        this.acc.x += force.x;
        this.acc.y += force.y;
    }

    // Separation: Steer away from nearby birds
    separate(boids) {
        let steering = { x: 0, y: 0 };
        let count = 0;
        for (const other of boids) {
            if (other === this) continue;
            let d = Math.hypot(this.pos.x - other.pos.x, this.pos.y - other.pos.y);
            if (d < 50 && d > 1) {
                let diffX = this.pos.x - other.pos.x;
                let diffY = this.pos.y - other.pos.y;
                steering.x += diffX / d;
                steering.y += diffY / d;
                count++;
            }
        }
        if (count > 0) {
            steering.x /= count;
            steering.y /= count;
            let mag = Math.hypot(steering.x, steering.y);
            steering.x /= mag;
            steering.y /= mag;
            return { x: steering.x * SEPARATION_WEIGHT, y: steering.y * SEPARATION_WEIGHT };
        }
        return { x: 0, y: 0 };
    }

    // Alignment: Steer towards average velocity of neighbors
    align(boids) {
        let avgVel = { x: 0, y: 0 };
        let count = 0;
        for (const other of boids) {
            if (other === this) continue;
            let d = Math.hypot(this.pos.x - other.pos.x, this.pos.y - other.pos.y);
            if (d < 75) {
                avgVel.x += other.vel.x;
                avgVel.y += other.vel.y;
                count++;
            }
        }
        if (count > 0) {
            avgVel.x /= count;
            avgVel.y /= count;
            let mag = Math.hypot(avgVel.x, avgVel.y);
            if (mag > 0) {
                avgVel.x /= mag;
                avgVel.y /= mag;
                return { x: avgVel.x * ALIGNMENT_WEIGHT, y: avgVel.y * ALIGNMENT_WEIGHT };
            }
        }
        return { x: 0, y: 0 };
    }

    // Cohesion: Steer towards the center of nearby birds
    cohese(boids) {
        let center = { x: 0, y: 0 };
        let count = 0;
        for (const other of boids) {
            if (other === this) continue;
            let d = Math.hypot(this.pos.x - other.pos.x, this.pos.y - other.pos.y);
            if (d < 100) {
                center.x += other.pos.x;
                center.y += other.pos.y;
                count++;
            }
        }
        if (count > 0) {
            center.x /= count;
            center.y /= count;
            let desired = { x: center.x, y: center.y };
            let steerX = desired.x - this.pos.x;
            let steerY = desired.y - this.pos.y;
            let dist = Math.hypot(steerX, steerY);
            if (dist > 0) {
                steerX /= dist;
                steerY /= dist;
                return { x: steerX * COHESION_WEIGHT, y: steerY * COHESION_WEIGHT };
            }
        }
        return { x: 0, y: 0 };
    }

    update(boids) {
        let separation = this.separate(boids);
        let alignment = this.align(boids);
        let cohesion = this.cohese(boids);

        this.applyForce(separation);
        this.applyForce(alignment);
        this.applyForce(cohesion);

        // Limit acceleration and apply force
        let accMag = Math.hypot(this.acc.x, this.acc.y);
        if (accMag > MAX_FORCE) {
            this.acc.x *= (MAX_FORCE / accMag);
            this.acc.y *= (MAX_FORCE / accMag);
        }

        // Update velocity and position
        this.vel.x += this.acc.x;
        this.vel.y += this.acc.y;
        let velMag = Math.hypot(this.vel.x, this.vel.y);
        if (velMag > MAX_SPEED) {
            this.vel.x *= (MAX_SPEED / velMag);
            this.vel.y *= (MAX_SPEED / velMag);
        }

        this.pos.x += this.vel.x;
        this.pos.y += this.vel.y;

        // Edge wrapping
        if (this.pos.x < 0) this.pos.x = W; else if (this.pos.x > W) this.pos.x = 0;
        if (this.pos.y < 0) this.pos.y = H; else if (this.pos.y > H) this.pos.y = 0;

        // Reset acceleration for next frame
        this.acc.x = 0;
        this.acc.y = 0;
    }

    draw() {
        ctx.save();
        ctx.translate(this.pos.x, this.pos.y);
        let angle = Math.atan2(this.vel.y, this.vel.x);
        ctx.rotate(angle);
        ctx.beginPath();
        ctx.moveTo(10, 0); // Tip of the triangle
        ctx.lineTo(-5, -5); // Bottom left
        ctx.lineTo(-5, 5);  // Bottom right
        ctx.closePath();
        ctx.fillStyle = '#FFF';
        ctx.fill();
        ctx.restore();
    }
}

function initialize() {
    birds = [];
    for (let i = 0; i < NUM_BIRDS; i++) {
        const x = Math.random() * W;
        const y = Math.random() * H;
        birds.push(new Bird(x, y));
    }
}

function calculateMetrics() {
    let totalSpeedSq = 0;
    for (const b of birds) {
        totalSpeedSq += b.vel.x * b.vel.x + b.vel.y * b.vel.y;
    }
    const avgSpeed = Math.sqrt(totalSpeedSq / NUM_BIRDS);

    // Simple flock counting: count groups of birds that are close together
    let numFlocks = 0;
    let visited = new Array(NUM_BIRDS).fill(false);

    for (let i = 0; i < NUM_BIRDS; i++) {
        if (!visited[i]) {
            numFlocks++;
            let seed = [i];
            let head = 0;
            while (head < seed.length) {
                const currentBirdIndex = seed[head++];
                visited[currentBirdIndex] = true;

                for (let j = currentBirdIndex + 1; j < NUM_BIRDS; j++) {
                    if (!visited[j]) {
                        const b1 = birds[currentBirdIndex];
                        const b2 = birds[j];
                        const dist = Math.hypot(b1.pos.x - b2.pos.x, b1.pos.y - b2.pos.y);
                        if (dist < 30) { // Flocking proximity threshold
                            seed.push(j);
                        }
                    }
                }
            }
        }
    }

    document.getElementById('stats').innerHTML = `Flocks: ${numFlocks}<br>Avg Speed: ${avgSpeed.toFixed(2)}`;
}

function animate() {
    ctx.fillStyle = 'rgba(17, 17, 17, 0.5)';
    ctx.fillRect(0, 0, W, H);

    for (const bird of birds) {
        bird.update(birds);
        bird.draw();
    }

    calculateMetrics();
    requestAnimationFrame(animate);
}

// Setup HUD element dynamically
document.body.insertAdjacentHTML('beforeend', '<div id="stats" style="position: fixed; top: 10px; left: 10px; color: white; font-family: monospace; background: rgba(0, 0, 0, 0.6); padding: 5px;">Initializing...</div>');

initialize();
animate();
</script>
</body>
</html>
```
qwq:32bSTATLIM
Show code
<think>

Okay, let me tackle this problem. I need to create an HTML file that simulates 200 flocking birds following the three rules: separation, alignment, and cohesion. The birds should be drawn as triangles pointing in their direction of travel. The simulation should display the number of distinct flocks and average speed, with wrap-around edges. Also, it has to use requestAnimationFrame and restart when finished without user input. No external libraries, and keep it under 7000 characters.

First, I'll structure the HTML file. The doctype, head with a title, and a canvas element. Then the JavaScript inside a script tag. Since it's self-contained, everything has to be within the HTML.

Starting with the canvas setup. I'll set the canvas size to a reasonable number, maybe 800x600. The context will be 2d. The birds will be stored in an array. Each bird needs position, velocity, and acceleration vectors. The rules will require checking each bird against others within a certain radius for separation, alignment, and cohesion.

Wait, how do I handle the flocking rules? Each bird should avoid others (separation), match their neighbors' direction (alignment), and move towards the average position (cohesion). The separation radius can be a constant, like 50, but maybe needs tuning. The weights for each rule might be important too.

The birds should wrap around the edges. So when their position goes beyond the canvas, they reappear on the opposite side. That means checking x and y positions and mod the canvas dimensions.

Calculating flocks is a bit tricky. Each flock is a group of connected birds. To find the number of flocks, I can use a connected components approach. For each bird, if it hasn't been visited, start a BFS or DFS to mark all connected birds as part of the same flock. The number of times this is done gives the flock count. But with 200 birds, this might be computationally expensive? Maybe using a simpler method, like grouping birds within a certain distance from each other? Wait, the problem states to show the current number of 'distinct' flocks, so a proper connected components approach is needed.

Alternatively, every frame, for each bird, check if they are in a group within a certain radius. But that might not capture all connections. Hmm, perhaps a flood fill algorithm.

But doing this every frame for 200 birds might be slow. Maybe optimize by maintaining a list of flock groups. But that could be complex. Alternatively, every frame, assign each bird to a flock by checking proximity to other birds, but this might not work accurately. Need to think of a way to compute connected components efficiently.

Alternatively, maybe the problem allows a simplified approach where if birds are within a certain radius of each other, they are considered in the same flock. But that might not give accurate count. Hmm. Alternatively, after computing all the rules, when a bird's neighborhood is considered, perhaps each bird's neighbors form a connected graph. To find the number of connected components in this graph, which is the number of flocks.

But how to compute connected components efficiently? For 200 birds, even a O(n^2) approach might be manageable per frame. Let's see. For each bird, check if it's already part of a component. If not, start a BFS to find all connected birds. Each time a component is found, increment the flock count.

So in code, after calculating all the accelerations and updating positions, before drawing, we can run this:

Initialize an array 'visited' of 200 booleans. Initialize flock count to 0.

Loop through each bird:

if not visited[i], then do BFS/DFS to mark all connected birds. Increment flock count.

But what defines 'connected'? Birds are connected if they are within a certain distance (maybe the same as the separation radius?). So in the BFS, the adjacency is based on being within the separation radius.

Wait, but the rules already consider birds within a certain radius. Maybe the separation radius (say, 50) is appropriate for determining flock membership. So birds within that radius are part of the same flock.

Alternatively, maybe a slightly larger radius for flock detection, like 70? Not sure. The exact value might affect flock count, but perhaps the problem allows some flexibility here.

So, the steps each frame:

1. Update each bird's acceleration based on the three rules (separation, alignment, cohesion).

2. Update velocities and positions (with wrap around).

3. Calculate flocks: determine how many connected components exist when birds within separation radius are considered connected.

4. Draw the birds as triangles, pointing in their direction.

5. Display the flock count and average speed.

Starting coding the structure:

- Variables: canvas, ctx, birds array.

Each bird object might have properties:

x, y (position)

vx, vy (velocity)

ax, ay (acceleration)

But maybe we can optimize by storing them in separate arrays for speed? Or maybe objects are okay.

Let me define Bird as an object with those properties.

Initialization: create 200 birds, each with random position and velocity.

The separation, alignment, cohesion rules:

For each bird, loop through all other birds, check distance, and compute the three vectors.

Wait, but for 200 birds, doing O(n^2) is 40,000 operations per frame. That's probably manageable in JS for a canvas animation, but need to be careful.

Alternatively, loop through all pairs once and compute the interactions, but that's O(n^2) anyway.

So code outline for each frame:

Clear the canvas.

Compute for each bird:

Reset acceleration ax, ay.

Loop over all other birds:

if distance < separationRadius, etc.

Compute separation, alignment, cohesion vectors.

Add each to acceleration.

Then clamp the acceleration to a max.

Update velocity, then position with wrap.

Then handle flocks:

Compute connected components.

Then draw each bird as a triangle pointing in direction.

Display flock count and average speed.

Now, the drawing part: each bird is a triangle. To draw a triangle pointing in the direction of velocity, we need to calculate the rotation.

The triangle can be drawn with three points: tip in the direction of the velocity, and two others forming a triangle. To do that, the velocity's heading can be used to rotate the triangle.

Alternatively, the triangle's vertices can be calculated based on the direction vector.

Let me think of the triangle as a small arrow. The main vector is the velocity. The triangle can be a simple three-point shape: tip is at the direction of velocity, and two other points offset perpendicular.

Wait, perhaps it's easier to compute the angle of the velocity vector, then draw the triangle pointing in that direction.

So for each bird, compute the angle theta = Math.atan2(vy, vx). Then draw a triangle with vertices rotated by theta.

The triangle can be, for example, a base of 5 pixels in size. The points could be something like:

The tip is at (x, y), then two other points offset by vectors perpendicular. Maybe:

Let me have a triangle with points like (0, -2), (2, 2), (-2, 2) in some coordinate system, then rotated to face theta.

Alternatively, simpler: the main point is at the center, then a direction vector, then the two sides. Hmm.

Alternatively, using the context's rotation.

So, for each bird:

ctx.save();

ctx.translate(x, y);

ctx.rotate(angle);

draw a triangle: like a line from (0, -2) to (3,0), then to (0
deepseek-r1:32bBLANKFORMAT
Show code
```html
<!DOCTYPE html><html><body style="margin:0;display:flex;justify-content:center;align-items:center;height:100vh;background:#000"><canvas id="c"></canvas><div id="flockInfo" style="position:absolute;color:white;font-family:sans-serif"></div></body>
<script>
const canvas = document.getElementById('c');
const ctx = canvas.getContext('2d');
const flockInfo = document.getElementById('flockInfo');

canvas.width = 800;
canvas.height = 600;

class Bird {
    constructor() {
        this.x = Math.random() * canvas.width;
        this.y = Math.random() * canvas.height;
        this.vx = (Math.random() - 0.5) * 2;
        this.vy = (Math.random() - 0.5) * 2;
        this.fx = 0;
        this.fy = 0;
        this.id = Date.now();
    }
}

let birds = [];
const birdCount = 200;
let flockCount = 0;
let averageSpeed = 0;
let frame = 0;

function init() {
    birds.length = 0;
    for (let i = 0; i < birdCount; i++) {
        birds.push(new Bird());
    }
}

init();

const rules = {
    separationWeight: 1.5,
    alignmentWeight: 1.2,
    cohesionWeight: 1.3,
    viewDistance: 50,
    maxForce: 0.1
};

function updateBirds() {
    frame++;
    
    for (let bird of birds) {
        let separation = {x:0, y:0};
        let alignment = {x:0, y:0};
        let cohesion = {x:0, y:0};
        
        let neighborCount = 0;
        let neighbors = [];
        
        for (let other of birds) {
            if (other.id !== bird.id) {
                const dx = other.x - bird.x;
                const dy = other.y - bird.y;
                const distance = Math.sqrt(dx * dx + dy * dy);
                
                if (distance < rules.viewDistance && distance > 0) {
                    neighborCount++;
                    
                    // Separation
                    let dirX = dx / distance;
                    let dirY = dy / distance;
                    separation.x += -dirX / distance;
                    separation.y += -dirY / distance;
                    
                    // Alignment
                    alignment.x += other.vx;
                    alignment.y += other.vy;
                    
                    // Cohesion
                    cohesion.x += other.x;
                    cohesion.y += other.y;
                }
            }
        }
        
        if (neighborCount > 0) {
            separation.x *= rules.separationWeight / neighborCount;
            separation.y *= rules.separationWeight / neighborCount;
            
            alignment.x = alignment.x * rules.alignmentWeight / neighborCount - bird.vx;
            alignment.y = alignment.y * rules.alignmentWeight / neighborCount - bird.vy;
            
            cohesion.x = (cohesion.x / neighborCount - bird.x) * rules.cohesionWeight;
            cohesion.y = (cohesion.y / neighborCount - bird.y) * rules.cohesionWeight;
        }
        
        bird.fx += separation.x + alignment.x + cohesion.x;
        bird.fy += separation.y + alignment.y + cohesion.y;
    }

    // Apply forces and update positions
    for (let bird of birds) {
        if (Math.abs(bird.fx) > rules.maxForce) {
            bird.fx = (bird.fx / Math.abs(bird.fx)) * rules.maxForce;
        }
        if (Math.abs(bird.fy) > rules.maxForce) {
            bird.fy = (bird.fy / Math.abs(bird.fy)) * rules.maxForce;
        }

        bird.vx += bird.fx;
        bird.vy += bird.fy;

        // Damping
        bird.vx *= 0.98;
        bird.vy *= 0.98;

        bird.x += bird.vx;
        bird.y += bird.vy;

        // Edge wrapping
        if (bird.x < 0) bird.x = canvas.width;
command-r:35bERRSTAT
Show code
<!DOCTYPE html>
<html>
  <head>
    <style type="text/css">
      canvas { border: 2px solid black; }
    </style>
  </head>

  <body style="background-color:black;">
    <canvas id="myCanvas" width="400" height="400"></canvas>

    <script type="application/javascript">

      const canvas = document.getElementById("myCanvas"),
        context = canvas.getContext("2d"),
        w = canvas.width, h = canvas.height;

      let numBirds = 200,
        maxFlocks = Math.floor(numBirds / 10),
        birds = [...Array(numBirds).keys()].map(() => ({
          x: getRandomCoord(w), y: getRandomCoord(h), 
          dx: randomInRange(-5, 5) * w, dy: randomInRange(-5, 5) * h
        })),
        flocks = Array.from({ length: maxFlocks }, () => []), 
        flockSize = [], avgSpeed = [];

      let numFlocks = countDistinctFlocks();
      function countDistinctFlocks() {
        return flockSize.filter(size => size > 0).length;
      }

      animate();
      function drawBird(bird) {
        context.save();
          context.translate(bird.x, bird.y);
          context.rotate(-Math.atan2(bird.dy, bird.dx));
          context.fillRect(7, -3, 6, 6);
        context.restore();
      }

      function animate() {
        requestAnimationFrame(animate);

        birds.forEach((bird, i) => {
          const { x, y, dx, dy } = bird;

          wrapAroundEdges(x, dx, w);
          wrapAroundEdges(y, dy, h);
          
          if (dx !== 0 || dy !== 0) avgSpeed.push(Math.sqrt(dx * dx + dy * dy));

          context.clearRect(0, 0, w, h);
          birds.forEach(drawBird);

          const flock = flocks[i % maxFlocks];
          if (flock.length > 1 && Math.random() < 0.2) {
            bird.dx += randomInRange(-5, 5);
            bird.dy += randomInRange(-5, 5);
          } else {
            flock.forEach(other => {
              const sep = separation(bird, other),
                ali = alignment(bird, other),
                coh = cohesion(bird, i, flocks);

              bird.dx += (sep + ali + coh) * 0.3;
              bird.dy += (sep + ali + coh) * 0.3;
            });
          }

          if (!flock.length || Math.random() < 0.1) flock.push(i);
        });

        avgSpeed = avgSpeed.slice(-25);
        flockSize = flocks.map(f => f.length).sort((a, b) => a - b);
        numFlocks = countDistinctFlocks();
      }

      function separation(birdA, birdB) {
        const dx = birdA.x - birdB.x, dy = birdA.y - birdB.y;

        if (dx * dx + dy * dy < 250) return Math.atan2(-dy, dx);
      }

      function alignment(birdA, birdB) {
        const dx = birdB.dx / flockSize[flockSize.length-1], 
              dy = birdB.dy / flockSize[flockSize.length-1];

        if (dx * dx + dy * dy < 250) return Math.atan2(-dy, dx);
      }

      function cohesion(birdA, index, flocks) {
        const targetX = birds[index].x,
              targetY = birds[index].y;
        
        flockSize.forEach((size, i) => {
          if (i > 0 && size >= numBirds / maxFlocks * (i + 1)) return;
          
          let dx = flocks[i][Math.floor(Math.random() * size)].x - targetX,
              dy = flocks[i][Math.floor(Math.random() * size)].y - targetY;

          if (dx * dx + dy * dy < 250) return Math.atan2(-dy, -dx);
        });
      }

      function wrapAroundEdges(coord, speed, maxCoord) {
        const halfMax = maxCoord / 2;

        if (coord > halfMax || coord < -halfMax) speed *= -1;
      }

      function getRandomCoord(maxCoord) {
        return Math.random() * (maxCoord + maxCoord / 4) - maxCoord / 4;
      }

      function randomInRange(min, max) {
        const range = max - min;

        if (!range) return max;
        
        return min + Math.random() * range;
      }

    </script>
  </body>
</html>
Outside the Brain cluster — same task, same character budget, collected through their own tooling (response times not comparable)
Claude Opus 5frontier referenceOK
Show code
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Flocking Birds</title>
<style>
html,body{margin:0;height:100%;background:#070b14;overflow:hidden}
canvas{display:block}
#hud{position:fixed;top:16px;left:16px;padding:10px 15px;border-radius:9px;
font:12px/1.7 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;letter-spacing:.09em;
color:#7fa8cc;background:rgba(9,15,28,.55);border:1px solid rgba(120,190,255,.22);
backdrop-filter:blur(4px);text-transform:uppercase;pointer-events:none}
#hud b{color:#eaf6ff;font-weight:600;font-size:14px}
#hud i{color:#3f5c78;font-style:normal;padding:0 6px}
</style></head><body>
<canvas id="c"></canvas>
<div id="hud">flocks <b id="f">-</b><i>|</i>avg speed <b id="s">-</b> px/s<i>|</i>birds <b>200</b></div>
<script>
const c=document.getElementById('c'),x=c.getContext('2d'),EF=document.getElementById('f'),ES=document.getElementById('s');
const N=200,R=Math.random;let W,H,S,D,b,par,tR=0,last=0,acc=0;
function rs(){D=Math.min(devicePixelRatio||1,2);W=c.width=Math.round(innerWidth*D);H=c.height=Math.round(innerHeight*D);c.style.width=innerWidth+'px';c.style.height=innerHeight+'px';S=Math.min(W,H)/800;}
function init(){rs();b=[];tR=0;const h0=R()*360,sp0=60+R()*40;
for(let i=0;i<N;i++){const a=R()*6.2832,v=(sp0+R()*50)*S;
b.push({x:R()*W,y:R()*H,vx:Math.cos(a)*v,vy:Math.sin(a)*v,h:h0+R()*80-40});}
x.fillStyle='#070b14';x.fillRect(0,0,W,H);}
function wr(d,m){return d>m*.5?d-m:d<-m*.5?d+m:d}
function find(a){while(par[a]!==a)a=par[a]=par[par[a]];return a}
function step(dt){
const P2=4900*S*S,F2=2704*S*S,E2=576*S*S,MX=175*S,MN=65*S,KS=4200*S*S;
const ax=new Float32Array(N),ay=new Float32Array(N),cx=new Float32Array(N),cy=new Float32Array(N),
sx=new Float32Array(N),sy=new Float32Array(N),n=new Float32Array(N);
par=new Int32Array(N);for(let i=0;i<N;i++)par[i]=i;
for(let i=0;i<N;i++){const A=b[i];
for(let j=i+1;j<N;j++){const B=b[j];
const dx=wr(B.x-A.x,W),dy=wr(B.y-A.y,H),d2=dx*dx+dy*dy;
if(d2>P2||d2===0)continue;
n[i]++;n[j]++;
ax[i]+=B.vx;ay[i]+=B.vy;ax[j]+=A.vx;ay[j]+=A.vy;
cx[i]+=dx;cy[i]+=dy;cx[j]-=dx;cy[j]-=dy;
if(d2<E2){const w=1/d2;sx[i]-=dx*w;sy[i]-=dy*w;sx[j]+=dx*w;sy[j]+=dy*w;}
if(d2<F2){const p=find(i),q=find(j);if(p!==q)par[p]=q;}}}
let tot=0;const seen=new Set();
for(let i=0;i<N;i++){const A=b[i],k=n[i];let fx=0,fy=0;
if(k){fx=(ax[i]/k-A.vx)*1.5+cx[i]/k*1.1+sx[i]*KS;
fy=(ay[i]/k-A.vy)*1.5+cy[i]/k*1.1+sy[i]*KS;}
A.vx+=fx*dt;A.vy+=fy*dt;
let v=Math.hypot(A.vx,A.vy)||1;
if(v>MX){A.vx*=MX/v;A.vy*=MX/v;v=MX}else if(v<MN){A.vx*=MN/v;A.vy*=MN/v;v=MN}
tot+=v;
A.x=(A.x+A.vx*dt+W)%W;A.y=(A.y+A.vy*dt+H)%H;
seen.add(find(i));}
return[seen.size,tot/N];}
function draw(){
x.fillStyle='rgba(7,11,20,.28)';x.fillRect(0,0,W,H);
const L=10*S,T=-6.5*S,Q=4.4*S;
for(let i=0;i<N;i++){const A=b[i],a=Math.atan2(A.vy,A.vx),co=Math.cos(a),si=Math.sin(a);
x.fillStyle='hsl('+A.h+',82%,66%)';
x.beginPath();
x.moveTo(A.x+L*co,A.y+L*si);
x.lineTo(A.x+T*co-Q*si,A.y+T*si+Q*co);
x.lineTo(A.x+T*co+Q*si,A.y+T*si-Q*co);
x.closePath();x.fill();}}
function loop(t){requestAnimationFrame(loop);
if(!last)last=t;let dt=(t-last)/1000;last=t;if(dt>.05)dt=.05;if(dt<=0)return;
tR+=dt;const r=step(dt);draw();
acc+=dt;if(acc>.25){acc=0;EF.textContent=r[0];ES.textContent=(r[1]/D).toFixed(0);}
if(tR>45)init();}
addEventListener('resize',init);
init();requestAnimationFrame(loop);
</script></body></html>
GPT-5.5 (Codex)frontier referenceOK
Show code
<!doctype html><html><head><meta charset=utf-8><title>Flocking Birds</title><style>html,body{margin:0;height:100%;overflow:hidden;background:#071017;color:#dff;font:14px system-ui}canvas{display:block}#s{position:fixed;left:12px;top:10px;background:#0008;padding:8px 10px;border-radius:6px}</style></head><body><canvas id=c></canvas><div id=s></div><script>
const c=document.getElementById("c"),x=c.getContext("2d"),s=document.getElementById("s"),N=200,R=48,SR=18,MS=2.9,MF=.055;let W,H,b=[];
function z(){W=c.width=innerWidth;H=c.height=innerHeight}
onresize=z;z();
function rnd(a){return Math.random()*a}
function reset(){b=[];for(let i=0;i<N;i++){let a=rnd(7);b.push({x:rnd(W),y:rnd(H),vx:Math.cos(a)*(1+rnd(1.5)),vy:Math.sin(a)*(1+rnd(1.5))})}}
reset();
function lim(vx,vy,m){let l=Math.hypot(vx,vy)||1;return l>m?[vx/l*m,vy/l*m]:[vx,vy]}
function flocks(){let p=new Int16Array(N).fill(-1),n=0;for(let i=0;i<N;i++)if(p[i]<0){let q=[i];p[i]=n;for(let h=0;h<q.length;h++){let a=b[q[h]];for(let j=0;j<N;j++)if(p[j]<0){let d=Math.hypot(a.x-b[j].x,a.y-b[j].y);if(d<R*1.3){p[j]=n;q.push(j)}}}n++}return n}
function step(){
 x.fillStyle="#071017";x.fillRect(0,0,W,H);
 let sp=0;
 for(let i=0;i<N;i++){
  let a=b[i],sx=0,sy=0,avx=0,avy=0,cx=0,cy=0,cnt=0,sc=0;
  for(let j=0;j<N;j++)if(i!=j){
   let o=b[j],dx=o.x-a.x,dy=o.y-a.y;
   if(dx>W/2)dx-=W;if(dx<-W/2)dx+=W;if(dy>H/2)dy-=H;if(dy<-H/2)dy+=H;
   let d=Math.hypot(dx,dy);
   if(d<R){avx+=o.vx;avy+=o.vy;cx+=dx;cy+=dy;cnt++;if(d<SR){sx-=dx/(d||1);sy-=dy/(d||1);sc++}}
  }
  if(cnt){avx=avx/cnt-a.vx;avy=avy/cnt-a.vy;cx/=cnt;cy/=cnt}
  a.vx+=sx*.045+avx*.035+cx*.0016;
  a.vy+=sy*.045+avy*.035+cy*.0016;
  let l=lim(a.vx,a.vy,MS);a.vx=l[0];a.vy=l[1];
  l=lim(a.vx,a.vy,.7);if(Math.hypot(a.vx,a.vy)<.7){a.vx=l[0];a.vy=l[1]}
 }
 for(let a of b){
  a.x=(a.x+a.vx+W)%W;a.y=(a.y+a.vy+H)%H;sp+=Math.hypot(a.vx,a.vy);
  let t=Math.atan2(a.vy,a.vx),cs=Math.cos(t),sn=Math.sin(t);
  x.beginPath();x.moveTo(a.x+8*cs,a.y+8*sn);x.lineTo(a.x-6*cs+4*sn,a.y-6*sn-4*cs);x.lineTo(a.x-6*cs-4*sn,a.y-6*sn+4*cs);x.closePath();
  x.fillStyle="#e9fbff";x.fill()
 }
 s.textContent="flocks: "+flocks()+"  avg speed: "+(sp/N).toFixed(2);
 requestAnimationFrame(step)
}
requestAnimationFrame(step)
</script></body></html>
Claude Sonnet 5frontier referenceOK
Show code
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Flock</title>
<style>html,body{margin:0;background:#071018;overflow:hidden;height:100%}canvas{display:block}
#h{position:fixed;top:8px;left:10px;color:#9fe;font:14px monospace;text-shadow:0 0 4px #000}</style>
</head><body><canvas id="c"></canvas><div id="h"></div>
<script>
const cv=document.getElementById('c'),x=cv.getContext('2d');
let W,H;function rz(){W=cv.width=innerWidth;H=cv.height=innerHeight;}
rz();addEventListener('resize',rz);
const N=200,VIS=55,SEP=22,MAXS=3.6,MINS=1.6;
let bx,by,vx,vy;
function init(){
  bx=new Float64Array(N);by=new Float64Array(N);vx=new Float64Array(N);vy=new Float64Array(N);
  for(let i=0;i<N;i++){
    bx[i]=Math.random()*W;by[i]=Math.random()*H;
    const a=Math.random()*6.283;
    vx[i]=Math.cos(a)*2.5;vy[i]=Math.sin(a)*2.5;
  }
}
init();
const parent=new Int32Array(N);
function find(a){while(parent[a]!==a){parent[a]=parent[parent[a]];a=parent[a];}return a;}
function uni(a,b){a=find(a);b=find(b);if(a!==b)parent[a]=b;}
function step(){
  for(let i=0;i<N;i++){
    let sx=0,sy=0,ax=0,ay=0,cx=0,cy=0,cnt=0;
    for(let j=0;j<N;j++){
      if(i===j)continue;
      let dx=bx[j]-bx[i],dy=by[j]-by[i];
      if(dx>W/2)dx-=W;if(dx<-W/2)dx+=W;
      if(dy>H/2)dy-=H;if(dy<-H/2)dy+=H;
      const d=Math.hypot(dx,dy);
      if(d<VIS&&d>0.01){
        cnt++;
        ax+=vx[j];ay+=vy[j];
        cx+=dx;cy+=dy;
        if(d<SEP){sx-=dx/d;sy-=dy/d;}
      }
    }
    if(cnt>0){
      ax/=cnt;ay/=cnt;cx/=cnt;cy/=cnt;
      vx[i]+=ax*0.02+cx*0.0012+sx*0.16;
      vy[i]+=ay*0.02+cy*0.0012+sy*0.16;
    }
    vx[i]+=(Math.random()-0.5)*0.06;
    vy[i]+=(Math.random()-0.5)*0.06;
    const sp=Math.hypot(vx[i],vy[i])||0.01;
    const cl=Math.max(MINS,Math.min(MAXS,sp));
    vx[i]=vx[i]/sp*cl;vy[i]=vy[i]/sp*cl;
  }
  for(let i=0;i<N;i++){
    bx[i]+=vx[i];by[i]+=vy[i];
    if(bx[i]<0)bx[i]+=W;if(bx[i]>=W)bx[i]-=W;
    if(by[i]<0)by[i]+=H;if(by[i]>=H)by[i]-=H;
  }
}
function countFlocks(){
  for(let i=0;i<N;i++)parent[i]=i;
  for(let i=0;i<N;i++)for(let j=i+1;j<N;j++){
    let dx=bx[j]-bx[i],dy=by[j]-by[i];
    if(dx>W/2)dx-=W;if(dx<-W/2)dx+=W;
    if(dy>H/2)dy-=H;if(dy<-H/2)dy+=H;
    if(dx*dx+dy*dy<VIS*VIS)uni(i,j);
  }
  const s=new Set();for(let i=0;i<N;i++)s.add(find(i));return s.size;
}
function draw(){
  x.fillStyle='rgba(7,16,24,0.28)';x.fillRect(0,0,W,H);
  let tot=0;
  for(let i=0;i<N;i++){
    const a=Math.atan2(vy[i],vx[i]);
    tot+=Math.hypot(vx[i],vy[i]);
    x.save();x.translate(bx[i],by[i]);x.rotate(a);
    x.fillStyle='#7fd3ff';
    x.beginPath();x.moveTo(7,0);x.lineTo(-5,3.5);x.lineTo(-5,-3.5);x.closePath();x.fill();
    x.restore();
  }
  const flocks=countFlocks();
  document.getElementById('h').textContent=
    `flocks: ${flocks}   avg speed: ${(tot/N).toFixed(2)}`;
}
let frame=0;
function loop(){
  step();draw();frame++;
  if(frame>6000)init(),frame=0;
  requestAnimationFrame(loop);
}
loop();
</script></body></html>
Results at a glance— every model in this round with score, response time and status.

Who wrote what

ModelBlind scoreLatencyStatus
deepseek-r1:14b —54.1 sOK
gemma4:26b ——harness
llama3.1:8b ——DNF
qwen3:8b ——harness
mistral-small:24b —219.0 sOK
qwen3-coder:30b —71.2 sOK
qwen3:14b —106.5 sOK
qwen3.5:9b —36.0 sOK
qwq:32b —135.9 sOK
deepseek-r1:32b —135.2 sOK
command-r:35b —147.5 sOK