Esempio n. 1
0
def main():
	
	#Open files
	activision = open("activision.txt", "r")
	vivendi = open("vivendi.txt", "r")
	
	head = Node()
	total = 0;
	#Read lines and create LL
	if activision.mode == "r":
		f1 = activision.readlines()
		
		for x in f1:
			head.add(int(x))
	
	if vivendi.mode == "r":
		f2 = vivendi.readlines()
		for x in f2:
			head.add(int(x))
			
	head = head.next
	
	'''''''''''''''''''''''''''
	Each solution returns a set to make it easier to compare
	the results to one another.
	To check a solution, uncomment the method call below and
	replace the appropriate variables inside the print statement
	'''''''''''''''''''''''''''
Esempio n. 2
0
 def create():
     top_node = Node('top')
     cube_mesh = load("Objects/cube/cube.obj")[0]
     cube_node = Node("cube1");
     cube_node.add(cube_mesh)
     top_node.add(cube_node)
     return top_node
Esempio n. 3
0
class Tree(object):
    """docstring for Tree"""
    def __init__(self):
        self.arg = arg
        self.root = Node()

    def insert(selfvalue):
        self.root.add(value)

    def preOrderTraversal(self):
        return self.root.preOrderTraversal()

    def inOrderTraversal(self):
        return self.root.inOrderTraversal()

    def postOrderTraversal(self):
        return self.root.postOrderTraversal()

    def breadthFirst(self):
        stack = []
        order = []
        stack.append(self.root)
        for node in stack:
            stack.append(node.left)
            stack.append(node.right)
            order.append(node.getValue())
        return order

    def __str__():
        pass
Esempio n. 4
0
    def create(self):
        top_node = Node('top')
        # mesh_trex = load_textured("Objects/trex/trex.obj")[0]
        # trex_one = Node("trex_one", children=[mesh_trex])
        # self.elevate(trex_one)

        trex_player = Node('player_node', children=[self.dino_moving("player")])
        trex_player.scale_total(10)
        self.elevate(trex_player)
        top_node.add(self.skybox(), self.terrain, self.tree(), self.rochers(), self.asteroids(),self.trex(), trex_player, self.gate())
        return top_node
Esempio n. 5
0
 def generate_nodes(self, mesh, number, rotation_max=360, axis_rotation=(0, 1, 0), axis_translation=(1, 0, 1)):
     """
         Generate all leaf nodes
         rotation_max = rotation max possible on the axes
         axis_rotation = axe of rotation, ex (0, 1, 0) = only on y
         axis_translation = axe of translation, ex (1, 0, 1) = for humans
     """
     nodes = []
     for i in range(number):
         node = Node('')
         node.add(mesh)
         self.randomize_creation(node, rotation_max, axis_rotation, axis_translation)
         nodes.append(node)
     return nodes
Esempio n. 6
0
    def asteroids(self):
        mesh_rocher = Rocher(self.light_direction, color=[0.8,0.2,0.2])
        node = Node("LaFinDuMonde")
        for i in range(4):
            oneNode = Node('', children=[mesh_rocher])
            oneNode.scale_total(20)
            oneNode.translate(0,100+randint(0,5),0)
            self.randomize_creation(oneNode, rotation_max=360, axis_rotation=(0, 1, 0), axis_translation=(1, 1, 1))

            translate_keys = {0: vec(0, 1000, 0), 4: vec(0, -800, 0)}
            rotate_keys = {0: quaternion(), 57: quaternion()}
            scale_keys = {0: 1,7:1}
            keynode = KeyFrameControlNode(translate_keys, rotate_keys, scale_keys, resetTime=6)
            keynode.add(oneNode)
            node.add(keynode)
        return node
Esempio n. 7
0
class KDtree:
    def __init__(self):
        self.root = None

    def insert(self, point):
        if (self.root == None):
            self.root = Node(None,None,point,0,None,0)
        else:
            self.root.add(point)

    def search(self, tl, br):
        rec = Rectangle(tl,br)
        if self.root == None:
            print("Empty tree")
        else:
            show = self.root.r_search(rec)
            for i in show:
                print(i.x,"|",i.y)
