Simulation code for FYP