BRASS & ENTROPY — From Maxwell's Demon to a One-Button Game in MATLAB

Can a single button create order from chaos?
BRASS & ENTROPY is an educational puzzle game inspired by Maxwell's demon. The goal is to create a temperature difference between two gas chambers by controlling a mechanical gate.
The game combines particle dynamics, thermodynamics and a Victorian visual aesthetic, entirely within MATLAB.
1. Turning physics into gameplay
Twelve particles move continuously through two chambers. Each button press temporarily opens the gate, allowing particles to move between them.
The player must guide faster particles toward the hot chamber and slower particles toward the cold chamber.
Across three experiments, the required temperature ratio increases, while population constraints and a limited number of gate openings make the final challenge more demanding.
2. Simulating elastic collisions
Particle collisions are calculated using the relative velocity projected onto the collision normal.
For two particles of equal mass:
nv=dv/dist;
vn=sum((s.v(i,:)-s.v(j,:)).*nv);
if vn<0
s.v(i,:)=s.v(i,:)-vn*nv;
s.v(j,:)=s.v(j,:)+vn*nv;
end
The condition vn<0 ensures that the velocity correction is applied only when the particles are approaching each other.
This preserves kinetic energy and momentum during particle-particle collisions.
3. Calculating relative temperature
Rather than assigning an arbitrary temperature to each chamber, the simulation calculates a relative temperature from the mean kinetic energy of its particles:
e=sum(s.v.^2,2)/2;
left=s.p(:,1)<400;
s.N=[sum(left) sum(~left)];
s.T=[sum(e(left)) sum(e(~left))]./max(s.N,1)/s.e0;
s.R=s.T(2)/max(s.T(1),1e-10);
Logical indexing and vectorized operations allow both chambers to be evaluated efficiently.
The temperature indicators therefore respond directly to the simulated particle dynamics.
4. Improving simulation stability
To reduce missed collisions, each frame is divided into smaller physics steps:
n=ceil(dt/.003);
h=dt/n;
This limits each simulation step to approximately 3 milliseconds, independently of the rendering frame rate.
During prototype testing, the maximum relative energy error was approximately 1.78 × 10⁻¹⁵.
5. Creating a Victorian laboratory
All visual elements are generated procedurally in MATLAB, including brass frames, glass chambers, particle trails, analog temperature gauges and the animated mechanical gate.
Graphics objects are created during initialization and reused throughout gameplay, avoiding unnecessary object creation.
6. What the experiment teaches
The game illustrates how selective particle transport can create a difference in mean kinetic energy.
It is an idealized model of Maxwell's demon. Information processing and memory-erasure costs are not included, so the simulation does not imply a violation of the second law of thermodynamics.
Developed using OpenAI Codex and MATLAB MCP, the game was manually playtested, numerically verified and successfully validated within the 10,000-character limit.
Play BRASS & ENTROPY: