Exemple #1
0
DecisionTreeNode* addNodeToTree(DecisionTreeNode* root, DecisionTreeNode* newNode)
{
    
    
    //create new node and return
	if(root == NULL)
	{
		newNode->left = NULL;
		newNode->right = NULL;
		return newNode; 
	}
	//insert to the right
	if( newNode->healthCeiling > root->healthCeiling)
	{
	    //recursion till base case
		root->right = addNodeToTree(root->right, newNode);
		return root;
	}
	//insert to the left
	if(newNode->healthCeiling < root->healthCeiling)
	{
	    //recursion again
		root->left = addNodeToTree(root->left, newNode);
		return root;
	}
    return root;
}
Exemple #2
0
Boss* loadBoss()
{
    FILE* fp = fopen("Boss.txt","r");
    if(fp == NULL)
    {
        printf("The file is wonky");
        return NULL;
    }
    
    //INITIALIZE THE BOSS
    Boss* theboss = malloc(sizeof(Boss)); //currently listening exclusively to bruce springsteen
    //scan in values from first line
    fscanf(fp, "%s | %d | %d | %d | %d", 
    theboss->name , &theboss->maxHealth , &theboss->baseDefense,
    &theboss->baseAttack, &theboss->baseSpeed);
    theboss->health = theboss->maxHealth;
    theboss->root = NULL;
    
    
    DecisionTreeNode* root = NULL;
    int numActions;
    //iterates through each tree node of the file
    while(1)
    {
        if(feof(fp)) break;
        
        numActions = 0;
        
        
        
        //INITIALIZE TREENODE
        DecisionTreeNode* newNode = malloc(sizeof(DecisionTreeNode));
        newNode->left = NULL;
        newNode->right = NULL;
        //scan your values into your new tree node
        fscanf(fp, "%d | %d | %d", &newNode->healthFloor, &newNode->healthCeiling, &numActions);
        
        newNode->FirstAction = NULL;
        
        //then attach a queue to your new tree node
        int i;
        for(i=0;i<numActions;i++)
        {
            //create space for a new queue node
            ActionNode* newANode = (ActionNode*)malloc(sizeof(ActionNode));
            //scan the data in from the file
            fscanf(fp, "%u", &newANode->decision );
            //put the node in its rightful place in the queue
            newNode->FirstAction = addActionToList(newNode->FirstAction, newANode);
        }
        
        //then put your tree node(with queue already attached) into a BST
        root = addNodeToTree(root, newNode);
        
    }
    //now you attach your bst to your boss
    theboss->root = root;
    return theboss;
}
Exemple #3
0
/**
* add node
* @param value an float.
* @return void
*/
void BinaryTree::addNode(float value)
{
	if (isEmpty())
	{
		firstAdd(value);
	}
	else 
	{
		addNodeToTree(value);
	}
}
Tree* findLeaf(Tree *parent, char curChar) {
    Tree* retValue = findNode(parent, curChar, &isCharLeaf);
    
    if (retValue == NULL) {
        Function* newFunction = calloc(FUNCTION_SIZE, 1);
        newFunction->character = curChar;
        return addNodeToTree(parent, newFunction);
    }
    
    return retValue;
}
Exemple #5
0
RRT::RRT(rw::common::Ptr<RRTNode> node){
	addNodeToTree(node);
}