コード例 #1
0
 def __init__(self, speed_limit: int, num_lanes: int,
              road_length_meters: float, road_name: str):
     """ The road object will contain all """
     self.road_name = road_name
     self.__begin_intersection = Intersection(self)
     self.end_intersection = Intersection()
     self.speed_limit = speed_limit
     self.num_lanes = num_lanes
     self.lanes = self._init_lanes()
     self.road_length_meters = road_length_meters
     self.capacity = None
コード例 #2
0
    def my_constructor(self, SF_STATION_MAT, RAY_START_HEIGHT):

        # attributes
        ## @var activated
        # Indicates if the ground following algorithm is activated or deactivated. In the last case,
        # the input matrix is simply passed through.
        self.activated = False

        ## @var falling
        # A boolean indicating if the user is currently falling. Used for fall speed computations.
        self.falling = False

        ## @var initial_fall_velocity
        # The starting velocity when the user is falling in meters per frame. Is increased the longer the falling process goes on.
        self.initial_fall_velocity = 0.05

        ## @var height_modification_factor
        # Scaling factor used for the modification of up and down vectors.
        self.height_modification_factor = 0.15

        # fall velocity in meter per frame
        ## @var fall_velocity
        # Speed when the user is falling in meters per frame.
        self.fall_velocity = self.initial_fall_velocity

        # pick length in meter
        ## @var ground_pick_length
        # Length of the ground following ray.
        self.ground_pick_length = 100.0

        ## @var ground_pick_direction_mat
        # Direction of the ground following ray.
        self.ground_pick_direction_mat = avango.gua.make_identity_mat()

        ## @var SCENEGRAPH
        # Reference to the scenegraph to intersect the ground following ray with.
        self.SCENEGRAPH = scenegraphs[0]

        ## @var ray_start_height
        # Starting height of the ground following ray.
        self.ray_start_height = RAY_START_HEIGHT

        # initialize shoot and output matrices
        self.sf_abs_output_mat.value = self.sf_abs_input_mat.value

        self.set_pick_direction(avango.gua.Vec3(0.0, -1.0, 0.0))

        # init field connections
        self.sf_station_mat.connect_from(SF_STATION_MAT)

        # init internal class
        ## @var ground_intersection
        # Intersection class to determine the intersections of the ground following ray with the objects in the scenegraph.
        self.ground_intersection = Intersection()
        self.ground_intersection.my_constructor(self.SCENEGRAPH,
                                                self.sf_gf_start_mat,
                                                self.ground_pick_length,
                                                "gf_pick_group")
        self.mf_ground_pick_result.connect_from(
            self.ground_intersection.mf_pick_result)
コード例 #3
0
    def parseSgfToken(token, board_size=19):
        ''' Takes in a single SGF token and returns an Intersection object
        representing that token.
        '''
        try:
            if token == ")":
                return None
            if len(token) > 5 and token[5] not in (")", "C"):
                SgfParser.raiseInvalidSgf(token)

            if token[0] == 'B':
                stoneColor = StoneColor.BLACK
            elif token[0] == 'W':
                stoneColor = StoneColor.WHITE
            else:
                SgfParser.raiseInvalidSgf(token)

            if token[1] != '[':
                SgfParser.raiseInvalidSgf(token)

            if token[2] == ']':
                coordinate = [-1, -1]
            elif board_size <= 19 and token[2] == 't' and token[
                    3] == 't':  # Part of SGF standard
                coordinate = [-1, -1]
            else:
                coordinate = [
                    ord(token[3]) - ord('a'),
                    ord(token[2]) - ord('a')
                ]
        except IndexError:
            SgfParser.raiseInvalidSgf(token)
        return Intersection(coordinate, stoneColor)
コード例 #4
0
    def __init__(self):
        self.super(MultiTouchDevice).__init__()
        self._sceneGraph = None
        self._display = None
        self._worldMat = avango.gua.make_identity_mat()
        self._transMat = avango.gua.make_identity_mat()
        self._rotMat = avango.gua.make_identity_mat()
        self._scaleMat = avango.gua.make_identity_mat()
        """ Scene transform matrix """
        self._globalMatrix = avango.gua.make_identity_mat()
        """ last cursor position """
        self._lastPos = None
        """ params to evaluate object / navigation mode """
        self._sceneName = None
        self._objectName = None
        self._objectMode = False

        self._headPosition1 = avango.gua.Vec3(0, 0, 0)
        """ params to evaluate intersection """
        self._intersection = Intersection(
        )  # ray intersection for target identification
        self._intersectionFound = False
        self._intersectionPoint = avango.gua.Vec3(0, 0, 0)
        self._intersectionObject = None
        self._lastIntersectionCounter = 0
        """ ray representation"""
        self.ray_length = 10
        self.ray_thickness = 0.0075
        self.intersection_sphere_size = 0.025
        self.highlighted_object = None
        self.hierarchy_selection_level = -1

        self.always_evaluate(True)
