Clean
This commit is contained in:
parent
2dd72ff011
commit
eccf07876a
19
snake/map.py
19
snake/map.py
|
@ -2,6 +2,8 @@
|
|||
This module contains the Map class.
|
||||
"""
|
||||
|
||||
import numpy as np
|
||||
|
||||
def is_on_border(i, j, w ,h):
|
||||
return i == 0 or i == w - 1 or j == 0 or j == h - 1
|
||||
|
||||
|
@ -20,16 +22,20 @@ class Map:
|
|||
"""
|
||||
self.width = w
|
||||
self.height = h
|
||||
self._data = [[wall if is_on_border(i, j, w + 2, h + 2) else empty for i in range(h + 2)] for j in range(w + 2)]
|
||||
self._data = np.array([[wall if is_on_border(i, j, w + 2, h + 2) else empty for i in range(h + 2)] for j in range(w + 2)])
|
||||
|
||||
def clone(self):
|
||||
"""
|
||||
Creates a clone of the map.
|
||||
"""
|
||||
map = Map(self.width, self.height, 0, 0)
|
||||
map._data = [[ self._data[j][i] for i in range(self.height + 2)] for j in range(self.width + 2) ]
|
||||
map._data = np.copy(self._data)
|
||||
return map
|
||||
|
||||
def convert(self, converter):
|
||||
map = Map(self.width, self.height, 0, 0)
|
||||
map._data = np.fromiter((converter.convert(xi) for xi in self._data), self._data.dtype)
|
||||
|
||||
def __getitem__(self, index):
|
||||
(i, j) = index
|
||||
return self._data[i+1][j+1]
|
||||
|
@ -37,3 +43,12 @@ class Map:
|
|||
def __setitem__(self, position, other):
|
||||
(i, j) = position
|
||||
self._data[i+1][j+1] = other
|
||||
|
||||
class Converter:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def convert(self, x):
|
||||
pass
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue