def __init__(self, app): self.app = app self.screen = app.screen self.ship = Ship(app) self.Puntuacion = Puntuacion(app) self.Fleet = Fleet(self) self.Muerto = pygame.mixer.Sound("Assets/Audio/Muerto.wav") self.Fondo = pygame.image.load("Assets/Image/Space.png") super().__init__('PlayScene')
def __init__(self): self.fleet = Fleet() self.herd = Herd() self.dino_list = Herd().dinosaur_list self.robo_list = Fleet().robots_list self.weapon_list = Fleet().weapon_list self.dino_attacks = Herd().dino_attack_type_list self.pick_dino = self.dino_list self.pick_robo = self.robo_list
def getFleets(self): techEspionageLevel = self.getTechLevel(106) fleets = {} overviewRequest = Request(self.ia.overviewPage, {}) self.ia.execRequest(overviewRequest) soup = BeautifulSoup(overviewRequest.response.content, "html.parser") #parse all available buildings fleetsTd = soup.find_all("td", class_="fleets") for fleetTd in fleetsTd[:: -1]: #invert the list so the smallest eta overrides the latest etaStr = fleetTd.attrs["data-fleet-end-time"] eta = float(etaStr) id = fleetTd.attrs["id"].split(etaStr)[ 1] #The etaStr is appended at the end of the id secondTd = fleetTd.parent.findAll("td")[1] fleetsSpans = secondTd.findAll( "span", recursive=False) #can be more than 1 if grouped attack typeList = fleetsSpans[-1].attrs[ "class"] #the last one has the type isGoing = (typeList[0] == "flight") type = typeList[1] aList = fleetsSpans[-1].findAll("a", class_=type) ships = {} for fleetSpan in fleetsSpans: shipsA = fleetSpan.find("a", class_="tooltip") if shipsA is not None and techEspionageLevel >= 8: shipsSoup = BeautifulSoup( shipsA.attrs["data-tooltip-content"], "html.parser") for tr in shipsSoup.findAll("tr"): tds = tr.findAll("td") shipType = Codes.strToId[tds[0].text[:-1]] shipAmount = int(tds[1].text.replace(".", "")) ships[shipType] = ships.get(shipType, 0) + shipAmount aList = [a for a in aList if not "tooltip" in a.attrs["class"]] originA = aList[0] targetA = aList[1] origin = [int(x) for x in originA.text[1:-1].split(":")] if "Lune" in originA.previous: origin.append(3) elif "CDR" in originA.previous: origin.append(2) else: origin.append(1) target = [int(x) for x in targetA.text[1:-1].split(":")] if "Lune" in targetA.previous: target.append(3) elif "CDR" in targetA.previous: target.append(2) else: target.append(1) fleet = Fleet(self, id, ships, origin, target, eta, type, isGoing) ancientFleet = self.fleets.get(fleet.id) if ancientFleet is not None: fleet.firstSpotted = ancientFleet.firstSpotted fleets[fleet.id] = fleet self.fleets = fleets
def __init__(self, board_size: type(Coordinate), fleet_seed: type(int), player_name: type(str) = "Undefined"): from Fleet import Fleet Player.Player_Count += 1 fleet_class = Fleet() if not player_name == "Undefined": self.__player_name = player_name else: self.__player_name = player_name + " " + format(self.Player_Count) self.__Fleet = fleet_class.create_fleet(board_size, fleet_seed)
class TestClient(): p1 = Gamefield(Constants.width, Constants.height) p2 = Gamefield(Constants.width, Constants.height) player1 = Fleet() player2 = Fleet() try: player1.addToFleet(0, 5, Coordinate( -1, 0, ), "v") except PastBound: print("caught past bound exception") player1.addToFleet(0, 4, Coordinate(1, 1), "v") #self.assertRaises(DuplicateIDException, player1.addToFleet, (0, 4, 2, 2, "h")) try: player1.addToFleet(0, 4, Coordinate(2, 2), "h") except DuplicateIDException: print("caught Duplicate id Exception") #player1.addToFleet(0, 5, 1, 1, "v") try: player1.addToFleet(1, 2, Coordinate(1, 1), "v") except OverlapException: print("caught vertical overlap") try: player1.addToFleet(2, 3, Coordinate(1, 1), "h") except OverlapException: print("caught horiz overlap") player1.addToFleet(1, 2, Coordinate(5, 5), "h") player1.addToFleet(2, 3, Coordinate(4, 4), "v") player1.addToFleet(3, 3, Coordinate(2, 1), "h") player1.addToFleet(4, 5, Coordinate(6, 0), "v") p1.addFleet(player1) p2.addFleet(player2) print(str(p1.printFleet())) print str(p1.hitOrMiss(Coordinate(5, 5)))
def mdp_only_feasible_actions(): evs = [ EV(0, 3, 3, 1, grid_pos=1, deadline=23), EV(0, 4, 4, 1, grid_pos=2, deadline=23) ] fleet = Fleet(evs) grid = Grid.load_grid_from_file('grids/grid_1.txt') mdp = MDP(fleet=fleet, grid=grid, horizon=6) return mdp
def uncoordinated_mdp_with_unfeasible_actions(): evs = [ EV(0, 3, 3, 1, grid_pos=1, deadline=23), EV(0, 4, 4, 1, grid_pos=2, deadline=23) ] fleet = Fleet(evs) grid = Grid.load_grid_from_file('grids/grid_1.txt') mdp = UncoordinatedMDP(fleet=fleet, grid=grid, horizon=6) return mdp
def __init__(self, coord): # Create a map using the Map() function and the coordinates for Charlottesville #self.map = folium.Map(location=[38.055148, -78.569812], zoom_start=12) if LOAD_DRIVER: self.driver = webdriver.Chrome() self.dirpath = os.path.dirname(os.path.abspath(__file__)) # draw initial map self.center = coord #self.centers.append([coord[0],coord[1]]) my_map = folium.Map(location=[coord[0], coord[1]], zoom_start=ZOOM_FACTOR) self.last_pt = coord my_map.save('index.html') if LOAD_DRIVER: self.driver.get("file:///" + self.dirpath + "/index.html") icon_image = 'bus.png' self.icon = CustomIcon('bus.png', icon_size=(50, 50), popup_anchor=(0, -10)) self.fleet = Fleet()
from math import ceil def save_obj(obj, name): with open('obj/' + name + '.pkl', 'wb') as f: pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL) from Airports import Airports from Fleet import Fleet from Demand import Demand from Stage import Stage Airports = Airports() Demand = Demand() Fleet = Fleet() airportsList = Airports.airportsList STAGE_RESOLUTION = 6 # 6 minutes TOTAL_HOURS = 120 numberOfStages = int(TOTAL_HOURS * 60 / STAGE_RESOLUTION + 1) for type, aircraft in Fleet.aircraftList.items(): print("Aircraft type: ", type) stagesList = [None] * numberOfStages # create last stage and add HUB node airportHUB = airportsList[Airports.HUB] lastStage = Stage(TOTAL_HOURS, numberOfStages - 1) lastStage.addNode(airportHUB)
for i in range(len(pokemon)): if (pokemon[i].isEffectiveAgainst(wildPokemon)): print(f"Ash should Choose {pokemon[i].get()}") ###### Fleet of Things from Fleet import Fleet from Thing import Thing # Create a fleet of things to have this output: # 1. [ ] Get milk c = Thing("Get milk") milk = c.__str__() fleet = Fleet() fleet.add(milk) # 2. [ ] Remove the obstacles c = Thing("Remove the obstacles") remove = c.__str__() fleet.add(remove) # 3. [x] Stand up c = Thing("Stand up") true_complete = c.complete() stand = c.__str__() fleet.add(stand) # 4. [x] Eat lunch c = Thing("Eat Lunch")
def __init__(self, teamName="ATeam"): self.mygrid = MyGrid() self.enemygrid = EnemyGrid() self.fleet = Fleet() self.teamName = teamName
# nekem megoldotta az import problémát az, # hogy a .vscode/settings.json -ön belül # "python.languageServer": "Jedi" -re változtattam a # "python.languageServer": "Microsoft" helyett from Fleet import Fleet from Thing import Thing fleet = Fleet() get_milk = Thing("Get milk") remove_obstacles = Thing("Remove the obstacles") stand_up = Thing("Stand up") stand_up.complete() eat_lunch = Thing("Eat lunch") eat_lunch.complete() fleet.add(get_milk) fleet.add(remove_obstacles) fleet.add(stand_up) fleet.add(eat_lunch) # Töltsd fel a fleet példányt olyan módon, hogy a következő legyen a kimenet: # 1. [ ] Get milk # 2. [ ] Remove the obstacles # 3. [x] Stand up # 4. [x] Eat lunch print(fleet)
"""UI Module for the Fleet Maneuver Game""" from tkinter import * from tkinter import ttk # from Coordinate import Coordinate from Playfield import Playfield from Coordinate import Coordinate from Fleet import Fleet button_collection_set = {} board_size = Coordinate(9,9) TestPlayfield = Playfield(board_size) p1_fleet = Fleet().create_fleet(board_size, 11) print("a") def button_frame(master, height_rows: int = 10, width_columns: int = 10, frame_text: str = "Frame", frame_background_color: str = "Grey"): """ Creates a Frame filled with Buttons @param master: Widget in that this Widget gets put @param height_rows: Buttons per Row @param width_columns: Buttons per Column @param frame_text: Text of the Frame @param frame_background_color: Background color of the Frame @return: Frame filled with Buttons """ btn_frame = LabelFrame(master, text=frame_text, bg=frame_background_color, width=width_columns*50, height=height_rows*50) index = 0
class Map: ''' init Map: - input - (lat,lon) coord specifying where to center map - purpose - open serial connection at COM## ''' def __init__(self, coord): # Create a map using the Map() function and the coordinates for Charlottesville #self.map = folium.Map(location=[38.055148, -78.569812], zoom_start=12) if LOAD_DRIVER: self.driver = webdriver.Chrome() self.dirpath = os.path.dirname(os.path.abspath(__file__)) # draw initial map self.center = coord #self.centers.append([coord[0],coord[1]]) my_map = folium.Map(location=[coord[0], coord[1]], zoom_start=ZOOM_FACTOR) self.last_pt = coord my_map.save('index.html') if LOAD_DRIVER: self.driver.get("file:///" + self.dirpath + "/index.html") icon_image = 'bus.png' self.icon = CustomIcon('bus.png', icon_size=(50, 50), popup_anchor=(0, -10)) self.fleet = Fleet() ''' function add_point: - input - Payload received from Uart - purpose - add point to map if it is within BUFFER of previous coordinate - create popup from Payload - draw route of each entity and add bus icon marker and popup at coordinate in payload - save map to index.html, 'press F5' to reload index.html in Chrome (if option selected at top) - return - nothing ''' def add_point(self, payload): if ((abs(payload.lat - self.last_pt[0]) < BUFFER) and (abs(payload.lon - self.last_pt[1]) < BUFFER)): point = (payload.lat, payload.lon) self.last_pt = point callout = payload.getCallout() self.fleet.processPayload(payload) #redraw map my_map = folium.Map(location=[self.center[0], self.center[1]], zoom_start=ZOOM_FACTOR) #add markers for entity in self.fleet.getEntities(): # add all markers but the last one for i in range(len(entity.points)): pt = entity.points[i] ts = entity.timestamps[i] if (i >= len(entity.points) - 1): marker = folium.Marker( location=[pt[0], pt[1]], icon=CustomIcon('bus.png', icon_size=(50, 50), popup_anchor=(0, -10)), popup=folium.Popup( ts, max_width=80, min_width=80, min_height=200, max_height=200)) #.add_to(my_map) my_map.add_child(marker) #add lines folium.PolyLine(entity.points).add_to(my_map) # display map my_map.save('index.html') if RELOAD: pyautogui.press('f5') # press the F1 key
from Fleet import Fleet from Thing import Thing fleet = Fleet() # Create a fleet of things to have this output: # 1. [ ] Get milk # 2. [ ] Remove the obstacles # 3. [x] Stand up # 4. [x] Eat lunch fleet.add(Thing("Get milk")) fleet.add(Thing("Remove the obstacles")) thing1 = Thing("Stand up") thing1.complete() thing2 = Thing("Eat lunch") thing2.complete() fleet.add(thing1) fleet.add(thing2) print(fleet)
def initialize_identical_ev_fleet(init_batt_level, batt_max, charge_rate, grid_pos_list, deadline): fleet = Fleet() for ev_pos in grid_pos_list: fleet.add_vehicle(EV(init_batt_level, batt_max, batt_max, charge_rate, ev_pos, deadline)) return fleet
def __init__(self): self.airports = Airports() self.fleet = Fleet()
from Fleet import Fleet from Demand import Demand from Financials import Financials from Stage import Stage import pickle import operator from Node_profit import Node_profit def load_obj(name ): with open('obj/' + name + '.pkl', 'rb') as f: return pickle.load(f) Airports = Airports() Demand = Demand() Fleet = Fleet() Financials = Financials() airportsList = Airports.airportsList BINS_0AM_4AM = [0,6,12,18,24] BINS_4AM_8AM = [1,7,13,19,25] BINS_8AM_12PM = [2,8,14,20,26] BINS_12PM_4PM = [3,9,15,21,27] BINS_4PM_8PM = [4,10,16,22,28] BINS_8PM_12AM = [5,11,17,23,29] STAGE_RESOLUTION = 6 # 6 minutes DEMAND_CAPTURE_PREVIOUS = 0.20 # 20% of previous two bins can capture TOTAL_HOURS = 120
"""Fleet_Maneuver_Game Module""" import Coordinate from Fleet import Fleet from Player import Player from Playfield import Playfield import View_Master_UI board_size = Coordinate.Coordinate board_size.x = 10 board_size.y = 10 fleet_class = Fleet() TestFleet_Test = fleet_class.create_fleet(board_size, 4468415) print("Test") TestShip = TestFleet_Test[1] TestShip_Type = TestShip.get_ship_type() print(TestShip_Type) Player_1 = Player(board_size, 1) Player_2 = Player(board_size, 2) TestPlayfield = Playfield(board_size) TestValue = TestPlayfield.get_position_value(board_size) print("Test 1:" + TestValue) status = "ship" board_size.x, board_size.y = 4, 5 TestPlayfield.set_position_value(board_size, status)
class Play_Scene(Scene): def __init__(self, app): self.app = app self.screen = app.screen self.ship = Ship(app) self.Puntuacion = Puntuacion(app) self.Fleet = Fleet(self) self.Muerto = pygame.mixer.Sound("Assets/Audio/Muerto.wav") self.Fondo = pygame.image.load("Assets/Image/Space.png") super().__init__('PlayScene') def start(self): print('Se inicia: ', self.name) if not self.Fleet.ENEMS: self.Fleet.create_fleet() def process_events(self, event): if event.type == pygame.KEYDOWN: if event.key == pygame.K_x: pass elif event.key == pygame.K_a: self.ship.move_left = True elif event.key == pygame.K_d: self.ship.move_right = True elif event.key == pygame.K_SPACE: self.ship.DispararESP(self.Puntuacion.Puntos) self.Puntuacion.Resta() if event.type == pygame.KEYUP: if event.key == pygame.K_a: self.ship.move_left = False elif event.key == pygame.K_d: self.ship.move_right = False if event.type == pygame.MOUSEBUTTONUP: self.ship.Disparar() def update(self): self.ship.update() self.Puntuacion.update() self.Fleet.update() self.collisions() def collisions(self): for Bullet in self.ship.Weapon.Balas: for ENEM in self.Fleet.ENEMS: if Bullet.active == True: if(Bullet.rect.x < ENEM.x + ENEM.rect.width and Bullet.rect.x + Bullet.rect.width > ENEM.rect.x and Bullet.rect.y < ENEM.rect.y + ENEM.rect.height and Bullet.rect.y + Bullet.rect.height> ENEM.rect.y): pygame.mixer.Sound.play(self.Muerto) Bullet.active = False self.Fleet.ENEMS.remove(ENEM) self.Puntuacion.Puntos += 1 for BalaESP in self.ship.Weapon.Balas2: for ENEM in self.Fleet.ENEMS: if BalaESP.active == True: if(BalaESP.rect.x < ENEM.x + ENEM.rect.width and BalaESP.rect.x + BalaESP.rect.width > ENEM.rect.x and BalaESP.rect.y < ENEM.rect.y + ENEM.rect.height and BalaESP.rect.y + BalaESP.rect.height> ENEM.rect.y): pygame.mixer.Sound.play(self.Muerto) self.Fleet.ENEMS.remove(ENEM) self.Puntuacion.Puntos += 1 if not self.Fleet.ENEMS: self.Fleet.create_fleet() def draw(self): self.screen.blit(self.Fondo, (0, 0)) #pygame.draw.circle(self.screen, (0, 0, 0), (self.app.width/2, self.app.height/2), 30) self.ship.draw() self.Puntuacion.draw() self.Fleet.draw() def exit(self): print('Termina: ', self.name)