def boardFromArray(arr): # creates board from numpy 1/0 array y, x = arr.shape board = create_blank(x,y) # includes 1-cell border set to 0 for j in range(y): for i in range(x): board[j][i] = arr[j][i] == 1 return board
def __init__(self, board, random=False): self.board = board if random: self.candidate = tools.create_random(board["x_size"], board["y_size"]) else: self.candidate = tools.create_blank(board["x_size"], board["y_size"]) self.initialize_neediness() self.initialize_weighting() self.initialize_impact()
def initUI(self): if not self.pattern: self.pattern = tools.create_blank(7, 7) self.grid = QtGui.QGridLayout() self.grid.setSpacing(1) for i in range(self.pattern["x_size"]): for j in range(self.pattern["y_size"]): cell = Cell(i, j, self.pattern) self.grid.addWidget(cell, j, i) self.setLayout(self.grid)
def __init__(self, board): '''Create the basic objects needed for the search. self.board is the target board, self.candidate is the current candidate to be tested and modified, self.needy is a matrix of how bad a shape each cell is in, self.total_needy is a sum of the values of self.needy, and self.impact is a matrix of how beneficial flipping each cell would be. self.minima is used to store known minima for the Pogo algorithm. It is initialized here mostly so I don't have to check for it every time I run use_pogo(). ''' self.board = board self.candidate = tools.create_random(board["x_size"], board["y_size"]) self.candidate = tools.create_blank(board["x_size"], board["y_size"]) self.needy, self.total_needy = self.initialize_neediness() self.impact = self.initialize_impact() self.minima = {}
def cleared(self): new = tools.create_blank(self.board.pattern["x_size"], self.board.pattern["y_size"]) mainw.central = centralArea(new) mainw.setCentralWidget(mainw.central) mainw.update()