In this very finite thermodynamics simulation things are set up with fairly good physics. We can define pressure P, volume V, and temperature T.
T is a measure of the average translational kinetic energy of the molecules of a gas. Since the number of moles, n, is proportional to the number of molecules, N, the product nT (or nRT or NT) is a measure of the sum of all the individual molecular kinetic energies (in this simple monatomic gas, this sum is the internal energy). In our simulation, initially one molecule is set in motion with a speed v and kinetic energy proportional to v2, this providing the internal energy. As (elastic) collisions occur this energy is distributed among the collection of molecules, but the total internal energy remains constant. One can choose 3 internal energies: E/2, E and 2E. For each choice, the products nRT and NT are fixed, so if N is fixed, then doubling E to 2E will also double the temperature (T is proportional to E/N). For a fixed V and fixed total internal energy (and therefore fixed NT), changing the number of molecules should not change the pressure, since p = nRT/V = constant(internal energy)/V (obviously T will change if N changes and the internal energy is constant).
One has to be a little tricky with the volume because the size of the molecules is so large compared to the size of the area. Things here are adjusted so that the usable area (volume) is V, V/2 or V/4, where V is the initial large volume.
Every time a ball hits a wall, the component of its momentum perpendicular to the wall is reversed. This causes a little push on the wall:
Here the momentum P is computed as an average over time of these momentum changes. Consequently each time the thing is restarted with new initial conditions it takes a little while to settle down to a final (somewhat fluctuating) pressure.
In general we still expect PV = N(constant)T, where N = the number of molecules, and this simulation, which uses a pretty good engine for determining the results of collisions, does a pretty good job of demonstrating that. Make changes to the initial conditions, predict the resulting pressure based on the present pressure, then hit "Restart".