Added environment boundaries

Added ternary expressions in the movement functions to detect
boundaries of the cube.