Code Room
Vibe codingHardvc-g359
Subject Ai code reviewLevel Senior–Staff~20 minCommon in Algorithms & data structures interviewsIndustries Computer games, Software development

Question

An AI agent wrote a spatial-hash broadphase for collision in C++. Most collisions work, but objects sometimes tunnel through each other when they sit exactly on a cell boundary, and large objects miss collisions with small ones at the edge of their span. Review the query and find the off-by-one.

cpp
std::vector<Entity*> SpatialHash::Query(const AABB& box) {    int minX = (int)(box.min.x / cellSize);    int maxX = (int)(box.max.x / cellSize);    int minY = (int)(box.min.y / cellSize);    int maxY = (int)(box.max.y / cellSize);    std::vector<Entity*> out;    for (int x = minX; x < maxX; ++x)        // iterate cells the box spans        for (int y = minY; y < maxY; ++y)            for (Entity* e : cells[Key(x, y)])                out.push_back(e);    return out;}
What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.

Describe your solution

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.