Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/snake/raw-rev/61be18bf77a2
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 07:25:02 2012
Кодировка:

# HG changeset patch
# User Alex Martynov
# Date 1292800662 -10800
# Node ID 61be18bf77a22d097374870055d3b5ad993a5cb7
# Parent 378227a79ebcc787285b98b56311e8c66d75a80b
engine.move_snake simplification

diff -r 378227a79ebc -r 61be18bf77a2 engine.py
--- a/engine.py Mon Dec 20 01:57:18 2010 +0300
+++ b/engine.py Mon Dec 20 02:17:42 2010 +0300
@@ -93,19 +93,18 @@
pass
pass
if len(choose_move) != 0:
- applied_dir = choose_dir[int(rnd.random()*len(choose_dir))]
+ applied_dir = rnd.shuffle(choose_dir)[0]
pass
else:
- dir_cell = self.field[snake.cells[0].y + applied_dir[0], snake.cells[0].x + applied_dir[1]]
- self.move_do()
+ self.move_do(snake, applied_dir)
break
if applied_dir == None:
- applied_dir = snake.legal_dir[int(rnd.random()*len(snake.legal_dir))]
- dir_cell = self.field[snake.cells[0].y + applied_dir[0], snake.cells[0].x + applied_dir[1]]
- self.move_do()
+ applied_dir = snake.legal_dir[0]
+ self.move_do(snake, applied_dir)
pass
return
- def move_do(self, snake, dir_cell):
+ def move_do(self, snake, applied_dir):
+ dir_cell = self.field[snake.cells[0].y + applied_dir[0], snake.cells[0].x + applied_dir[1]]
if dir_cell.type == 'empty':
snake.cells.insert(0,dir_cell)
del snake.cells[-1]