예제 #1
0
파일: map.py 프로젝트: gentimouton/tridef
 def __init__(self, mapfile, res):
     f = open(os.path.join("maps", mapfile))
     #other lines = map in itself
     lines = f.readlines() #might be optimized: for line in open("file.txt"):
     self.__BOARD = [] #contains game board
     for j in range(len(lines)): #for all lines in file
         tmprow = []
         line = lines[j].strip().split(',')
         for i in range(len(line)):
             cellvalue = line[i];
             if cellvalue == 'E':
                 self.__entrance_coords = i,j
                 tmprow.append(1) #entrance is walkable
             elif cellvalue == 'L':
                 self.__lair_coords = i,j
                 tmprow.append(1) #lair is walkable
             else:
                 tmprow.append(int(line[i]))
         self.__BOARD.append(tmprow)
     self.__BOARD = matrix_transpose(self.__BOARD)
     # TODO: instead of assert, catch error and print explanatory message 
     assert(self.__BOARD and self.__BOARD[0]) # map has no row or no column
     #compute cell width and height to fit the resolution
     self.__CELL_WIDTH = int(res[0] / self.get_width()) #800/4=200
     self.__CELL_HEIGHT = int(res[1] / self.get_height()) #600/3=200
     self.__CELLGRID = [[Cell((i, j),
                                self.__CELL_WIDTH,
                                self.__CELL_HEIGHT,
                                self._get_board()[i][j],
                                self.get_width() * self.get_height()) for j in range(self.get_height())] for i in range(self.get_width())] #length * width = so far a distance that it'll be replaced during path making
     self.path = self._makePath() #need __CELLGRID to be initialized to work 
     # init game objects 
     self.cellgrid(self.get_entrance_coords()).set_entrance()
     self.cellgrid(self.get_lair_coords()).set_lair()
     return
예제 #2
0
파일: 011.py 프로젝트: hoodakaushal/Euler
def max_consec_product(matrix, k):
    a = max_adj_prod(matrix, k)  # Left to right
    b = max_adj_prod(tools.matrix_transpose(matrix), k)  # Up down
    c = max_adj_prod(tools.matrix_diagonalise(matrix), k)  # Diagonals slope -1
    alpha = tools.matrix_diagonalise(list(map(reverse, matrix)))
    d = max_adj_prod(alpha, k)  # Diagonals slope 1
    return max(a, b, c, d)
예제 #3
0
 def __init__(self, mapfile, res):
     f = open(os.path.join("maps", mapfile))
     #other lines = map in itself
     lines = f.readlines(
     )  #might be optimized: for line in open("file.txt"):
     self.__BOARD = []  #contains game board
     for j in range(len(lines)):  #for all lines in file
         tmprow = []
         line = lines[j].strip().split(',')
         for i in range(len(line)):
             cellvalue = line[i]
             if cellvalue == 'E':
                 self.__entrance_coords = i, j
                 tmprow.append(1)  #entrance is walkable
             elif cellvalue == 'L':
                 self.__lair_coords = i, j
                 tmprow.append(1)  #lair is walkable
             else:
                 tmprow.append(int(line[i]))
         self.__BOARD.append(tmprow)
     self.__BOARD = matrix_transpose(self.__BOARD)
     # TODO: instead of assert, catch error and print explanatory message
     assert (self.__BOARD
             and self.__BOARD[0])  # map has no row or no column
     #compute cell width and height to fit the resolution
     self.__CELL_WIDTH = int(res[0] / self.get_width())  #800/4=200
     self.__CELL_HEIGHT = int(res[1] / self.get_height())  #600/3=200
     self.__CELLGRID = [
         [
             Cell((i, j), self.__CELL_WIDTH, self.__CELL_HEIGHT,
                  self._get_board()[i][j],
                  self.get_width() * self.get_height())
             for j in range(self.get_height())
         ] for i in range(self.get_width())
     ]  #length * width = so far a distance that it'll be replaced during path making
     self.path = self._makePath(
     )  #need __CELLGRID to be initialized to work
     # init game objects
     self.cellgrid(self.get_entrance_coords()).set_entrance()
     self.cellgrid(self.get_lair_coords()).set_lair()
     return