Esempio n. 8
0
class Tree:
    root = None


    def __init__(self):
        pass


    def add(self, data):
        if self.root is None:
            self.root = Node(data)
        else:
            self.root.add(data)
        
    def print(self):
        if self.root is None:
            print("The tree is empty!")
        else:
            self.root.print()
Esempio n. 9
0
    def set_root(self, root):
        self.root = root



def function(number):
    print number


if __name__ == '__main__':
    root = Node(function, 1)
    node2 = Node(function, 2)
    node21 = Node(function, 21)
    node22 = Node(function, 22)

    node2.add(node21)
    node2.add(node22)

    node3 = Node(function, 3)
    node31 = Node(function, 31)
    node41 = Node(function, 41)

    node3.add(node31)
    node31.add(node41)

    root.add(node2)
    root.add(node3)

    tree = BinaryTree(root)
    tree.postfix(tree.get_root())
Esempio n. 10
0
	def insertMain(self, subtree, key, value):
		if subtree.type == 'leafType':
			if subtree.hasSpace():
				# add it to the leaf node directly
				subtree.add(key, value)
				return None
			else:
				# split the leaf node
				subtree.add(key,value)
				newNode1 = Node(self.nodeSize, 'leafType')
				newNode2 = Node(self.nodeSize, 'leafType')
				keyList = subtree.keyList
				pointerList = subtree.pointerList
				# entries to move to the left and right node
				nodesForLeft = math.floor(len(subtree.keyList) / 2.0)
				nodesForRight = len(subtree.keyList) - nodesForLeft
				counter = 0
				for i in range(len(subtree.keyList)):
					if i < nodesForLeft:
						newNode1.add(keyList[i], pointerList[i])
					else:
						newNode2.add(keyList[i], pointerList[i])
				if subtree is self.root:
					newRoot = Node(self.nodeSize, 'rootType')
					newRoot.add(newNode2.keyList[0], newNode1)
					newRoot.pointerList.append(newNode2)
					self.root = newRoot
				return (newNode2.keyList[0], newNode2, newNode1)
		else: 
			# i is the subtree to insert K into
			for sub in range(len(subtree.keyList)):
				if subtree.keyList[sub] > key:
					i = subtree.pointerList[sub]
					break
				else:
					i = subtree.pointerList[sub + 1]
			newEntry = self.insertMain(i, key, value)

			if newEntry == None:
				# child was not split, so nothing to do here
				return None
			else:
				# if there is space in this subtree
				if subtree.hasSpace():
					subtree.addSubtree(newEntry[0], newEntry[1], newEntry[2])
					return None
				else:
					# split this subtree
					subtree.addSubtree(newEntry[0], newEntry[1], newEntry[2])
					subtree1 = Node(self.nodeSize, 'rootType')
					subtree2 = Node(self.nodeSize, 'rootType')
					nodesForLeft = int(math.floor( (len(subtree.keyList) - 1) / 2.0))
					nodesForRight = int(len(subtree.keyList) - nodesForLeft- 1 )
					subtree1.keyList = [None] * nodesForLeft
					subtree1.pointerList = [None] * (nodesForLeft + 1)
					subtree2.keyList = [None] * nodesForRight
					subtree2.pointerList = [None] * (nodesForRight + 1)
					keyToMove = subtree.keyList[nodesForLeft]

					for a in range(int(nodesForLeft)):
						subtree1.keyList[a] = subtree.keyList[a]
						subtree1.pointerList[a] = subtree.pointerList[a]
					subtree1.pointerList[nodesForLeft] = subtree.pointerList[nodesForLeft]

					for a in range(nodesForRight):
						subtree2.keyList[a] = subtree.keyList[a + nodesForLeft + 1]
						subtree2.pointerList[a] = subtree.pointerList[a + nodesForLeft + 1]
					subtree2.pointerList[nodesForRight] = subtree.pointerList[len(subtree.keyList)]
					newEntry = (keyToMove, subtree2, subtree1)
					if subtree is self.root:
						newNode = Node(self.nodeSize, 'rootType')
						newNode.add(keyToMove, subtree1)
						newNode.pointerList.append(subtree2)
						self.root = newNode
					return newEntry