コード例 #5
0
    def addNeighbor(self, currentWord, currentWordIsAcross, neighborWord,
                    board):

        for current_i in range(len(currentWord)):
            for neighbor_i in range(len(neighborWord)):
                if currentWord[current_i] == neighborWord[neighbor_i]:

                    # generate an intersection object
                    if currentWordIsAcross:
                        intersection = Intersection(currentWord, current_i,
                                                    neighborWord, neighbor_i)
                    else:
                        intersection = Intersection(neighborWord, neighbor_i,
                                                    currentWord, current_i)

                    # if this is a valid intersection, add it to crossword and break out of the second loop
                    if board.addIfValid(intersection, not currentWordIsAcross):
                        return True

        return False
コード例 #6
0
    def generateMap(self):
        for i in range(len(self.intersectionCount)):
            # Procedurarly position intersection count:

            if (len(self.intersectionCount) == 1):
                print("Map has one intersection")

                # We will generate one intersection in the middle of the map. This is the base case
                currIntersection = Intersection(length=40,
                                                wid=40,
                                                posX=490,
                                                posY=490)

            elif (len(self.intersectionCount) == 2):
                print("Map has two intersections")

            elif (len(self.intersectionCount) == 3):
                print("Map has three intersections")

            elif (len(self.intersectionCount == 5)):
                print("Map has three intersectoins")
コード例 #7
0
ファイル: Road.py プロジェクト: Govoz/graphOSM
def getOrientamentWay(idWay, soup):
    #ottengo la lista di tutti i nodi, cerco quelli più a nord e più a sud e calcolo l'angolazione
    listIntersectionID = getListIntersection(idWay, soup)
    listIntersection = []

    for i in range(len(listIntersectionID)):
        obj = Intersection(listIntersectionID[i], soup)

        listIntersection.append(obj)

    nodeNord = getNodeNord(listIntersection)
    nodeSud = getNodeSud(listIntersection)

    latNord = math.radians(float(nodeNord.lat))
    latSud = math.radians(float(nodeSud.lat))
    lonNord = math.radians(float(nodeNord.lon))
    lonSud = math.radians(float(nodeSud.lon))

    objA = (latNord, lonNord)
    objB = (latSud, lonSud)

    x = calculate_initial_compass_bearing(objA, objB)
    return x
コード例 #8
0
ファイル: solution.py プロジェクト: RdecKa/HashCode2021
# Read which input to choose
selectedInput = "a"
if len(sys.argv) > 1:
    candidate = sys.argv[1]
    if len(candidate) == 1 and candidate in "abcdef":
        selectedInput = candidate
    else:
        print(f"! Invalid input {candidate}, using default")
print(f"Selected input: {selectedInput}")

# Read input
with open(f"input/{selectedInput}.in", "r") as file:
    firstLine = file.readline().strip()
    D, I, S, V, F = list(map(int, firstLine.split(" ")))

    allIntersections = [Intersection(id) for id in range(I)]
    allStreets = {}

    for s in range(S):
        street = Street.fromString(file.readline().strip())
        allStreets[street.name] = street
        allIntersections[street.start].addOutgoing(street)
        allIntersections[street.end].addIncoming(street)
        # print(street)

    for v in range(V):
        car = Car.fromString(file.readline().strip(), allStreets, D)
        # print(car)

    # for street in allStreets.values():
    #     print(street)
コード例 #9
0
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
###########################################################################################

import socket  # Import socket module
import gopigo
from Intersection import *

s = socket.socket()  # Create a socket object
host = socket.gethostname()  # Get local machine name
turnList = [
    Intersection(True, False, False, False),
    Intersection(False, True, False, False),
    Intersection(True, False, False, False)
]
port = 12345  # Reserve a port for your service.
s.bind(('192.168.1.109', port))  # Bind to the port
print(host)

s.listen(5)  # Now wait for client connection.
while True:
    c, addr = s.accept()  # Establish connection with client.
    print 'Got connection from', addr
    c.send(turnList)
    c.close()
