Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.cmm.msu.ru/trac/snake/changeset/110%3A763c07539658/?old=109%3A7352863453bc&old_path=
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sat Mar 1 21:46:45 2014
Êîäèðîâêà: IBM-866
Diff [7352863453bc1f7e0fcaabe41f7b2544f6315a35:763c075396582e905425f79cc374bbf70733a6b5] for / òÀÓ Python Battle

Ignore:
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • engine.py

    • Property exe set to *
    r103 r108 ˆà
    8888        returnˆà
    8989    def move_snake(self, snake):ˆà
    90ˆà        dir_to_numb_of_rot={ˆà
    91ˆà            (0,-1):0,ˆà
    92ˆà            (1,0):1,ˆà
    93ˆà            (0,1):2,ˆà
    94ˆà            (-1,0):3}ˆà
    95ˆà        applied_dir = Noneˆà
    ˆà90        head = snake.cells[0]ˆà
    9691        for rule in snake.rules:ˆà
    97ˆà            if applied_dir == None:ˆà
    98ˆà                for direction in snake.legal_dir:ˆà
    99ˆà                    rule.rotate(dir_to_numb_of_rot[direction])ˆà
    100ˆà                    if rule.applies(self.field, snake.cells[0].x, snake.cells[0].y) == True:ˆà
    101ˆà                        applied_dir = directionˆà
    102ˆà                        breakˆà
    103ˆà            else:ˆà
    104ˆà                self.move_do(snake, applied_dir)ˆà
    105ˆà                breakˆà
    106ˆà        if applied_dir == None:ˆà
    ˆà92            for direction in snake.legal_dir:ˆà
    ˆà93                rule.rotate(direction)ˆà
    ˆà94                if rule.applies(self.field, head.x, head.y) == True:ˆà
    ˆà95                    self.move_do(snake, direction)ˆà
    ˆà96                    returnˆà
    ˆà97        if snake.legal_dir != []:ˆà
    10798            self.move_do(snake, snake.legal_dir[0])ˆà
    10899            passˆà
    109100        returnˆà
    110101    def move_do(self, snake, applied_dir):ˆà
    111ˆà        dir_cell = self.field[snake.cells[0].y + applied_dir[0], snake.cells[0].x + applied_dir[1]]ˆà
    ˆà102        head = snake.cells[0]ˆà
    ˆà103        dir_cell = self.field[head.x + applied_dir[0], head.y + applied_dir[1]]ˆà
    112104        if dir_cell.type == 'empty':ˆà
    113105            snake.cells.insert(0,dir_cell)ˆà
    òÀæ òÀæ ˆà
    156148    def legal_moves(self, snake):ˆà
    157149        snake.legal_dir = []ˆà
    ˆà150        head = snake.cells[0]ˆà
    158151        for direction in directions:ˆà
    159ˆà            dir_cell = self.field[snake.cells[0].y + direction[0], snake.cells[0].x + direction[1]]ˆà
    ˆà152            dir_cell = self.field[head.x + direction[0], head.y + direction[1]]ˆà
    160153            if (dir_cell.type == 'empty' or (dir_cell.type == 'tail' and dir_cell.snake != snake)):ˆà
    161154                snake.legal_dir.append(direction)ˆà
  • main.py

    • Property exe set to *
    r103 r107 ˆà
    3737            self.step_id = 0ˆà
    3838            passˆà
    39ˆà        elif self.step_id == 0:ˆà
    ˆà39        if self.step_id == 0:ˆà
    4040            file_name = tkfd.askopenfilename(title="Open file")ˆà
    4141            snake = self.engine.create_snake(snake_number)ˆà
    4242            snake.load(open(file_name, "r"))ˆà
    43ˆà            passˆà
    44ˆà        else:ˆà
    4543            passˆà
    4644        self.engine.refill()ˆà
Note: See TracChangeset for help on using the changeset viewer.