def test_placingTwoBoats(self): boat1 = Boat(5) boat2 = Boat(2) grid = Grid(10, 10) boat1.place(grid, 0, 0, Boat.DIR_RIGHT) # Can't place over an existing boat self.assertEqual(boat2.place(grid, 0, 0, Boat.DIR_DOWN), False) # Can place anywhere else self.assertEqual(boat2.place(grid, 0, 1, Boat.DIR_DOWN), True)
def editschedule(): global con # set debugging level db.enabled = False # Only administrators have access to this page if not session['administrator']: return render_template( 'error.html', error="Only Administrators can access schedules") # create the objects we need sched = Schedule() bt = Boat() rt = Route() # process the data sent back from the form if request.method == 'POST': # Read the boats and schedule to display in option lists boats = readBoatTable() routes = readRouteTable() # If they processed the edit button then read the scchedule record and pass the details # to the new schedule scren if 'Edit' in request.form: CruiseDate = request.form['Edit'].split('.')[0] CruiseNo = int(request.form['Edit'].split('.')[1]) (dbStatus, rows) = sched.readSched(con, CruiseDate, CruiseNo) if dbStatus == False: # return render_template("newschedule.html", sched = rows, CruiseDate = CruiseDate, CruiseNo = CruiseNo, boats = boats, routes = routes, action = 'UPDATE', returnmessage = sched.error) return render_template("newschedule.html", sched=rows, CruiseDate=CruiseDate, CruiseNo=CruiseNo, boats=boats, routes=routes, action='UPDATE', returnmessage=sched.error) else: return render_template("newschedule.html", sched=rows[0], CruiseDate=CruiseDate, CruiseNo=CruiseNo, boats=boats, routes=routes, action='UPDATE') # If they have pressed add then create a blank 'rows' record and pass to the newschedule form if 'Add' in request.form: rows = sched.blankScheduleRow() CruiseDate = rows[0]["CruiseDate"] CruiseNo = int(rows[0]["CruiseNo"]) return render_template("newschedule.html", sched=rows, CruiseDate=CruiseDate, CruiseNo=CruiseNo, boats=boats, routes=routes, action='ADD')
def readBoatTable(): bt = Boat() (dbStatus, boats) = bt.readBoats(con) if (dbStatus == False): return render_template('error.html', error=bt.error) else: return (boats)
def initBoat(self, sc, space): boat = Boat(sc, self._listwp[0].X + 15, self.screen.get_size()[1] - self._listwp[0].Y - 50, random.randint(5, 10), space) boat.speed = random.randint(10, 20) * 10 boat.maxspeed = boat.speed return boat
def __init__(self): """ Initialization function for a game of Students and Monobears. """ # Create a list of entities on the left side self.left_side_entities = [] # Create a list of entities on the right side self.right_side_entities = [] # Put the boat on the right side of the game boat = Boat() self.right_side_entities.append(boat) # Create three students on the right side for x in range(0, 3): if (x is 0): name = 'Fukawa' elif (x is 1): name = 'Kirigiri' elif (x is 2): name = 'Asahina' print('Student name is ' + name) student = Student(name) print(student.name + ' is on the ' + student.location + ' side') self.right_side_entities.append(student) # Create three monobears on the right side for x in range(0, 3): monobear = Monobear(x) print('Monobear ' + str(monobear.number) + ' created!') print('Monobear ' + str(monobear.number) + ' is on the ' + monobear.location + ' side') self.right_side_entities.append(monobear)
def test_connection(connection_parameters): boat = Boat(**connection_parameters) boat.connect(wait_ready=False) assert boat.vehicle is not None boat.vehicle.close()
def __init__(self, log_interval=10, sample_interval=1): # self.boat = boat.Boat(compass_file=boat.Boat.DEFAULT_CALIBRATION_FILE_PATH) self.boat = Boat(compass_file=None) # self.boat.compass.params = compass.Compass._default_params() self.skiff = Skiff() self.sample_interval = sample_interval self.log_interval = log_interval self.filename = None self.has_boat_pressure_gauge = self.boat.pressure_gauge is not None if self.has_boat_pressure_gauge: logger.info("Successfully loaded boat pressure gauge") else: logger.warning("FAILED to load boat pressure gauge") self.has_boat_compass = self.boat.compass is not None if self.has_boat_compass: logger.info("Successfully loaded boat compass") else: logger.warning("FAILED to load boat compass") self.has_boat_gps = self.boat.has_gps() if self.has_boat_gps: logger.info("Successfully loaded boat gps") else: logger.critical("FAILED to load boat gps") self.has_boat_gps_fix = self.boat.has_gps_fix() if self.has_boat_gps_fix: logger.info("Successfully got fix on boat gps") else: logger.critical("FAILED to get fix on boat gps") print("here!")
def event_handler(self, event): print(self.current_player.id) if self.current_gamestate == "setup": px, py = event.pos size = self.current_player.board.cell_size x = int(px / size) y = int(py / size) if (x < self.amount_of_cols) & (y < self.amount_of_cols - 2): #FUUULT boat_cells = [ self.current_player.board.cells[x][y], self.current_player.board.cells[x][y + 1], self.current_player.board.cells[x][y + 2] ] boat = Boat(boat_cells, self) if self.current_player.board.check_cell(event.pos, boat): boat.place() self.current_player.boats.append(boat) else: hit_not_occupied = self.current_player.board.check_cell(event.pos) self.current_player.board.render() has_alive_boats = False if hit_not_occupied: print("hit") for boat in self.current_player.boats: if boat.alive: has_alive_boats = True break if not has_alive_boats: self.current_player.board.render_winner_text( self.current_player) return sleep(1) self.change_current_player()
def main(n=5, t=1): if n < 5: raise Exception("N must be greater than 5") if t <= 0: raise Exception("T must be grater than 0") boat = Boat() boat.start_server(n, t) boat.manage_requests()
def test_vehicle_mode(connection_parameters): boat = Boat(**connection_parameters) boat.connect(wait_ready=False) boat.set_mode('GUIDED') assert boat.vehicle.mode.name == 'GUIDED' boat.vehicle.close()
def test_vehicle_armed(connection_parameters): boat = Boat(**connection_parameters) boat.connect(wait_ready=False) boat.arm() assert boat.vehicle.armed boat.vehicle.close()
def test_wait_armable_vehicle(connection_parameters): boat = Boat(**connection_parameters) boat.connect(wait_ready=False) while not boat.vehicle.is_armable: print(" Waiting for vehicle to initialise...") time.sleep(1) assert boat.vehicle.is_armable boat.vehicle.close()
def main(): commands = [] with open('day12/input.txt', 'r') as f: commands = f.read().splitlines() boat = Boat() for command in commands: execute_command(actor=boat, command=command) print(boat) print(f"Manhattan distance {boat.manhattan_distance()}")
def place_one_boat(self, boat_type: BoatType, pos_head: tuple, orientation: Orientation): if self.check_correct_boat_location(boat_type, pos_head, orientation): self.my_boats.append(Boat(boat_type, pos_head, orientation)) if orientation == Orientation.horizontal: for i in range(boat_type.value): self.my_grid[pos_head[1]][pos_head[0] + i] = GridCellType.boat.value elif orientation == Orientation.vertical: for i in range(boat_type.value): self.my_grid[pos_head[1] + i][pos_head[0]] = GridCellType.boat.value
def run_test(): pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) boat = Boat(screen, ai_settings) pygame.display.set_caption("test-12_5") bullets = Group() while True: gf.check_events(ai_settings, screen, boat, bullets) boat.update() gf.update_bullets(bullets, ai_settings) gf.update_screen(ai_settings, screen, boat, bullets)
def test_placingBoatRight(self): boat = Boat(5) grid = Grid(10, 10) # Can't self.assertEqual(boat.place(grid, 9, 2, boat.DIR_RIGHT), False) self.assertEqual(grid.get(9, 2), Grid.EMPTY) # Can self.assertEqual(boat.place(grid, 2, 2, boat.DIR_RIGHT), True) self.assertEqual(grid.get(2, 2), Grid.BOAT) self.assertEqual(grid.get(3, 2), Grid.BOAT) self.assertEqual(grid.get(4, 2), Grid.BOAT) self.assertEqual(grid.get(5, 2), Grid.BOAT) self.assertEqual(grid.get(6, 2), Grid.BOAT) # Can't anymore self.assertEqual(boat.place(grid, 0, 2, boat.DIR_RIGHT), False)
def test_placingBoatUp(self): boat = Boat(5) grid = Grid(10, 10) # Can't self.assertEqual(boat.place(grid, 0, 0, boat.DIR_UP), False) self.assertEqual(grid.get(0, 0), Grid.EMPTY) # Can self.assertEqual(boat.place(grid, 6, 6, boat.DIR_UP), True) self.assertEqual(grid.get(6, 6), Grid.BOAT) self.assertEqual(grid.get(6, 5), Grid.BOAT) self.assertEqual(grid.get(6, 4), Grid.BOAT) self.assertEqual(grid.get(6, 3), Grid.BOAT) self.assertEqual(grid.get(6, 2), Grid.BOAT) # Can't anymore self.assertEqual(boat.place(grid, 6, 6, boat.DIR_UP), False)
def test_placingBoatLeft(self): boat = Boat(5) grid = Grid(10, 10) # Can't self.assertEqual(boat.place(grid, 0, 7, boat.DIR_LEFT), False) self.assertEqual(grid.get(0, 7), Grid.EMPTY) # Can self.assertEqual(boat.place(grid, 7, 7, boat.DIR_LEFT), True) self.assertEqual(grid.get(7, 7), Grid.BOAT) self.assertEqual(grid.get(6, 7), Grid.BOAT) self.assertEqual(grid.get(5, 7), Grid.BOAT) self.assertEqual(grid.get(4, 7), Grid.BOAT) self.assertEqual(grid.get(3, 7), Grid.BOAT) # Can't anymore self.assertEqual(boat.place(grid, 7, 7, boat.DIR_LEFT), False)
def test_placingBoatDown(self): boat = Boat(5) grid = Grid(10, 10) # Can't self.assertEqual(boat.place(grid, 0, 9, boat.DIR_DOWN), False) self.assertEqual(grid.get(0, 9), Grid.EMPTY) # Can self.assertEqual(boat.place(grid, 0, 0, boat.DIR_DOWN), True) self.assertEqual(grid.get(0, 0), Grid.BOAT) self.assertEqual(grid.get(0, 1), Grid.BOAT) self.assertEqual(grid.get(0, 2), Grid.BOAT) self.assertEqual(grid.get(0, 3), Grid.BOAT) self.assertEqual(grid.get(0, 4), Grid.BOAT) # Can't anymore self.assertEqual(boat.place(grid, 0, 0, boat.DIR_DOWN), False)
def test_placingRandomly(self): boat = Boat(5) grid = Grid(10, 10) boat.place(grid) self.assertEqual(len(boat.pos_x), 5) self.assertEqual(len(boat.pos_y), 5) # Trying to hit the boat while boat.remaining > 0: remaining = boat.remaining x = boat.pos_x[0] y = boat.pos_y[0] self.assertEqual(boat.hit(x, y), True) self.assertEqual(boat.remaining, remaining - 1) self.assertEqual(boat.hit(x, y), False) self.assertEqual(boat.remaining, remaining - 1)
def run_game(): pygame.init() mySettings = MySettings() screen = pygame.display.set_mode( (mySettings.screen_width, mySettings.screen_height)) pygame.display.set_caption("Blue Sky") myBoat = Boat(screen) myMissiles = Group() #开始游戏主循环 while True: mf.check_events(mySettings, screen, myBoat, myMissiles) myBoat.update(mySettings, screen, myMissiles) mf.fire(screen, myMissiles) mf.update_screen(mySettings, screen, myBoat, myMissiles)
def test_hit(self): boat = Boat(5) grid = Grid(10, 10) self.assertEqual(boat.place(grid, 2, 2, boat.DIR_RIGHT), True) self.assertEqual(boat.remaining, 5) # Miss self.assertEqual(boat.hit(1, 2), False) self.assertEqual(boat.hit(2, 1), False) self.assertEqual(boat.hit(2, 3), False) self.assertEqual(boat.hit(7, 2), False) # Hit self.assertEqual(boat.hit(2, 2), True) self.assertEqual(boat.remaining, 4) # Can't hit a second time at the same pos self.assertEqual(boat.hit(2, 2), False) self.assertEqual(boat.remaining, 4)
def load(self): self.group = [] for i in range(NUM_PLAYER): boat = Boat() brain = NN() brain.init_weights() player = Player(brain, boat) self.group.append(player) if LOAD_PATH is not None: checkpoint = torch.load(LOAD_PATH) self.current_generation = checkpoint['generation'] for i, ind in enumerate(self.group): str_ind = 'ind_' + str(i) ind.brain.load_state_dict(checkpoint[str_ind]) ind.brain.eval()
def test_set_sail(connection_parameters): boat = Boat(**connection_parameters) boat.connect() boat.arm() boat.set_mode('GUIDED') lat_point = 42.227870 long_point = -8.719468 boat.goto(latitude=lat_point, longitude=long_point, ground_speed=10) while boat.vehicle.location.global_frame.lat < lat_point: time.sleep(1) assert 42.227860 < boat.vehicle.location.global_frame.lat < 42.227890 boat.vehicle.close()
def main(): with open('input.txt', newline='') as raw_input: puzzle_input = raw_input.read().splitlines() puzzle_boat = Boat(90) for dir in puzzle_input: if dir[0] in 'NESW': puzzle_boat.add_to_direction(dir[0], int(dir[1:])) elif dir[0] in 'LR': puzzle_boat.change_direction(dir[0], int(dir[1:])) elif dir[0] == 'F': puzzle_boat.forward(int(dir[1:])) # prints answer puzzle_boat.manhattan_distance()
def objects_request(self, left, top, right, bottom, age): if not self._has_token(): self._authenticate() url = self._generate_url_objects(left, top, right, bottom, age) objects_resp = requests.get(url, headers={'Authorization': self._token}) objects_json = json.loads(objects_resp.text) # invert list order before returning list. print objects_json boats = [] for data_item in objects_json: boat_state = BoatState(data_item['Position']['y'], data_item['Position']['x'], data_item['Direction'], data_item['Speed'], data_item['Lastupdate']) boats.append( Boat(data_item['Id'], data_item['Name'], data_item['Type'], data_item['Length'], data_item['Width'], boat_state)) # invert list order before returning list. return boats
def main(): connection_string = settings.DEFAULT_SERIAL_PORT baud_rate = settings.DEFAULT_BAUD_RATE if arg_options.connect: connection_string = arg_options.connect if arg_options.baud_rate: baud_rate = arg_options.baud_rate boat = Boat(connection_string, baudrate=baud_rate) boat.connect(wait_ready=False) vehicle = boat.vehicle while not vehicle.attitude.pitch: logger.debug(" Waiting for vehicle to initialise...") time.sleep(1) pub.send("DBG", "Autopilot: {!s}".format(vehicle.version)) # logger.debug("Autopilot Firmware version: %s", vehicle.version) pub.send("DBG", "Mode: {}".format(vehicle.mode.name)) # logger.debug("Mode: %s", vehicle.mode.name) # pub.send("DBG", "System status: {}".format(vehicle.system_status)) # logger.debug("System status: %s", vehicle.system_status) pub.send("DBG", "Armed: {}".format(vehicle.armed)) # logger.debug("Armed: %s", vehicle.armed) # print (boat.vehicle.groundspeed) if arg_options.listen: messageLoop(boat) if arg_options.goto: boat.arm() boat.set_mode('GUIDED') lat, lon = arg_options.goto.split(',') boat.goto(lat, lon) boat.vehicle.close()
def __init__(self, dbFilleName='default', dataDistant=False, lat=None, lon=None,cog=None, sog=None, ep_length=100, refDeepth=1): # This function will initialise the sounding point position list # These points will be used to compute the result of your algorithm if dataDistant == False: #We thing that the dataset have the good stucture self.pointDataFrame = pd.read_csv(dbFilleName+str('.csv')) self.pointDataFram.dropna(axis=0, inplace=True) else: try: # Connect to an existing database #change to your database credential self.connection = psycopg2.connect(user="******", password="******", host="127.0.0.1", port="5432", database=dbFilleName) # Create a cursor to perform database operations self.cursor = self.connection.cursor() # Print PostgreSQL details print("PostgreSQL server information") print(self.connection.get_dsn_parameters(), "\n") # Executing a SQL query self.cursor.execute("SELECT version();") # Fetch result record = self.cursor.fetchone() print("You are connected to - ", record, "\n") except (Exception, Error) as error: print("Error while connecting to PostgreSQL", error) exit() #dim self.boat = Boat() dim = 3 #dimenstion de l'espace de travail self.action_space = spaces.Tuple(spaces.Discrete(1), spaces.Discrete(1), spaces.Discrete(1)) self.observation_space = self.action_space self.ep_length = ep_length self.dim = dim self.reset()
def main(): connection_string = settings.DEFAULT_SERIAL_PORT baud_rate = settings.DEFAULT_BAUD_RATE if arg_options.connect: connection_string = arg_options.connect if arg_options.baud_rate: baud_rate = arg_options.baud_rate boat = Boat(connection_string, baudrate=baud_rate) boat.connect(wait_ready=False) vehicle = boat.vehicle while not vehicle.attitude.pitch: logger.debug(" Waiting for vehicle to initialise...") time.sleep(1) logger.debug("Autopilot Firmware version: %s", vehicle.version) logger.debug("Mode: %s", vehicle.mode.name) logger.debug("System status: %s", vehicle.system_status) logger.debug("Armed: %s", vehicle.armed) while arg_options.listen: listen_data = "Location: %s - %s - Groundspeed: %s" % \ (boat.location, boat.vehicle.attitude, boat.vehicle.groundspeed) logger.debug(listen_data) time.sleep(2) if arg_options.goto: boat.arm() boat.set_mode('GUIDED') lat, lon = arg_options.goto.split(',') boat.goto(lat, lon) boat.vehicle.close()
def test_constructor(self): boat = Boat(5) self.assertEqual(boat.size, 5)