コード例 #10
0
    def bruteForce(self, graph):
        # get a random word to start with
        keys = list(graph.keys())
        randomIndex0 = random.randint(0, len(keys) - 1)
        randomLetter = keys[
            randomIndex0]  # Gives us a list of words from graph[some random letter]
        wordList = graph[randomLetter]
        randomIndex1 = random.randint(0, len(wordList) - 1)
        startWord = wordList[randomIndex1]

        Q = deque(
            []
        )  # initialize a queue that will store each word that has been added to the crossword
        Q.append(startWord)
        allWords = []
        allWords.append(startWord)
        # initialize a crossword that contains that start word
        crossword = CrosswordRepresentation({startWord: None}, {})
        board = Board(crossword)

        # this outer loop continues until we have the desired number of words in our crossword
        currentWordIsAcross = True
        while len(Q) > 0:  # while Q is not empty
            currentWord = Q.popleft(
            )  # removes the first element in the Queue.

            # updates currentWordIsAcross depending on whether or not
            # the current word is in the across or down dictionary keys.
            if currentWord in board.crossword.across.keys():
                currentWordIsAcross = True
            elif currentWord in board.crossword.down.keys():
                currentWordIsAcross = False

            # loops through each letter in the current word and try's to add a word on each letter.
            for x in range(0, len(currentWord), 2):
                neighbors = graph[currentWord[
                    x]]  # list of all words that have the letter of currentWord[x] in them.
                for neighbor in neighbors:  # Searches through all the neighbors for a potentially valid word to add.
                    newWord = neighbor
                    if currentWordIsAcross and newWord not in Q and newWord not in allWords:
                        intersection = Intersection(
                            currentWord, newWord, x,
                            newWord.find(currentWord[x]))
                        # print("Current word: " + currentWord + ", list: " + str(board.crossword.across))
                        firstCell = board.crossword.across[currentWord]
                        interCell = board.getCellAt(firstCell.xCoord + x,
                                                    firstCell.yCoord)
                        if interCell is not None and board.addIfValid(
                                interCell, intersection, False):
                            Q.append(newWord)
                            allWords.append(newWord)
                            board.terminalRepresentationOfCrossword(
                            )  # prints the crossword in the terminal as it is.
                            print("--------------")
                            break  # We don't want to keep looping through all the neighbors if we found a valid one.
                    elif not currentWordIsAcross and newWord not in Q and newWord not in allWords:
                        intersection = Intersection(
                            newWord, currentWord, newWord.find(currentWord[x]),
                            x)
                        # print("Current word: "+currentWord+", list: "+str(board.crossword.down))
                        firstCell = board.crossword.down[currentWord]
                        interCell = board.getCellAt(firstCell.xCoord,
                                                    firstCell.yCoord + x)
                        if interCell is not None and board.addIfValid(
                                interCell, intersection, True):
                            Q.append(newWord)
                            allWords.append(newWord)
                            board.terminalRepresentationOfCrossword(
                            )  # prints the crossword in the terminal as it is.
                            print("--------------")
                            break
        return board
コード例 #11
0
    def my_constructor(self, WORKSPACE_INSTANCE, USER_ID, VIP,
                       AVATAR_VISIBILITY_TABLE, HEADTRACKING_TARGET_NAME,
                       EYE_DISTANCE, NO_TRACKING_MAT):

        self.table_constructor(AVATAR_VISIBILITY_TABLE)

        # flags
        ## @var is_vip
        # Boolean indicating if this user has vip status.
        self.is_vip = VIP

        ## @var is_active
        # Boolean indicating if this user is currently active.
        self.is_active = True

        ## @var eye_distance
        # The eye distance of the user to be applied.
        self.eye_distance = EYE_DISTANCE

        # variables
        ## @var WORKSPACE_INSTANCE
        # Workspace instance at which this user is registered.
        self.WORKSPACE_INSTANCE = WORKSPACE_INSTANCE

        ## @var id
        # Identification number of the user within the workspace, starting from 0.
        self.id = USER_ID

        ## @var headtracking_target_name
        # Name of the headtracking station as registered in daemon.
        self.headtracking_target_name = HEADTRACKING_TARGET_NAME

        ## @var headtracking_reader
        # TrackingTargetReader for the user's glasses.
        if self.headtracking_target_name == None:
            self.headtracking_reader = TrackingDefaultReader()
            self.headtracking_reader.set_no_tracking_matrix(NO_TRACKING_MAT)
        else:
            self.headtracking_reader = TrackingTargetReader()
            self.headtracking_reader.my_constructor(HEADTRACKING_TARGET_NAME)
            self.headtracking_reader.set_transmitter_offset(
                self.WORKSPACE_INSTANCE.transmitter_offset)
            self.headtracking_reader.set_receiver_offset(
                avango.gua.make_identity_mat())

        ## @var user_representations
        # List of UserRepresentation instances for all display groups in the user's workspace.
        self.user_representations = []

        # toggles activity
        self.toggle_user_activity(self.is_active)

        ## @var intersection_tester
        # Instance of Intersection to determine intersection points of user with screens.
        self.intersection_tester = Intersection()
        self.intersection_tester.my_constructor(
            scenegraphs[0], self.headtracking_reader.sf_abs_mat, 5.0,
            "screen_proxy_group", False)
        self.mf_screen_pick_result.connect_from(
            self.intersection_tester.mf_pick_result)

        ## @var last_seen_display_group
        # DisplayGroup instance for which the user's viewing ray lastly hit a screen proxy geometry.
        self.last_seen_display_group = None

        self.always_evaluate(True)