def post(self): name = self.get_argument("name", None) size = self.get_argument("size", None) mapfile = "default" if name is None or size is None: return jsonify(self, status=406, error = "name") try: int(size) except ValueError: return jsonify(self, status=406, error = "size") if size not in ['16', '32', '64']: return jsonify(self, status=404) # Make sure the name doesn't already exist if Grid.fromName(name).exists(): return jsonify(self, status=406, error = "Name taken") status, g = Grid.create(name, size, "default") if status == False: return jsonify(self, status=406, error=g) # Send to nogrids UpdateManager.sendNogrids("newGrid", gid = g['id'], size = size, name = g['name'], players = 1, ) return jsonify(self, status=200, gid = g['id'])
def get_confrontation_nodes(grid: model.Grid, country: int) -> set: """Получить все узлы, входящие в прифронтовую полосу, кроме узлов линии фронта""" border_nodes = grid.border_nodes return set({ x for x in grid.get_neighbors_of(border_nodes) if x.country == country or x.related_country == country })
def main(): try: key = sys.argv[1].split("-", 1)[1] except: key = "c" path = os.getcwd() + "/model/grid.txt" Game(Grid(path), App(key)).play()
def get(self): name = self.get_argument("name", None) gid = self.get_argument("gid", None) if name is None and gid is None: return jsonify(self, status=406) if gid is None: g = Grid.fromName(name) elif name is None: g = Grid(gid) if g.exists() is False: return jsonify(self, status=404) return jsonify(self, status=200, data = { "gid": g['id'], "size": g['size'] })
def get(self): name = self.get_argument("name", None) if name is None: return jsonify(self, status=406) grid = Grid.fromName(name) if grid.exists() is False: return jsonify(self, status=404) return jsonify(self, status=200, colors = grid.getUsedColors())
def getGrids(handler, **args): grids = [] for grid in Grid.all(): grids.append({ "gid": grid['id'], "name": grid['name'], "size": grid['size'], "players": len(grid.getUsers()) }) return {"status": 200, "grids": grids}
def joinGrid(handler, **args): try: #TODO: Sanity checks gid = args['gid'] except KeyError: return {"status": 406, "error": "no gid"} pid = None if "pid" in args: pid = args['pid'] g = Grid(gid) if g.exists() is False: return {"status":404, "error":"Grid not found."} # Add the user to the grid/UpdateManager pid = g.addUser(handler.user, pid) if pid is False: return { "status":406, "error": "Grid is full" } handler.user['pid'] = pid handler.user['grid'] = gid handler.user['active'] = True player = handler.user.getPlayer() # Looks like it's a new player, go ahead and init them if g.playerExists(pid) is False: player['cash'] = g['init_cash'] # Starting cash value player['inc'] = 0 player['lastInc'] = int(time()) player['tused'] = g['init_tused'] player['tlim'] = g['init_tlim'] updated = g.loadEvent("join_%s" % pid) # Add their new coords for coord in updated: UpdateManager.sendCoord(g, coord, handler.user) # Announce our color to all other clients UpdateManager.sendGrid(g, "addPlayer", handler.user) return { "status":200, "uid": handler.user['id'], "pid": pid, "cash": player['cash'], "inc": player['inc'], "tused": player['tused'], "tlim": player['tlim'], "colors": g.getColors(), "color": player['color'], "coords": g.dump() }
def create_objects(params, locIncome, PrintGrids): income = Income.Income(params, locIncome, False) params.addIncomeParameters(income) grids = Grid.Grid(params, income) if PrintGrids: print('Cash grid:') functions.printVector(grids.x_flat) print('Consumption grid:') functions.printVector(grids.c_flat) quit() return (grids, income)
def test_propagate_short(self): grid = Grid(8, 8) grid.add_source(Source(2, 1)) grid.propagate(9) self.assertEqual(grid[0], [999.0, 999.0, 999.0, 999.0]) self.assertEqual(grid[1], [1, 1, 1, 999.0]) self.assertEqual(grid[2], [1, 0, 1, 999.0]) self.assertEqual(grid[3], [1, 1, 1, 999.0])
def test_propagate(self): grid = Grid(8, 8) grid.add_source(Source(2, 1)) grid.propagate() print (grid) self.assertEqual(grid[0], [2, 2, 2, 2]) self.assertEqual(grid[1], [1, 1, 1, 2]) self.assertEqual(grid[2], [1, 0, 1, 2]) self.assertEqual(grid[3], [1, 1, 1, 2])
def main(width, height, cells): live_cells = [[ random.randint(0, width - 1), random.randint(0, height - 1) ] for _ in range(cells)] grid = Grid(width, height) grid.set_alive(live_cells) while not grid.stale: tmp = os.system('clear') grid.play() time.sleep(0.5)
from model import Grid from view import View from uav import Uav pygame.init() # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() # initialize the map (size, num_targets) size = 40 targets = 5 data = Grid(size, targets) # define drones num_drones = 10 drones = [Uav(1, 1, data)] for m in range(num_drones - 1): drones.append(Uav(m + 1, 1, data)) # init the view of the map view = View(600, data, drones) # max fps at which to run fps = 10 counter = 0 raw_input('Press <ENTER> to begin')
def build_fixture(name): """build game from fixture name""" return Game(Grid(fixture_name(name)), None)
from model import Grid from view import View from uav import Uav pygame.init() # Loop until the user clicks the close button. done = False # Used to manage how fast the screen updates clock = pygame.time.Clock() # initialize the map (size, num_targets) size = 40 targets = 5 data = Grid(size,targets) # define drones num_drones = 10 drones = [Uav(1, 1, data)] for m in range(num_drones-1): drones.append(Uav(m+1, 1, data)) # init the view of the map view = View(600, data, drones) # max fps at which to run fps = 10 counter = 0 raw_input('Press <ENTER> to begin')
"tused": player['tused'], "tlim": player['tlim'], "colors": g.getColors(), "color": player['color'], "coords": g.dump() } def place(handler, **args): try: coord = args['coord'] tile = int(args['tile']) props = TileProps[int(args['tile'])] except KeyError, ValueError: return { "status": 406 } g = Grid(handler.user['grid']) c = g.get(coord) player = handler.user.getPlayer() if c.exists() and c['type'] != "1" and tile not in [8, 10, 11]: return { "status":405, "coord": coord, "error": "coord exists" } try: placeable = TileAdd[tile](g, c, player) except KeyError: return { "status": 406, "coord": coord, "error": "invalid tile" } # If it's not placeable if placeable is False: return { "status": 412, "coord": coord, "error": "invalid placement" } # Make sure they have enough cash for it
def testFromName(self): self.assertEqual(Grid.fromName("test"), self.g)
def setUp(self): db.flushdb() status, self.g = Grid.create("test", 32, "default")
def __init__(self, v): # Pass the view into the grid to allow the model to update self.g = Grid.Grid(v) self.g.add_neighbours()
def test_grid_printing(self): grid = Grid(4, 4) self.assertEqual (grid[0], [999.0] * 2) self.assertEqual (grid[1], [999.0] * 2)
def test_grid_update(self): grid = Grid(4, 4) grid[1][1] = 10.0 self.assertEqual (grid[0], [999.0] * 2) self.assertEqual (grid[1], [999.0, 10.0])
# No need for this line below # ! C:\Users\USER\AppData\Local\Programs\Python\Python37-32\python.exe # Please follow Pep reccomendations, I # f using Pycharm, you should have the warnings and you can fix them just by clicking on code -> reformat code import webview from model import Grid if __name__ == "__main__": grid = Grid() w = webview.create_window("hello world", url="vue.html", js_api=grid) w.expose(grid.get_cell) webview.start()
def get_nodes_by_keys(keys: list, grid: model.Grid) -> list: """Получить ключи узлов из списка узлов""" return list(grid.node(key) for key in keys)
def build(self): game = PongGame() game.serve_ball() grid = Grid(*game.size) Clock.schedule_interval(game.update, 1.0 / 60.0) return game
def test_grid_creation(self): grid = Grid(100, 100) self.assertEqual(len(grid), 50, "Correct row size") self.assertEqual(len(grid[0]), 50, "Correct column size")