Esempio n. 11
0
    def insertMain(self, subtree, key, value):
        if subtree.type == 'leafType':
            if subtree.hasSpace():
                # add it to the leaf node directly
                subtree.add(key, value)
                return None
            else:
                # split the leaf node
                subtree.add(key, value)
                newNode1 = Node(self.nodeSize, 'leafType')
                newNode2 = Node(self.nodeSize, 'leafType')
                keyList = subtree.keyList
                pointerList = subtree.pointerList
                # entries to move to the left and right node
                nodesForLeft = math.floor(len(subtree.keyList) / 2.0)
                nodesForRight = len(subtree.keyList) - nodesForLeft
                counter = 0
                for i in range(len(subtree.keyList)):
                    if i < nodesForLeft:
                        newNode1.add(keyList[i], pointerList[i])
                    else:
                        newNode2.add(keyList[i], pointerList[i])
                if subtree is self.root:
                    newRoot = Node(self.nodeSize, 'rootType')
                    newRoot.add(newNode2.keyList[0], newNode1)
                    newRoot.pointerList.append(newNode2)
                    self.root = newRoot
                return (newNode2.keyList[0], newNode2, newNode1)
        else:
            # i is the subtree to insert K into
            for sub in range(len(subtree.keyList)):
                if subtree.keyList[sub] > key:
                    i = subtree.pointerList[sub]
                    break
                else:
                    i = subtree.pointerList[sub + 1]
            newEntry = self.insertMain(i, key, value)

            if newEntry == None:
                # child was not split, so nothing to do here
                return None
            else:
                # if there is space in this subtree
                if subtree.hasSpace():
                    subtree.addSubtree(newEntry[0], newEntry[1], newEntry[2])
                    return None
                else:
                    # split this subtree
                    subtree.addSubtree(newEntry[0], newEntry[1], newEntry[2])
                    subtree1 = Node(self.nodeSize, 'rootType')
                    subtree2 = Node(self.nodeSize, 'rootType')
                    nodesForLeft = int(
                        math.floor((len(subtree.keyList) - 1) / 2.0))
                    nodesForRight = int(
                        len(subtree.keyList) - nodesForLeft - 1)
                    subtree1.keyList = [None] * nodesForLeft
                    subtree1.pointerList = [None] * (nodesForLeft + 1)
                    subtree2.keyList = [None] * nodesForRight
                    subtree2.pointerList = [None] * (nodesForRight + 1)
                    keyToMove = subtree.keyList[nodesForLeft]

                    for a in range(int(nodesForLeft)):
                        subtree1.keyList[a] = subtree.keyList[a]
                        subtree1.pointerList[a] = subtree.pointerList[a]
                    subtree1.pointerList[nodesForLeft] = subtree.pointerList[
                        nodesForLeft]

                    for a in range(nodesForRight):
                        subtree2.keyList[a] = subtree.keyList[a +
                                                              nodesForLeft + 1]
                        subtree2.pointerList[a] = subtree.pointerList[
                            a + nodesForLeft + 1]
                    subtree2.pointerList[nodesForRight] = subtree.pointerList[
                        len(subtree.keyList)]
                    newEntry = (keyToMove, subtree2, subtree1)
                    if subtree is self.root:
                        newNode = Node(self.nodeSize, 'rootType')
                        newNode.add(keyToMove, subtree1)
                        newNode.pointerList.append(subtree2)
                        self.root = newNode
                    return newEntry