Improvement algorithm in snake.py