  In simulations of crystals, unlike liquids or gases, it may happen that the
properties of the studied system depend not only on the volume of the
simulation cell but also on its shape. For such cases it is desirable to change
the shape of the box on the fly in the course of the simulation as it may not
be known ahead of time which geometry fits the studied system best. In this
work we derive an algorithm for this task based on the condition that the
distribution of specific geometrical parameter observed in simulations at a
constant volume matches that observed in the constant-pressure ensemble. The
proposed algorithm is tested for the system of hard-core ellipses which makes
lattices of different types depending on the asphericity parameter of the
particle. It is shown that the performance of the algorithm critically depends
on the range of the sampled geometrical parameter. If the range is narrow, the
impact of the sampling method is minimal. If the range is large, inadequate
sampling can lead to significant distortions of the relevant distribution
functions and, as a consequence, errors in the estimates of free energy.
