/* valid input: (DrawPen r g b m) (DrawPen (r g b m)) */ le * eval_gfx_DrawPen ( lithp_burrito * lb, const int argc, le * branch ) { int r,g,b; int ac; le *mono, *result; if( !lb || !branch || (argc != 5 && argc != 2) ) return( leNew( "NIL" )); if( argc == 5 ) { mono = eval_getint_3( lb, branch, &r, &g, &b ); result = evaluateNode( lb, mono ); } else { result = evaluateNode( lb, branch->list_next ); ac = countNodes( result ); if( ac != 4 ) return( leNew( "NIL" )); mono = eval_getint_3_noskip( lb, result, &r, &g, &b ); } lb->pen1 = eval_make_color( lb, r, g, b, result->data ); return( leNew( "T" )); }
le * eval_cb_cons( lithp_burrito * lb, const int argc, le * branch ) { le * result1 = NULL; le * result2 = NULL; if (!branch || argc != 3 ) return( leNew( "NIL" )); result1 = evaluateNode(lb, branch->list_next); if ( result1 == NULL ) return( leNew( "NIL" )); result2 = evaluateNode(lb, branch->list_next->list_next); if ( result2 == NULL ) { leWipe( result1 ); return( leNew( "NIL" )); } if ( countNodes(result1) > 1 ) { le * temp = leNew( NULL ); temp->branch = result1; result1 = temp; } result1->list_next = result2; result2->list_prev = result1; return( result1 ); }
le * eval_cb_whenunless_helper( enum whenunless which, lithp_burrito * lb, const int argc, le * branch ) { le * retval = NULL; le * trythis = NULL; if (!branch || argc < 3 ) return( leNew( "NIL" )); /* conditional */ retval = evaluateNode(lb, branch->list_next); if ( which == WU_UNLESS ) { /* unless - it wasn't true... bail */ if ( strcmp( retval->data, "NIL" )) { leWipe( retval ); return( leNew( "NIL" ) ); } } else { /* when: it wasn't false... bail */ if ( !strcmp( retval->data, "NIL" )) return( retval ); } trythis = branch->list_next->list_next; while( trythis ) { if (retval) leWipe( retval ); retval = evaluateNode(lb, trythis); trythis = trythis->list_next; } return( retval ); }
le * eval_cb_select( lithp_burrito * lb, const int argc, le * branch ) { le * result; if (argc < 2) return( leNew( "NIL" )); branch = branch->list_next; result = evaluateNode(lb, branch); branch = branch->list_next; while( branch ) { if( branch->branch ) { le * check = branch->branch; if (check && check->data && (!strcmp( check->data, result->data ))) { /* we're in the right place, evaluate and return */ le * computelist = check->list_next; while( computelist ) { leWipe( result ); result = evaluateNode( lb, computelist ); computelist = computelist->list_next; } return( result ); } } branch = branch->list_next; } return( result ); }
static le * eval_getint_2( lithp_burrito *lb, le * branch, int *a, int *b ) { le * retle = evaluateNode( lb, branch->list_next ); *a = evalCastLeToInt( retle ); leWipe( retle ); retle = evaluateNode( lb, branch->list_next->list_next ); *b = evalCastLeToInt( retle ); leWipe( retle ); return( branch->list_next->list_next->list_next ); }
static le * eval_getint_3_noskip( lithp_burrito *lb, le * node, int *a, int *b, int *c ) { le * retle = evaluateNode( lb, node ); *a = evalCastLeToInt( retle ); leWipe( retle ); retle = evaluateNode( lb, node->list_next ); *b = evalCastLeToInt( retle ); leWipe( retle ); retle = evaluateNode( lb, node->list_next->list_next ); *c = evalCastLeToInt( retle ); leWipe( retle ); return( node->list_next->list_next->list_next ); }
bool IDAStar::findPath(Metrics& metrics) { float g = 0.0f; _nrOfPathNodes = 0; //It's 1 because there's an offset in the loop later. Vec2D currentPos = _start; float threshold = getHeuristicDistance(_start, _goal); while (currentPos != _goal) { currentPos = evaluateNode(_start, 0.0f, threshold); threshold = _grid[currentPos._x][currentPos._y]._gCost + getHeuristicDistance(currentPos, _goal); if (threshold >= _width * _height || !isPositionValid(currentPos)) { return false; } } while (currentPos != _start) //traces the route back to start { _nrOfPathNodes++; currentPos = _grid[currentPos._x][currentPos._y]._parent->_position; } _path = new Vec2D[_nrOfPathNodes]; int c = 0; currentPos = _goal; while (currentPos != _start) //traces the route back to start { _path[c++] = currentPos; currentPos = _grid[currentPos._x][currentPos._y]._parent->_position; } metrics.setPathNodes(_path, _nrOfPathNodes, _grid[_goal._x][_goal._y]._gCost); return true; }
le * eval_cb_car( lithp_burrito * lb, const int argc, le * branch ) { le * result = NULL; le * temp = NULL; if (!branch || argc != 2 ) return( leNew( "NIL" )); result = evaluateNode(lb, branch->list_next); if( result == NULL ) return( leNew( "NIL" ) ); if (countNodes(result) <= 1) { if (result->branch) { temp = result; result = result->branch; temp->branch = NULL; leWipe( temp ); } return( result ); } result->list_next->list_prev = NULL; leWipe( result->list_next ); result->list_next = NULL; if (result->branch) { temp = result; result = result->branch; temp->branch = NULL; leWipe( temp ); } return( result ); }
le * eval_cb_prog( lithp_burrito * lb, const int argc, le * branch, int returnit ) { le * curr; le * retval = NULL; le * tempval = NULL; int current = 0; if (!branch || argc < (returnit +1) ) return( leNew( "NIL" )); curr = branch->list_next; while (curr) { ++current; if ( tempval ) leWipe (tempval); tempval = evaluateNode( lb, curr ); if (current == returnit) retval = leDup( tempval ); curr = curr->list_next; } if (!retval) retval = tempval; return( retval ); }
le * evaluateBranch( lithp_burrito *lb, le * trybranch) { le * keyword; int tryit = 0; if (!trybranch) return( NULL ); if (trybranch->branch) { keyword = evaluateBranch(lb, trybranch->branch); } else keyword = leNew( trybranch->data ); if (!keyword->data) { leWipe( keyword ); return( leNew( "NIL" )); } for ( tryit=0 ; evalTable[tryit].word ; tryit++) { if (!strcmp(evalTable[tryit].word, keyword->data)) { leWipe( keyword ); return( evalTable[tryit].callback( lb, countNodes( trybranch ), trybranch) ); } } leWipe( keyword ); return( evaluateNode( lb, trybranch )); }
le * eval_cb_eqsign( lithp_burrito * lb, const int argc, le * branch ) { le * letemp; int value1, value2; if (!branch || argc != 3 ) return( leNew( "NIL" ) ); letemp = evaluateNode( lb, branch->list_next ); value1 = evalCastLeToInt( letemp ); leWipe( letemp ); letemp = evaluateNode( lb, branch->list_next->list_next ); value2 = evalCastLeToInt( letemp ); leWipe( letemp ); return( leNew ( (value1 == value2 )?"T":"NIL" ) ); }
le * eval_cb_modulus( lithp_burrito * lb, const int argc, le * branch ) { le * letemp; int value1, value2; if (!branch || argc != 3) return( leNew( "NIL" ) ); letemp = evaluateNode( lb, branch->list_next ); value1 = evalCastLeToInt( letemp ); leWipe( letemp ); letemp = evaluateNode( lb, branch->list_next->list_next ); value2 = evalCastLeToInt( letemp ); leWipe( letemp ); return( evalCastIntToLe ( value1 % value2 ) ); }
le * eval_cb_equal( lithp_burrito * lb, const int argc, le * branch ) { le * list1 = NULL; le * list2 = NULL; int retval = 0; if (!branch || argc != 3 ) return( leNew( "NIL" ) ); list1 = evaluateNode( lb, branch->list_next ); list2 = evaluateNode( lb, branch->list_next->list_next ); retval = eval_cb_lists_same( list1, list2 ); leWipe( list1 ); leWipe( list2 ); return( leNew ( (retval == 1) ? "T" : "NIL" ) ); }
le * evaluateDefun( lithp_burrito *lb, le * fcn, le * params ) { le * function; le * thisparam; le * result; int count; /* make sure both lists exist */ if (!fcn) return( leNew( "NIL" )); /* check for the correct number of parameters */ if (countNodes(fcn->branch) > countNodes(params)) return( leNew( "NIL" )); /* allocate another function definition, since we're gonna hack it */ function = leDup(fcn); /* pass 1: tag each node properly. for each parameter: (fcn) - look for it in the tree, tag those with the value */ count = 0; thisparam = fcn->branch; while (thisparam) { leTagData(function, thisparam->data, count); thisparam = thisparam->list_next; count++; } /* pass 2: replace for each parameter: (param) - evaluate the passed in value - replace it in the tree */ count = 0; thisparam = params; while (thisparam) { result = evaluateNode( lb, thisparam ); leTagReplace(function, count, result); thisparam = thisparam->list_next; leWipe(result); count++; } /* then evaluate the resulting tree */ result = evaluateBranch( lb, function->list_next ); /* free any space allocated */ leWipe( function ); /* return the evaluation */ return( result ); }
le * eval_gfx_DrawPen2 ( lithp_burrito * lb, const int argc, le * branch ) { int r,g,b; le *mono, *result; if( !lb || !branch || argc != 5 ) return( leNew( "NIL" )); mono = eval_getint_3( lb, branch, &r, &g, &b ); result = evaluateNode( lb, mono ); lb->pen1 = eval_make_color( lb, r, g, b, result->data ); return( leNew( "T" )); }
le * eval_cb_eval( lithp_burrito * lb, const int argc, le * branch ) { le * temp; le * retval; if (!branch || argc != 2 ) return( leNew( "NIL" )); temp = evaluateNode(lb, branch->list_next); retval = evaluateBranch(lb, temp); leWipe( temp ); return( retval ); }
le * eval_gfx_DrawVectorTextCentered ( lithp_burrito * lb, const int argc, le * branch ) { int x,y,w,h; le *t, *t2; if( !lb || !branch || argc < 6 ) return( leNew( "NIL" )); t = eval_getint_4( lb, branch, &x, &y, &w, &h ); t2 = evaluateNode( lb, t ); pz_vector_string_center( lb->srf, t2->data, x, y, w, h, 1, lb->pen1 ); return( leNew( "T" )); }
le * eval_cb_atom( lithp_burrito * lb, const int argc, le * branch ) { le * result = NULL; if (!branch || argc != 2 ) return( leNew( "NIL" )); result = evaluateNode( lb, branch->list_next ); if (countNodes(result) == 1) { leWipe( result ); return( leNew( "T" ) ); } return( leNew( "NIL" ) ); }
le * eval_cb_oneplus( lithp_burrito * lb, const int argc, le * branch ) { le * retle; int value; if (!branch || argc < 2) return( leNew( "NIL" ) ); retle = evaluateNode( lb, branch->list_next ); value = evalCastLeToInt( retle ); leWipe( retle ); return( evalCastIntToLe(value + 1) ); }
le * eval_cb_if( lithp_burrito * lb, const int argc, le * branch ) { le * retcond = NULL; if (!branch || argc < 3 || argc > 4) return( leNew( "NIL" )); /* if */ retcond = evaluateNode(lb, branch->list_next); if (!strcmp ( retcond->data, "NIL" )) { if (argc == 3) /* no else */ return( retcond ); leWipe( retcond ); return( evaluateNode( lb, branch->list_next->list_next->list_next ) ); } /* then */ leWipe( retcond ); return( evaluateNode(lb, branch->list_next->list_next) ); }
le * eval_cb_set_helper( enum setfcn function, lithp_burrito * lb, const int argc, le * branch ) { le * newkey = NULL; le * newvalue = NULL; le * current = NULL; if (!branch || argc < 3) return( leNew( "NIL" ) ); current = branch->list_next; while ( current ) { if (!current->list_next) { newvalue = leNew( "NIL" ); } else { newvalue = evaluateNode(lb, current->list_next); } if ( function == S_SET ) newkey = evaluateNode(lb, current); lb->mainVarList = variableSet( lb->mainVarList, ( function == S_SET )? newkey->data : current->data, newvalue ); if ( function == S_SET ) leWipe(newkey); if (!current->list_next) { current = NULL; } else { current = current->list_next->list_next; } } return( leDup(newvalue) ); }
void Lithp_callDefun( lithp_burrito *lb, char * fname ) { le * ret; le * fcn; le * temp = variableGet( lb->defunList, fname ); if( !temp ) return; fcn = leNew( fname ); ret = evaluateNode( lb, fcn ); leWipe( ret ); leWipe( fcn ); }
le * eval_cb_divide( lithp_burrito * lb, const int argc, le * branch ) { int firstitem = 0; le * lefirst; if (!branch || argc < 2) return( leNew( "NIL" ) ); lefirst = evaluateNode( lb, branch->list_next ); firstitem = evalCastLeToInt( lefirst ); leWipe( lefirst ); return( evalCastIntToLe( eval_cume_helper( C_DIVIDE, lb, firstitem, branch->list_next->list_next))); }
le * eval_cb_cond( lithp_burrito * lb, const int argc, le * branch ) { le * retval = NULL; le * retblock = NULL; le * trythis = NULL; le * tryblock = NULL; int newargc; if (!branch || argc < 2 ) return( leNew( "NIL" )); trythis = branch->list_next; while (trythis) { newargc = countNodes( trythis->branch ); if (newargc == 0) continue; /* conditional */ if (retval) leWipe(retval); retval = evaluateNode(lb, trythis->branch); if ( strcmp(retval->data, "NIL" )) { if (newargc == 1) return( retval ); tryblock = trythis->branch->list_next; while (tryblock) { if (retblock) leWipe(retblock); retblock = NULL; retblock = evaluateNode(lb, tryblock); tryblock = tryblock->list_next; } return( retblock ); } trythis = trythis->list_next; } return( retval ); }
le * eval_gfx_Rand ( lithp_burrito * lb, const int argc, le * branch ) { le * retle; int value; int r; if (!branch || argc != 2) return( leNew( "NIL" ) ); retle = evaluateNode( lb, branch->list_next ); value = evalCastLeToInt( retle ); leWipe( retle ); r = (int)((float)value * rand() / (RAND_MAX + 1.0)); return( evalCastIntToLe( r ) ); }
le * eval_cb_princ( lithp_burrito * lb, const int argc, le * branch ) { le * thisnode; le * retblock = NULL; if (!branch || argc < 1 ) return( leNew( "NIL" )); thisnode = branch->list_next; while (thisnode) { if (retblock) leWipe( retblock ); retblock = evaluateNode(lb, thisnode); leDumpReformat(stdout, retblock); thisnode = thisnode->list_next; } return( retblock ); }
le * eval_cb_subtract( lithp_burrito * lb, const int argc, le * branch ) { int firstitem = 0; le * lefirst; if (!branch || argc < 2) return( leNew( "NIL" ) ); lefirst = evaluateNode( lb, branch->list_next ); firstitem = evalCastLeToInt( lefirst ); leWipe( lefirst ); if (argc == 2) { return( evalCastIntToLe( -1 * firstitem) ); } return( evalCastIntToLe( eval_cume_helper( C_SUBTRACT, lb, firstitem, branch->list_next->list_next))); }
Vec2D IDAStar::evaluateNode(Vec2D pos, float g, float threshold) { _grid[pos._x][pos._y]._gCost = g; if (pos == _goal || (g + getHeuristicDistance(pos, _goal)) > threshold ) { return pos; } Vec2D minPos = {-1, -1}; float minValue = -1.0f; for (int i = 0; i < 8 && (_heuristicType != MANHATTAN || i < 4); i++) //Manhattan skips diagonals { Vec2D checkedPos = pos + NEIGHBOUR_OFFSETS[i]; if ((_grid[pos._x][pos._y]._parent == nullptr || checkedPos != _grid[pos._x][pos._y]._parent->_position) && isPositionValid(checkedPos) && _grid[checkedPos._x][checkedPos._y]._traversable) { Vec2D foundPos = {-1, -1}; float tileDist = 1; if (i >= 4) { tileDist = SQRT2; } if (_grid[checkedPos._x][checkedPos._y]._gCost <= 0 || (g + tileDist) <= _grid[checkedPos._x][checkedPos._y]._gCost) { _grid[checkedPos._x][checkedPos._y]._parent = &_grid[pos._x][pos._y]; foundPos = evaluateNode(checkedPos, g + tileDist, threshold); } if (isPositionValid(foundPos)) { if (foundPos == _goal) { return foundPos; } float foundValue = _grid[foundPos._x][foundPos._y]._gCost + getHeuristicDistance(foundPos, _goal); if ((foundValue < minValue || minValue < 0) || (abs(minValue - foundValue) < 0.0001f && _grid[minPos._x][minPos._y]._gCost < _grid[foundPos._x][foundPos._y]._gCost)) { minValue = foundValue; minPos = foundPos; } } } } return minPos; }
QVector<QVector<QPair<int, int>>> SearchingTree::searchValidCorr() { QVector<QVector<QPair<int, int>>> candidates; //Expand tree while (1) { SearchingNode * LastOne = sTree[sTree.size() - 1]; if (LastOne->VolumeProportion > volumeThreshold) { evaluateNode(LastOne); if (LastOne->energy < energyThreshold) candidates.push_back(LastOne->corr); else LastOne->valid = false; } if (LastOne->currentPair.second < totalB - 1 && expandBranch(LastOne)) { continue; } if (LastOne->currentPair.first < totalA - 1) { if (LastOne->parent != NULL) { if (LastOne->parent->next != NULL) { expandChild(LastOne->parent->next); continue; } } SearchingNode * parent = LastOne->pre; if (parent == NULL) break; while (parent->pre != NULL) parent = parent->pre; expandChild(parent); continue; } } return candidates; }
le * eval_cb_or( lithp_burrito * lb, const int argc, le * branch ) { le * temp; le * result = NULL; if (!branch || argc < 2 ) return( leNew( "NIL" )); temp = branch->list_next; while( temp ) { if( result ) leWipe( result ); result = evaluateNode(lb, temp); if (result->data) { if (strcmp ( result->data, "NIL" )) { return( result ); } } temp = temp->list_next; } return( result ); }