Implemented Stack-based algorithm to prevent any movement beyond game walls.