def addCell(self, select_team, add_team): with self.lock: if self.testing: ret = set() for (row,col) in self.selected[select_team]: if self.cells[row][col].team != neutral_str: return "Can only add to neutral cells" self.cells[row][col] = Cell(add_team, 3, initDna()) ret.add((row,col)) ret = ret.union(set(self.adj(row,col))) return ret
def reset(self, include_tornado = True, testing = False): with self.lock: self.testing = testing self.turn = 0 self.land = [[baseLand() for col in range(self.width)] for row in range(self.height)] self.selected = dict() for team in self.teams: self.selected[team] = set() self.points = collections.Counter() self.points[self.teams[0]] = 0 self.points[self.teams[1]] = 0 for row in range(self.height): for col in range((self.width + 1) / 2): result = self.rand.random() if result < .75 and col < self.width * 2 / 5: # < 1000 10000 # .25 .265 .2927 # .35 .385 # .50 .469 # .55 .487 .4802 # .60 .518 .4972 # .65 .522 .5022 # .66 .4956 # .67 .509 .5052 # .68 .4987 # .70 .522 .5001 # .75 .488 .5182 # .76 .5012 # .77 .4969 # .80 .5126 # .85 .4758 self.cells[row][col] = Cell(self.teams[0], 3, initDna()) self.cells[row][self.width - col - 1] = Cell(self.teams[1], 3, initDna()) else: self.cells[row][col] = neutral() self.cells[row][self.width - col - 1] = neutral() if include_tornado: self.cells[self.width / 2][self.height / 2] = tornado() self.warning_cells.clear() self.lava_cells.clear() self.volcanoes.clear()