def findNextPos(self, aturn, charac, move, cpx, cpy): if isinstance(self.board[cpx][cpy], pawn.Pawn): p = self.board[cpx][cpy] p.assRnC(aturn, move) co = coordinate.Coordinate(cpx, cpy) co.nextPosXY(p) npx, npy = co.npx, co.npy elif isinstance(self.board[cpx][cpy], hero1.Hero1): h1 = self.board[cpx][cpy] h1.assRnC(aturn, move) co = coordinate.Coordinate(cpx, cpy) co.nextPosXY(h1) npx, npy = co.npx, co.npy elif isinstance(self.board[cpx][cpy], hero2.Hero2): h2 = self.board[cpx][cpy] h2.assRnC(aturn, move) co = coordinate.Coordinate(cpx, cpy) co.nextPosXY(h2) npx, npy = co.npx, co.npy elif isinstance(self.board[cpx][cpy], hero3.Hero3): h3 = self.board[cpx][cpy] h3.assRnC(aturn, move) co = coordinate.Coordinate(cpx, cpy) co.nextPosXY(h3) npx, npy = co.npx, co.npy return (npx, npy)
def GetSunCoordinate(self): self._observer.date = datetime.datetime.utcnow() sun = ephem.Sun(self._observer) return coordinate.Coordinate(pitch=float(sun.alt), yaw=float(sun.az), name='Sun', degree=False)
def LoadConfig(self, config_filename): with open(config_filename, 'r') as f: json_data = json.loads(f.read()) target_parameters = {} for data in json_data: if data['name'] == 'sun': target_parameters[data['name']] = coordinate.Coordinate( pitch=None, yaw=None, degree=True, name=data['name']) else: target_parameters[data['name']] = coordinate.Coordinate( pitch=data['pitch'], yaw=data['yaw'], degree=True, name=data['name']) print 'Config file %s was loaded successfully.' % config_filename return target_parameters
def on_click(self, event: tkinter.Event) -> None: 'Handles changing of the label, creation of ovals before & after game starts where black and white input the original board' self._color_count.grid(row=5, column=0, padx=10, pady=10, sticky=tkinter.W) if self._change_color: if self._done_int == 2: self._game_state.change_turn(self._first_player) self._done_int += 1 self._turn_label.configure(text='Turn: ' + othello_logic2.number_to_letter( self._game_state.return_turn())) else: self._game_state.change_turn( othello_logic2.opposite(self._game_state.return_turn())) self._turn_label.configure(text='Turn: ' + othello_logic2.number_to_letter( self._game_state.return_turn())) fill = self.color_filled() x = event.x y = event.y coor = coordinate.Coordinate(self._canvas.winfo_width(), self._canvas.winfo_height(), self._rows, self._cols) x_coor = coor.return_grid_x(x) y_coor = coor.return_grid_y(y) x, y = coor.return_coords_given_grid([x_coor, y_coor]) #print('xcoor',x,'ycoor',y) if self._game_state.return_board()[y_coor][x_coor] != 0: return self._game_state.return_board( )[y_coor][x_coor] = self._game_state.return_turn() self._canvas_width = self._canvas.winfo_width() self._canvas_height = self._canvas.winfo_height() #temp = self._canvas.create_oval(x,y,x+int(self._canvas_width/self._cols),y+int(self._canvas_height/self._rows),fill=fill) change back temp = self._canvas.create_oval(self._canvas.coords( self._dictionary_rect[y_coor, x_coor]), fill=fill) self._dictionary[x_coor, y_coor] = temp self._list_of_ovals.append(temp) self._list_of_orig.append((x, y, self._canvas_width, self._canvas_height, temp, x_coor, y_coor)) self._canvas.bind('<Configure>', self.if_changed, add='+') count = self._game_state.count() self._color_count.configure(text='B: ' + str(count[0]) + ' W: ' + str(count[1]))
def MakeGrid(Bounds, rows, cols): x_increment = (Bounds[0].GetUL.GetLng() - Bounds[1].GetUL.GetLng()) / cols y_increment = (Bounds[1].GetUL.GetLat() - Bounds[3].GetDR.GetLat()) / rows current = Bounds[0].GetUL nodes = [] for i in range(0, rows): lat_next = current.GetLat() + y_increment nodes.append([]) for j in range(0, cols): lng_next = current.GetLng() + x_increment node = nodo.Nodo(lat_next / 2, lng_next / 2, 0) nodes[j].append(node) current = coor.Coordinate(current.GetLat(), lng_next) current = coor.Coordinate(lat_next, current.GetLng()) return nodes
def generateCoordinates(numberOfCities, coordinates): for i in range(numberOfCities): x = random.randint(1, 10000) y = random.randint(1, 10000) nCoordinate = coordinate.Coordinate(x=x, y=y) coordinates.append(nCoordinate)
def __init__(self, station_id): self.name = "" self.item = "" self.station_id = station_id self.address = "" self.coord = coordinate.Coordinate() self._data_page = None self.df = pandas.DataFrame()
def get_adj_coords(self, coord): """Returns a list of coordinates adjacent to coordinate coord""" adj_coords = [] if not coord.x == 0: adj_coords.append(coord_class.Coordinate(coord.x - 1, coord.y)) if not coord.x == self.num_rows - 1: adj_coords.append(coord_class.Coordinate(coord.x + 1, coord.y)) if not coord.y == 0: adj_coords.append(coord_class.Coordinate(coord.x, coord.y - 1)) if not coord.y == self.num_cols - 1: adj_coords.append(coord_class.Coordinate(coord.x, coord.y + 1)) return adj_coords
def __init__(self, size): self.size = size startDomain = [i+1 for i in range(size)] self.coordinates = [] for i in range(size): for j in range(size): self.coordinates.append(coordinate.Coordinate(i, j, startDomain)) self.constraints = [] self.fullDomain = [x+1 for x in range(self.size)]
def __init__(self, lat, lng): self.center = coor.Coordinate(lat, lng) self.neig_00 self.neig_01 self.neig_02 self.neig_10 self.neig_12 self.neig_20 self.neig_21 self.neig_22
def get_interection_point(plane_eq_1, plane_eq_2): print(plane_eq_1) print(plane_eq_2) x = -78.0073 y = (-plane_eq_1.get_d() - plane_eq_1.get_coef_x() * x) / plane_eq_1.get_coef_y() z = 0 intersection_point = coordinate.Coordinate(x, y, z) return copy.deepcopy(intersection_point)
def GetReflectionAngles(sun_coordinate, mirror_coordinate): world_ray_sun = sun_coordinate.GetRay(reverse=True) world_normal_mirror = mirror_coordinate.GetRay(reverse=False) dot_product = world_ray_sun.transpose().dot(world_normal_mirror) world_ray_reflection = world_ray_sun - 2 * dot_product * world_normal_mirror reflection_yaw = np.arctan2(world_ray_reflection[1], world_ray_reflection[0]) reflection_pitch = np.arcsin(-world_ray_reflection[2]) if reflection_yaw < 0: reflection_yaw += 2 * np.pi return coordinate.Coordinate(pitch=reflection_pitch, yaw=reflection_yaw, name='Reflection', degree=False)
def generate_coord_boards(): """Generates a 2D coordinate board and its transpose. These are used when verifying solutions and creating random boards. """ self.coord_board = [] for x in range(self.num_rows): coord_list = [] for y in range(self.num_cols): coord_list.append(coord_class.Coordinate(x, y)) self.coord_board.append(coord_list) self.transpose_coord_board = [ list(l) for l in zip(*self.coord_board) ]
def _get_station_info(self): self._station_info["station_name"] = self._soup.find( "td", string="観測所名").findNext("td").get_text() self._station_info["item"] = self._soup.find( "td", string="観測項目").findNext("td").get_text() if self._station_info["item"] == "水位流量" or self._station_info[ "item"] == "雨量": self._station_info["basin_name"] = self._soup.find( "td", string="水系名").findNext("td").get_text() self._station_info["river_name"] = self._soup.find( "td", string="河川名").findNext("td").get_text() if self._station_info["item"] == "水位流量": self._station_info["tp"] = self._soup.find( "td", string="最新の零点高").findNext("td").get_text() self._station_info["address"] = self._soup.find( "td", string="所在地").findNext("td").get_text() coord_text = self._soup.find("td", string="緯度経度").findNext("td").get_text() lon, lat = coordinate.coord_text_to_lonlat(coord_text) self._station_info["coord"] = coordinate.Coordinate() self._station_info["coord"].set_by_lonlat(lon, lat)
def draw_grid(self, event: tkinter.Event) -> None: 'Draws rectangles cooresponding to the width and height of the canvas at the specific event' self._canvas.delete('r') self._canvas_width = self._canvas.winfo_width() self._canvas_height = self._canvas.winfo_height() for r in range(0, self._rows): for c in range(0, self._cols): coor = coordinate.Coordinate( self._canvas_width, self._canvas_height, self._rows, self._cols) #change into coordinate class l = self._canvas.create_rectangle(coor.return_scaled_coords( r, c), tag='r') self._list_of_rect.append(l) self._dictionary_rect[r, c] = l #print(self._canvas.coords(l)) #print('LOL',self._canvas_width) self._canvas.highlightthickness = 0 if self._change_color != True: self._canvas.bind('<Button-1>', self.on_click) #MOVE THIS else: self._canvas.bind('<Button-1>', self.run_othello) self.if_changed(event)
def if_changed(self, event: tkinter.Event) -> None: 'If the canvas size is changed changes the size of the ovals and rectangles' #print('k',self._list_of_ovals) for l in range(len(self._list_of_ovals)): x = self._list_of_orig[l][0] y = self._list_of_orig[l][1] current_width = self._list_of_orig[l][2] current_height = self._list_of_orig[l][3] coor = coordinate.Coordinate(current_width, current_height, self._rows, self._cols) new_x = (1 / self._cols) * coor.return_grid_x(x) * round( self._canvas_width, -1) new_y = (1 / self._rows) * coor.return_grid_y(y) * round( self._canvas_height, -1) self._canvas.coords(self._list_of_ovals[l], new_x, new_y, new_x + int(self._canvas_width / self._cols), new_y + int(self._canvas_height / self._rows)) count = self._game_state.count() self._color_count.configure(text='B: ' + str(count[0]) + ' W: ' + str(count[1]))
def __init__(self, config): """Initializes the light up puzzle class.""" def generate_coord_boards(): """Generates a 2D coordinate board and its transpose. These are used when verifying solutions and creating random boards. """ self.coord_board = [] for x in range(self.num_rows): coord_list = [] for y in range(self.num_cols): coord_list.append(coord_class.Coordinate(x, y)) self.coord_board.append(coord_list) self.transpose_coord_board = [ list(l) for l in zip(*self.coord_board) ] def generate_random_board(): """Randomly generates a solvable board. Solvable boards are generated by iteratively placing black squares (with probability dictated by the configuration file) and required bulbs around each square before removing the bulbs, leaving a board with at least one solution. This function should only be called in __init__ """ self.black_squares = {} self.bulbs = set([]) if self.config.settings["override_random_board_dimensions"]: self.num_rows = self.config.settings["override_num_rows"] self.num_cols = self.config.settings["override_num_cols"] else: min_dimension = self.config.settings[ "min_random_board_dimension"] max_dimension = self.config.settings[ "max_random_board_dimension"] self.num_rows = random.randint(min_dimension, max_dimension) self.num_cols = random.randint(min_dimension, max_dimension) generate_coord_boards() # Create a list of shuffled coordinates used in assigning black squares shuffled_coords = [] for row in self.coord_board: for coord in row: shuffled_coords.append(coord) random.shuffle(shuffled_coords) # Assign black squares to the board for coord in shuffled_coords: if not coord in self.bulbs and random.random( ) <= self.config.settings["black_square_placement_prob"]: adj_coord_list = self.get_adj_coords(coord) num_placed_bulbs = 0 # Compute the random max value for this black square max_value = random.choices( list( range( 0, self.config.settings["adj_value_dont_care"])), self.config. settings["black_square_value_probabilities"])[0] # Put a placeholder black square to ensure the maximum amount of bulbs can be placed self.black_squares[coord] = self.config.settings[ "adj_value_dont_care"] # Place bulbs around the square, if allowed for adj_coord in adj_coord_list: if num_placed_bulbs < max_value and self.place_bulb( adj_coord): num_placed_bulbs += 1 # Update the real black square value to match the number of adjacent bulbs self.black_squares[coord] = num_placed_bulbs if not self.check_completely_solved(): # Fill non-lit coordinates with black squares of value self.config.settings["adj_value_dont_care"] for coord in shuffled_coords: if not coord in self.shined_squares and not coord in self.bulbs and not coord in self.black_squares: self.black_squares[coord] = self.config.settings[ "adj_value_dont_care"] self.black_squares = {} self.bulbs = set([]) self.log_str = '' self.config = config # Seed the random number generator self.log_str += 'seed: ' if self.config.settings["use_external_seed"]: # Use external seed seed_val = self.config.settings["seed"] else: # Default to system time as seed seed_val = time.time() random.seed(seed_val) self.log_str += str(seed_val) + '\n\n' if self.config.settings["generate_board"]: # Generate random initial board state generate_random_board() while len(self.black_squares) == ( self.num_cols * self.num_rows) or not self.check_completely_solved(): generate_random_board() # Re-initialize the bulb set self.bulbs = set([]) self.log_str += 'randomly generated puzzle\n' + \ '\tmin_random_board_dimension: ' + str(self.config.settings["min_random_board_dimension"]) + '\n' + \ '\tmax_random_board_dimension: ' + str(self.config.settings["max_random_board_dimension"]) + '\n' + \ '\toverride_random_board_dimensions: ' + ('True' if self.config.settings["override_random_board_dimensions"] else 'False') + '\n' + \ '\toverride_num_rows: ' + str(self.config.settings["override_num_rows"]) + '\n' + \ '\toverride_num_cols: ' + str(self.config.settings["override_num_cols"]) + '\n' + \ '\tblack_square_value_probabilities: ' + str(self.config.settings["black_square_value_probabilities"]) + '\n' + \ '\tblack_square_placement_prob: ' + str(self.config.settings["black_square_placement_prob"]) + '\n\n' else: # Read initial board state with open(self.config.settings["input_file_path"], 'r') as input_file: self.log_str += 'puzzle source: ' + self.config.settings[ "input_file_path"] + '\n\n' # Read line 0 (number of columns) self.num_cols = int(input_file.readline()) # Read line 1 (number of rows) self.num_rows = int(input_file.readline()) # Read line 2 to eof (coordinates of black squares and their adjacency values) for row in input_file: black_square_data = [int(i) for i in row.split()] self.black_squares[coord_class.Coordinate( black_square_data[1] - 1, black_square_data[0] - 1)] = black_square_data[2] # Generate coordinate versions of the board generate_coord_boards() self.log_str += 'board size (#cols x #rows): ' + str(self.num_cols) + ' x ' + str(self.num_rows) + '\n' + \ 'enforce_adj_quotas: ' + ('True' if self.config.settings["enforce_adj_quotas"] else 'False') + '\n' + \ 'adj_value_dont_care: ' + str(self.config.settings["adj_value_dont_care"]) + '\n' + \ 'max_num_random_bulb_placements: ' + str(self.config.settings["max_num_random_bulb_placements"]) + '\n\n' with open(config.settings["log_file_path"], 'a') as log: log.write(self.log_str) self.num_empty_squares = -1 # This value is updated during solution verification
import constants import coordinate import pigpio import servo pi_client = pigpio.pi() servo_client = servo.ServoClient(pi_client, constants.SERVO_PARAMETERS) while True: input = raw_input('Enter pitch yaw: ') input_list = input.split(' ') pitch = float(input_list[0]) yaw = float(input_list[1]) target = coordinate.Coordinate(pitch=pitch, yaw=yaw, degree=True, name='target') target.Print() try: servo_client.MoveTo(target) except pigpio.error: servo_client.MoveTo(target, sleeptime=0)
def get_random_coord(self): """Returns a random coordinate ranging in the space (num_cols, num_rows).""" return coord_class.Coordinate(random.randint(0, self.num_rows - 1), random.randint(0, self.num_cols - 1))
def __init__(self): coordSet = coordinate.Coordinate()
#the testing values here are made up by me (eccept for the eccentricity which is from alhpa centauri) #they have no meaning except for the fact that they given nice pictures import coordinate import math import sphere import matplotlib.pyplot as plt import orbit import constants origin = coordinate.origin a = coordinate.Coordinate(0, 0, 40000000000) b = coordinate.Coordinate(17, -4, 9) c = coordinate.Coordinate(0, 1000000000, 10000000000) d = coordinate.Coordinate(4, 9, 16) e = coordinate.Coordinate(40000000000, 0, 0) f = coordinate.Coordinate(10000000000, 100000000, 0) g = coordinate.Coordinate(0, 1100000000, 10000000000) x = origin - coordinate.Coordinate(1, 0, 0) y = origin - coordinate.Coordinate(0, 1, 0) z = origin - coordinate.Coordinate(0, 0, 1) sphere_one = sphere.Star(10, 100) sphere_two = sphere.Star(1, 1) sphere_three = sphere.Star(1, 1) sphere_one.plot() sphere_one.plot_with_obstruction(origin, a, c, sphere_two) sphere_one.plot_with_obstruction(origin, a, g, sphere_two)
#!/usr/bin/env python2.7 import sys import coordinate import world import theano as th from car import UserControlledCar #import gc th.config.optimizer_verbose = False th.config.allow_gc = False if __name__ == '__main__': world_to_use = world.world7(0.1) coord = coordinate.Coordinate() coord.use_world(world_to_use) coord.run() #gc.collect() print("HERE!") del world_to_use del coord world_to_use = world.world7(0.3) coord = coordinate.Coordinate() coord.use_world(world_to_use) coord.run() print("HERE AGAIN!")
import coordinate import mirror sun = coordinate.Coordinate(pitch=60, yaw=270, degree=True, name='sun') sun.Print() target = coordinate.Coordinate(pitch=10, yaw=135, degree=True, name='target') target.Print() mirror.GetMirrorCoordinate(sun, target, max_iter=50)
def run_othello(self, event: tkinter.Event) -> None: 'Main othello code that handles the clicking of each turn on the canvas' if self._done_int == 2: self._game_state.change_turn(self._game_state._first_player) self._turn_label.configure( text='Turn: ' + othello_logic2.number_to_letter(self._game_state.return_turn()) ) self._done_int += 1 continues = False list_of_changes = [] list_of_deltas = [[-1, 0], [1, 1], [1, 0], [1, -1], [0, -1], [-1, -1], [0, 1], [-1, 1]] count = self._game_state.count() self._color_count.configure(text='B: ' + str(count[0]) + ' W: ' + str(count[1])) self._color_count.grid(row=5, column=0, padx=10, pady=10, sticky=tkinter.W) if self._game_state.board_capacity_checker(): text = str('WINNER: ' + othello_logic2.number_to_letter( othello_logic2.get_winner(self._win_determiner, count))) self._turn_label.configure( text=text) #KEEPS SAYING WINNER WHEN NO WINNER return if not self._game_state.valid_move_left(self._game_state.return_turn(), self._rows, self._cols, list_of_deltas): self._game_state.change_turn( othello_logic2.opposite(self._game_state.return_turn())) #print('yo') if not self._game_state.valid_move_left( self._game_state.return_turn(), self._rows, self._cols, list_of_deltas): #print('oyo') text = str('WINNER: ' + othello_logic2.number_to_letter( othello_logic2.get_winner(self._win_determiner, count))) self._turn_label.configure(text=text) self._canvas.bind('<Button-1>', print) return else: self._turn_label.configure( text='No turn available for ' + othello_logic2.number_to_letter( othello_logic2.opposite( self._game_state.return_turn())) + ' so, Turn: ' + othello_logic2.number_to_letter( self._game_state.return_turn())) x = event.x y = event.y coor = coordinate.Coordinate(self._canvas.winfo_width(), self._canvas.winfo_height(), self._rows, self._cols) x_coor = coor.return_grid_x(x) y_coor = coor.return_grid_y(y) if self._game_state.return_board()[y_coor][x_coor] != 0: return untouched = 0 if self._game_state.is_valid_move(self._game_state.return_turn(), y_coor, x_coor, self._rows, self._cols, list_of_deltas): for deltas in list_of_deltas: if self._game_state.check_sequence( self._game_state.return_turn(), y_coor, x_coor, deltas[0], deltas[1], self._rows, self._cols): color_count_before = self._game_state.count() #othello_logic2.print_board(self._game_state.return_board()) test = self._game_state.make_move( self._game_state.return_turn(), y_coor, x_coor, deltas[0], deltas[1], self._rows, self._cols) #print('next') #othello_logic2.print_board(self._game_state.return_board()) color_count_after = self._game_state.count() if color_count_before != color_count_after: untouched += 1 #doesnt work, i tihnk its somewhere in the code above that it doesnt change list_of_changes.append( test ) #game_state board and doesnt accept any click as valid # print(list_of_changes) continues = True # print('u',untouched) if untouched != 0: untouched = 0 # something wrong here self._game_state.return_board( )[y_coor][x_coor] = self._game_state.return_turn() list_of_changes[0].append([y_coor, x_coor]) #print(list_of_changes) x, y = coor.return_coords_given_grid([x_coor, y_coor]) #print('RUN OTHELLO',x,y) self._canvas_width = self._canvas.winfo_width() self._canvas_height = self._canvas.winfo_height() #temp = self._canvas.create_oval(x,y,x+int(self._canvas_width/self._cols),y+int(self._canvas_height/self._rows),fill=self.color_filled()) change back temp = self._canvas.create_oval(self._canvas.coords( self._dictionary_rect[y_coor, x_coor]), fill=self.color_filled()) self._dictionary[x_coor, y_coor] = temp self._list_of_ovals.append(temp) self._list_of_orig.append( (x, y, self._canvas_width, self._canvas_height)) for l in list_of_changes: for coor in l: fill = self.color_filled() self._canvas.itemconfig(self._dictionary[coor[1], coor[0]], fill=fill) self._covered_spaces = [] self._game_state.change_turn( othello_logic2.opposite(self._game_state.return_turn())) if continues: self.on_click(event) self._game_state.change_turn( othello_logic2.opposite(self._game_state.return_turn())) self._turn_label.configure( text='Turn: ' + othello_logic2.number_to_letter(self._game_state.return_turn())) count = self._game_state.count() self._color_count.configure(text='B: ' + str(count[0]) + ' W: ' + str(count[1])) #print('herereree') if not self._game_state.valid_move_left(self._game_state.return_turn(), self._rows, self._cols, list_of_deltas) \ and self._game_state.valid_move_left(othello_logic2.opposite(self._game_state.return_turn()), self._rows, self._cols, list_of_deltas): self._game_state.change_turn( othello_logic2.opposite(self._game_state.return_turn())) self._turn_label.configure(text = 'No turn available for '+othello_logic2.number_to_letter(othello_logic2.opposite(self._game_state.return_turn())) \ +' so, Turn: ' +othello_logic2.number_to_letter(self._game_state.return_turn())) if not self._game_state.valid_move_left(othello_logic2.opposite(self._game_state.return_turn()), self._rows, self._cols, list_of_deltas) \ and not self._game_state.valid_move_left(self._game_state.return_turn(), self._rows, self._cols, list_of_deltas): text = str('WINNER: ' + othello_logic2.number_to_letter( othello_logic2.get_winner(self._win_determiner, count))) self._turn_label.configure(text=text)