def highlightGrid(self, event): self.mainWindow.hide() combat_grid = Grid(env.COMBAT_R, env.VCELLS, env.HCELLS) combat_grid.parse() self.overlay = GridOverlay(combat_grid) self.overlay.highlightEnded.connect(self.mainWindow.show) self.overlay.highlight(2)
def __init__(self, spell, workdir, name="Fighter"): super(Fighter, self).__init__(workdir, name) self.spell = spell self.fightEndObs = CombatEndObs(self) self.fightStartObs = CombatStartObs(self) self.grid = Grid(dofus.COMBAT_R, dofus.VCELLS, dofus.HCELLS) self.mobs_killed = 0 self.nbr_fights = 0
def get_grid(grid: str, width: int, height: int) -> Grid: match grid: case ["colored", _]: typer.echo("Using colored grid") return ColoredGrid(height, width) case ["distance", _]: return DistanceGrid(height, width) case _: return Grid(width, height)
def test_generate_complete(self): grid = Grid(3) grid.init_generate_grid() # self.assertEqual(len(grid.grid), 36) grid.simple_show() grid.show_detail() grid.check_eliminate() for state in grid.direct_states: print(state, grid.direct_states[state])
def test_best_plan(self): grid = Grid() grid.init_generate_grid() grid.show_detail() result = grid.swap_by_strategy(StrategyType.HIGH_ORDER_FIRST) if len(result) == 0: log.error('no swap') for i in result: log.info('swap %s' % i)
def test_check(self): grid = Grid(1) grid.init_generate_grid() grid.show_detail() print('数量统计', grid.type_count) grid.check_eliminate() for state in grid.direct_states: print(state, grid.direct_states[state])
def test_generate(self): grid = Grid() grid.init_generate_grid() self.assertEqual(len(grid.grid), 16) for cell in grid.grid: log.debug(str(cell)) log.debug(grid.type_count) grid.show_detail()
def test_probably(self): grid = Grid(2) grid.init_generate_grid() grid.simple_show() grid.check_eliminate() for state in grid.probably_eliminate: state_list = grid.probably_eliminate[state] for cell in state_list: print(cell.direct_type, cell.ref_id, cell.get_pre(grid), cell.indexes, cell.get_next(grid))
def test_get_alternative_monster(self): grid = Grid() grid.init_generate_grid() grid.simple_show() # grid.show() result = grid.get_complex_swap_choice() for vo in result: print(vo) if len(result) == 0: print('There is no way to eliminate it.')
def test_swap(self): grid = Grid() grid.init_generate_grid() grid.simple_show() result = grid.swap_by_strategy(StrategyType.HIGH_ORDER_FIRST) if len(result) == 0: log.warning('no swap') return for i in result: log.info('swap %s' % i) grid.swap_and_eliminate(result) grid.show()
def get_path(matrix_id, s, e): grid = Grid(matrix=matrixes[matrix_id]) s = [x*2-1 for x in s] e = [x*2-1 for x in e] start = grid.node(*s) end = grid.node(*e) finder = AStarFinder(diagonal_movement=2) path, runs = finder.find_path(start, end, grid) #print('operations:', runs, 'path length:', len(path)) rep = grid.grid_str(path=path, start=start, end=end) path2 = [j for i, j in enumerate(path+[e]) if i % 2 == 0] #print(path2) path3 = [] #print(s) for i, node in enumerate(path2): path2[i] = [int((path2[i][0]+1)/2), int((path2[i][1]+1)/2)] if i == 0: continue #print(path2[i-1]) #print(path2[i]) path3.append([path2[i][0] - path2[i-1][0], path2[i][1] - path2[i-1][1]]) #print(i) #print(path3) #print(path2) #print(path3) for i, node in enumerate(path3): if node == [1, 0]: path3[i] = "R" elif node == [-1, 0]: path3[i] = "L" elif node == [0, 1]: path3[i] = "D" elif node == [0, -1]: path3[i] = "U" else: path3[i] = "X" #print(path3) #print(" ".join(path3)) return (" ".join(path3), rep)
def test_creating_grid_assigns_cell_neighbours(): grid = Grid(2, 2) cell = grid[1][1] north_cell = cell.north assert north_cell assert north_cell.row == 0 assert north_cell.col == 1 east_cell = cell.east assert not east_cell south_cell = cell.south assert not south_cell west_cell = cell.west assert west_cell assert west_cell.row == 1 assert west_cell.col == 0
def test_show(self): grid = Grid() grid.init_generate_grid() grid.show_detail() print('数量统计', grid.type_count)
from generators.binary_tree import BinaryTree from core.grid import Grid if __name__ == "__main__": grid = Grid(10, 10) BinaryTree.on(grid) print(grid) image = grid.to_png() image.save("results/binary_tree.png")
def test_creating_grid_sets_up_a_2d_grid(): grid = Grid(2, 2) cell = grid[1][1] assert cell is not None
from core.grid import Grid if __name__ == "__main__": grid = Grid(2, 2) image = grid.to_png() image.save("results/png_test.png")
def test_iterating_over_grid_goes_column_first(): grid = Grid(2, 2) cells = [cell for cell in grid] assert len(cells) == 4 assert cells[1].row == 0 and cells[1].col == 1
def test_main_loop(self): grid = Grid() grid.main_loop(4, StrategyType.HIGH_ORDER_FIRST)
from core.grid import Grid from generators.sidewinder import Sidewinder if __name__ == "__main__": grid = Grid(100, 100) Sidewinder.on(grid) image = grid.to_png() image.save("results/sidewinder.png")