diff options
author | Peter Ward <peteraward@gmail.com> | 2010-09-10 11:49:17 +1000 |
---|---|---|
committer | Peter Ward <peteraward@gmail.com> | 2010-09-10 11:49:17 +1000 |
commit | 368a79abc1982615dc521e2128abd15ba1d28966 (patch) | |
tree | c0845071f39aa111f87797dd46a324e71b8714e2 | |
parent | 56c61e0850478e3aa31b4e559acabcd0f3c4f0d2 (diff) |
Added wrapping support.
-rw-r--r-- | snake.py | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -15,9 +15,10 @@ import traceback from common import * class SnakeEngine(object): - def __init__(self, rows, columns, n_apples, results=False): + def __init__(self, rows, columns, n_apples, wrap=False, results=False): super(SnakeEngine, self).__init__() + self.wrap = wrap self.bots = {} self.results = None if results: @@ -123,9 +124,13 @@ class SnakeEngine(object): nx = x + dx ny = y + dy - if ny < 0 or ny >= self.rows or nx < 0 or nx >= self.columns: - self.remove_bot(letter) - continue + if self.wrap: + ny %= self.rows + nx %= self.columns + else: + if ny < 0 or ny >= self.rows or nx < 0 or nx >= self.columns: + self.remove_bot(letter) + continue oldcell = self.board[ny][nx] if oldcell in (Squares.EMPTY, Squares.APPLE): |