Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/snake/rev/c68b54a43501
Дата изменения: Unknown
Дата индексирования: Mon Oct 1 23:57:45 2012
Кодировка:
snake: c68b54a43501

snake

changeset 104:c68b54a43501

Rule.rotate now accepts target direction, not number of times to rotate
author Daniil Alexeyevsky <me.dendik@gmail.com>
date Mon, 20 Dec 2010 11:22:26 +0300
parents 30d062a2d532
children bfd8f8d778a8 7352863453bc
files snake.py
diffstat 1 files changed, 6 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/snake.py	Mon Dec 20 04:03:55 2010 +0300
     1.2 +++ b/snake.py	Mon Dec 20 11:22:26 2010 +0300
     1.3 @@ -122,10 +122,13 @@
     1.4                          return False
     1.5          return True
     1.6  
     1.7 -    def rotate (self, rot):
     1.8 -        """Rotate rule pattern `rot` times counterclockwise."""
     1.9 -        for i in range(((rot % 4) + 4) % 4):
    1.10 +    def rotate (self, direction):
    1.11 +        """Rotate rule pattern to head in `direction`."""
    1.12 +        for i in range(4):
    1.13 +            if self.direction == direction:
    1.14 +                return
    1.15              self.rotate_ccw()
    1.16 +        raise AssertionError("Illegal direction: %s" % direction)
    1.17  
    1.18      def rotate_ccw(self):
    1.19          """Rotate rule pattern one time counterclockwise."""