def dict_to_grid(grid_as_dict) -> Grid: grid = Grid(branches_number=8, radius=250, invisible_branches=320, inv_nodes_per_branch=71) grid.branches = [_dict_to_branch(br) for br in grid_as_dict['branches']] grid.recalculate_invisibles() return grid
def __init__(self): self.__stage = WindowStage.EDIT_OBSTACLES self.__width = CANVAS_WIDTH self.__height = CANVAS_HEIGHT self.__grid = Grid(GRID_WIDTH, GRID_HEIGHT) self.__root = tk.Tk() self.__canvas = tk.Canvas(self.__root, width=self.__width, height=self.__height, bg='white') self.__canvas.pack(padx=ELEMENTS_PADDING, pady=ELEMENTS_PADDING) self.__canvas.bind('<Button-1>', self.__on_canvas_click) self.__algorithm = tk.StringVar() self.__algorithm.set('DFS') tk.Button(self.__root, text='obstacle', bg='black', fg='white', command=lambda _=None: self.__set_stage( WindowStage.EDIT_OBSTACLES)).pack( padx=ELEMENTS_PADDING, pady=(ELEMENTS_PADDING // 2), side=tk.LEFT) tk.Button(self.__root, text='start', bg='cyan', command=lambda _=None: self.__set_stage( WindowStage.EDIT_START)).pack(padx=ELEMENTS_PADDING, pady=(ELEMENTS_PADDING // 2), side=tk.LEFT) tk.Button(self.__root, text='destination', bg='blue', fg='white', command=lambda _=None: self.__set_stage( WindowStage.EDIT_DESTINATION)).pack( padx=ELEMENTS_PADDING, pady=(ELEMENTS_PADDING // 2), side=tk.LEFT) tk.Button(self.__root, text='solve', bg='green', fg='white', command=lambda _=None: self.__solve()).pack( padx=ELEMENTS_PADDING, pady=(ELEMENTS_PADDING // 2), side=tk.LEFT) tk.OptionMenu(self.__root, self.__algorithm, 'DFS', 'BFS', 'A*').pack(padx=ELEMENTS_PADDING, pady=(ELEMENTS_PADDING // 2), side=tk.LEFT) self.__solvers = { 'DFS': dfs.DfsSearch, 'BFS': bfs.BfsSearch, 'A*': astar.AStar }
def __init__(self): ShowBase.__init__(self) self.editormode = True base.win.setClearColor((0, 0, 0, 1)) base.win.setClearColorActive(True) lang = "ita" ''' #ortho camera lens lens = OrthographicLens() lens.setFilmSize(12, 9) #TODO: quattro terzi, fixare, spostare tutto nella classe telecamera e adattare in base allo schermo utente base.cam.node().setLens(lens) base.cam.setY(-5) base.cam.setP(-355) ''' #enabling shader system (and ppl) render.setShaderAuto() #base.oobe() #defining global variables # TAKE CARE: these must be objects created form classes which # structure has been built with globalness in mind!! # # for completeness: add minus 'p' before class name for naming variables __builtin__.main = self __builtin__.pGrid = Grid() __builtin__.extract = ExtractTitle() __builtin__.baloons = BaloonManager() #__builtin__.configManager = ConfigManager() __builtin__.audioManager = AudioManager() __builtin__.editorCamera = EditorCamera() __builtin__.customCamera = __builtin__.editorCamera #careful, refactor? here for compatibility between game engine and editor engine __builtin__.script = Script() __builtin__.persistence = Persistence() self.prepareEditor() self.accept("editor_loadmap", self.loadMap)
def __init__(self): ShowBase.__init__(self) self.editormode = True base.win.setClearColor((0, 0, 0, 1)) base.win.setClearColorActive(True) lang = "ita" ''' #ortho camera lens lens = OrthographicLens() lens.setFilmSize(12, 9) #TODO: quattro terzi, fixare, spostare tutto nella classe telecamera e adattare in base allo schermo utente base.cam.node().setLens(lens) base.cam.setY(-5) base.cam.setP(-355) ''' __builtins__.resourceManager = ResourceManager() __builtins__.configManager = ConfigManager(resourceManager) __builtins__.pGrid = Grid() __builtins__.extract = ExtractTitle() __builtins__.baloons = BaloonManager() #__builtins__.configManager = ConfigManager() __builtins__.audioManager = AudioManager() __builtins__.editorCamera = EditorCamera() __builtins__.customCamera = editorCamera #TODO: why?! #careful, refactor? here for compatibility between game engine and editor engine __builtins__.script = Script() __builtins__.persistence = Persistence() __builtins__.main = self #enabling shader system (and ppl) render.setShaderAuto() #base.oobe() self.prepareEditor() self.accept("editor_loadmap", self.loadMap)
def __init__(self): """Read config file and initialise default parameters.""" # Open grid config file file = open("./gridConfig.json") # Read grid config from file gridConfig = json.load(file) # Close file file.close() # Initialise base path to logging directory self.baseLogDir = gridConfig["baseLogDir"] # Initialise path to log current events self.currentLogDir = None # Initilaise number of days self.noOfDays = gridConfig["noOfDays"] # Initialise grid size self.gridSize = gridConfig["gridSize"] # Initialise grid with grid size self.grid = Grid(self.gridSize) # Initialise a lock for grid self.gridLock = threading.Semaphore() # Initialise food limit self.foodLimit = gridConfig["foodLimit"] # Initialise array to hold players self.players = [] # Initialise array to hold threads self.threads = [] # Iterate till player limit is reached for i in range(gridConfig["noOfPlayers"]): # Call function to create players self.initialisePlayer()
def __init__(self, parent=None): """ :param parent: :return: """ super(GroundBody, self).__init__(name="ground", parent=parent) # type of body self.body_type = "ground" # body id self.body_id = -1 # name self._name = "Ground" # visualization properties self.color = np.array([0.8, 0.8, 0.8]) # grid object self.grid = Grid(parent=self)
# Copyright (c) 2019 Aliaksandr Tsukanau. # Licensed under GNU General Public Licence, version 3. # You may not use this file except in compliance with GNU General Public License, version 3. # See the GNU General Public License, version 3 for more details. https://www.gnu.org/licenses/gpl-3.0.en.html # # from db.grid_driver import GridMongoClient from grid.grid import Grid driver = GridMongoClient() grid = Grid(branches_number=8, radius=250, invisible_branches=320, inv_nodes_per_branch=71) driver.save_grid(grid, 'testing_my_grid') saved_grid = driver.get_grid_obj('testing_my_grid')
10, #R needed to reach half of maximum consumption rate (res) 0.4, #population generated by max consumption (pop) 0.02, #pop natural death rate (year^-1) 10, #foundingp pop 100, ) # carrying capacity (pop) R = Res( 0.2, #resource natural growth 60) #resource carrying capacity sim = Grid( Nstart, start, N, R, Europe, 0.01, #alpha -- production taxation (%.year^-1) 10, #range dt) fig, ax = plt.subplots() plt.axis('off') im = plt.imshow(sim.get_img()) ax.set_title(f'Year: 0') def animate(i): for _ in range(scale): sim.update()
def __init__(self): self.wanted_x = -1 self.wanted_y = -1 self.turns = -1 self.grid = Grid()
from grid import ipfsapi import base64 import random import keras import json from keras.models import Sequential from keras.layers.core import Dense, Dropout, Activation from keras.optimizers import SGD import numpy as np from grid.grid import Grid grid = Grid() print("grid id: {}".format(grid.id)) grid.work()
def __init__(self): ShowBase.__init__(self) self.editormode = False base.win.setClearColor((0, 0, 0, 1)) base.win.setClearColorActive(True) lang = "ita" ''' #ortho camera lens lens = OrthographicLens() lens.setFilmSize(12, 9) #TODO: quattro terzi, fixare, spostare tutto nella classe telecamera e adattare in base allo schermo utente base.cam.node().setLens(lens) base.cam.setY(-5) base.cam.setP(-355) ''' #enabling shader system (and ppl) render.setShaderAuto() #base.oobe() #filters -- experimental filters = CommonFilters(base.win, base.cam) #defining global variables # TAKE CARE: these must be objects created form classes which # structure has been built with globalness in mind!! # # for completeness: add minus 'p' before class name for naming variables __builtins__.main = self __builtins__.pGrid = Grid() __builtins__.extract = ExtractTitle() __builtins__.baloons = BaloonManager() #__builtins__.configManager = ConfigManager() __builtins__.audioManager = AudioManager() __builtins__.fadingtext = FadingTextManager() __builtins__.customCamera = CustomCamera() __builtins__.script = Script() __builtins__.persistence = Persistence() __builtins__.fademanager = FadeOut() __builtins__.flow = Flow() __builtins__.myfilters = filters # =========================================== #load the config class #configmanager.loadConfig() #lang = configmanager.getData("LANGUAGE").lower() # =========================================== __builtins__.mainMenu = MainMenu(lang) lang = configManager.getData("LANGUAGE").lower() #extract.extractTxt("ita") extract.extractTxt(lang) #DEBUG for the getResource #print(resourceManager.getResource("misc/grass.png")) configManager.saveConfig("LANGUAGE", "ITA") lang = configManager.getData("LANGUAGE").lower() extract.extractTxt(lang) """ r = ResourceManager() print(r.getResource('misc/grass') # deve dire path assoluto = res/misc/grass.png) """ #self.entrypoint = ['camera.map', '3,3'] #self.entrypoint = ['finedemo.map', '1,1'] #self.entrypoint = ['parcogiochi.map', '9,12'] #self.entrypoint = ['incidente.map', '20,11'] #self.entrypoint = ['macchinadasola.map', '2,2'] #self.entrypoint = ['black.map', '5,5'] #cinematica self.entrypoint = ['tetto.map', '4,2'] #inizio vero #self.entrypoint = ['classe.map', '5,2', 'up'] mainMenu.show() #UNCOMMENT TO ENABLE INTRO i = Intro() i.start()
actor = Actor() os.popen("VampiresVSWerewolvesGameServer.exe") name = 'paul' conn = Connector("127.0.0.1", 5555) # envoit sequence NME conn.send("NME".encode() + struct.pack("1B", len(name)) + name.encode()) # recoit commande SET Set = conn.receive() # initialise la carte grid = Grid(Set[1][0], Set[1][1]) # recoit HME --inutile mais il faut quand même le recevoir conn.receive() # recoit HME --inutile mais il faut quand même le recevoir conn.receive() # Map = conn.receive() grid.update_all_groups(Map[1]) # tant que la partie est active while conn.connected: # ecoute le serveur order = conn.receive()
def execute(name, algorithm, ip, port): print(ip, port) """ :param name: name of the ai :param algorithm: 1 for greedy, 2 for alpha-beta :return: """ actor = Actor(algorithm) conn = Connector(ip, port) # envoie sequence NME conn.send("NME".encode()+struct.pack("1B",len(name))+name.encode()) # recoit commande SET Set = conn.receive() # initialise la carte grid = Grid(Set[1][0],Set[1][1]) # recoit HUM —inutile mais il faut quand même le recevoir conn.receive() # recoit HME — utile pour identifier son espèce hme = conn.receive() # Map = conn.receive() grid.initiate_all_groups(Map[1],hme[1]) turn = 0 # tant que la partie est active while conn.connected: # écoute le serveur logging.info('starting turn {}'.format(turn)) order = conn.receive() start_time = time.time() if order[0] == "UPD": #update la grille grid.update_map(order[1]) elif order[0] == "BYE": # TODO clean break logging.error("server unexpectedly close connexion") break elif order[0] == "END": logging.info("finishing game") # TODO clean break break # prend la decision actor.action(grid, turn) # envoie file d'actions au serveur conn.send(actor.send_moves()) logging.info('finishing turn {} \n elapsed time : {}s'.format(turn, time.time()-start_time)) # vide la file d'action pour prochain tour actor.clean_moves() # attend une seconde pour visualiser sur .exe #time.sleep(0.5) turn += 1
def _get_palette(): default_grid = Grid(branches_number=8, radius=250, invisible_branches=320, inv_nodes_per_branch=71) return Palette(default_grid)
import pytest from grid.grid import Grid new_grid = Grid() test_board = [[7, 8, 0, 4, 0, 0, 1, 2, 0], [6, 0, 0, 0, 7, 5, 0, 0, 9], [0, 0, 0, 6, 0, 1, 0, 7, 8], [0, 0, 7, 0, 4, 0, 2, 6, 0], [0, 0, 1, 0, 5, 0, 9, 3, 0], [9, 0, 4, 0, 6, 0, 0, 0, 5], [0, 7, 0, 3, 0, 0, 0, 1, 2], [1, 2, 0, 0, 0, 7, 4, 0, 0], [0, 4, 9, 2, 0, 6, 0, 0, 7]] def test_set_board(): new_grid.set_board(new_grid.empty_board) assert new_grid.board == new_grid.empty_board def test_print(capsys): new_grid.set_board(test_board) new_grid.print() captured = capsys.readouterr() assert captured.out == test_board # def test_new_func(): # assert 4 == 5