void makeRandomTree (treegen_t* tg, edgefn ef) { resetStack(tg->sp); resetTree(tg->tp); genTree (tg->N, tg->T, tg->sp, tg->tp); writeTree (tg->tp, ef); }
int main(int argc, char** argv){ if(validInput(argc, argv) != 1){ return 0; } char* tree= genTree(atoi(argv[1]), argv[2][0], argv[3][0]); printf("%s", tree); }
ObjectNode* genForest(int numTrees, float minR, float maxR, const mat4& initTrans, const mat4& initSkew) { ObjectNode* forest = new ObjectNode(nullptr, initTrans, initSkew); mat4 rotMat = rY(0.3 * numTrees + 2.0 * M_PI / numTrees); mat4 tempPosit = MatMath::ID; for (int i = 0; i < numTrees; ++i, rotMat *= rotMat) { tempPosit = rotMat * translate(0.0, 0.0, -randNum(minR, maxR)); forest->addChild( *genTree( 3, 2, 150, 0.5, 0.5, 1.6, tempPosit, tempPosit ) ); } return forest; }
binTree_t* genTree(uint32_t* pArray, uint32_t len) { binTree_t* pRoot; binTree_t* pLeft; binTree_t* pRight; uint32_t pRootIndex; if (len == 0) { return NULL; } srand(time(0)); pRootIndex = rand() % len; // printf("random = %d\n", pRootIndex); pRoot = (binTree_t*)malloc(sizeof(binTree_t)); pRoot->value = pArray[pRootIndex]; pRoot->left = genTree(pArray, pRootIndex); pRoot->right = genTree(pArray + pRootIndex + 1, len - pRootIndex - 1); return pRoot; }
int main2() { printf("\n\nSize of node is %zd bytes\n\n", sizeof(Node)); int randSeed = time(NULL); printf("Random Seed: %d\n", randSeed); srand(randSeed); // 3, and 4 are good. 6,7,8 are very good // 10 is excellent srand(10); // generate a random tree printf ("generating random tree of depth %d\n", g_depth); Node root = {0}; START_TIMER genTree(&root, g_depth); STOP_TIMER printf("random tree generated, total nodes: %d, leaf nodes: %d, time: %g ms\n", gTotalNodes, gLeafNodes, gTime); float bestVal = 0; // search the best move using min-max search printf("searching the tree using min-max\n"); START_TIMER bestVal = negaMax(&root, g_depth, g_depth); STOP_TIMER printf ("best move %d, score: %f, time: %g\n", root.bestChild, root.nodeVal, gTime); // search the best move using alpha-beta search printf("searching the tree using alpha-beta\n"); START_TIMER bestVal = alphabeta(&root, g_depth, g_depth, -INF, INF); STOP_TIMER printf ("best move %d, score: %f\nnodes visited (leaves/interior/total): %d/%d/%d\n", root.bestChild, root.nodeVal, gLeafNodesVisited, gInteriorNodesVisited, gLeafNodesVisited + gInteriorNodesVisited); printf("time taken: %g\n", gTime); START_TIMER exploreTree(&root, g_depth); STOP_TIMER printf("time taken: %g\n", gTime); float val; START_TIMER val = SSS_star(&root, g_depth); STOP_TIMER printf("SSS* best node: %d, score: %f, nodes explored: %d, time taken: %g\n", root.bestChild, val, g_sssNodes, gTime); freeTree(&root); getchar(); return 0; }
int main() { for (int i = 0; i < 1000; i++) { int randSeed = i + time(NULL); gTotalNodes = 0; gLeafNodes = 0; gLeafNodesVisited = 0; gInteriorNodesVisited = 0; printf("Random Seed: %d\n", randSeed); srand(randSeed); printf("generating random tree of depth %d\n", g_depth); Node root = { 0 }; START_TIMER genTree(&root, g_depth); STOP_TIMER printf("random tree generated, total nodes: %d, leaf nodes: %d, time: %g ms\n", gTotalNodes, gLeafNodes, gTime); float bestValAB = 0; float bestValET = 0; // search the best move using alpha-beta search printf("searching the tree using alpha-beta\n"); START_TIMER bestValAB = alphabeta(&root, g_depth, g_depth, -INF, INF); STOP_TIMER printf("best move %d, score: %f\nnodes visited (leaves/interior/total): %d/%d/%d\n", root.bestChild, root.nodeVal, gLeafNodesVisited, gInteriorNodesVisited, gLeafNodesVisited + gInteriorNodesVisited); printf("time taken: %g\n", gTime); START_TIMER bestValET = exploreTree(&root, g_depth); STOP_TIMER printf("time taken: %g\n\n\n\n", gTime); if (bestValET != bestValAB) { printf("\n*Mismatch found!*\n"); getchar(); } freeTree(&root); //getchar(); } getchar(); return 0; }
int main(int argc, char *argv[]) { clrscr(); showCredits(); checkUsages(argc); readFromFile(argv[1]); genTree(); openFile2Write(argv[1]); genCode(); closeFile2Write(); printProc("Closing destination file... "); printStatus("DONE",1); printf("\n"); return 0; }
void genTree(Node *root, int depth) { gTotalNodes++; root->frontierOffset = -1; root->numChildrenAtFrontier = 0; if (g_depth % 2 == 0) { // even depths are maximizing nodes root->isMaxNode = !(depth % 2); } else { root->isMaxNode = !!(depth % 2); } if (depth == 0) { gLeafNodes++; // generate random node val (between 0 and 100) and return root->nodeVal = (rand() % 10000) / 100.0f; return; } // allocate memory for random number of children (have at least one children for now - to be changed later!) int nChildren = rand() % MAX_CHILDREN + 1; Node *children = (Node *) malloc (nChildren * sizeof(Node)); for (int i=0; i<nChildren; i++) { children[i].nChildsExplored = 0; children[i].nChildren = 0; children[i].children = NULL; children[i].nodeVal = 0.0f; children[i].parent = root; genTree (&children[i], depth - 1); } root->nChildren = nChildren; root->children = children; root->nChildsExplored = 0; }