int executeCutCPU(SDL_Renderer *ren, Board *B){ if (determineWinner(B)) return 1; // Nothing to do int i, j; minmaxImplementation(B, &i, &j, minMaxDepth, 1); // Estimate position of desired I and J starting with Cut // The rest is the same as in Basic Execute Cut B->edges[i][j] = noArc; B->edges[j][i] = noArc; eraseArc(ren, B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y); if (B->Vertices[findIndex(B, i)].locked > 0){ endNode(ren, B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y); } else{ drawNode(ren, B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y); } if (B->Vertices[findIndex(B, j)].locked > 0){ endNode(ren, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y); } else{ drawNode(ren, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y); } //the next two lines rotate the turn display...you should not need to chagne this stringColor(ren, 5, 5, "Cut's Turn:", white); stringColor(ren, 5, 5, "Short's Turn:", black); return 1; }
Graph Scene::buildGraph() const { Graph g; for (auto item : items()) { auto node = dynamic_cast<Node *>(item); if (node) { GraphNode graphNode; graphNode.index = node->index(); graphNode.weight = node->number(); g.addNode(graphNode); } } for (auto item : items()) { auto edge = dynamic_cast<Edge *>(item); if (edge) { auto &startGraphNode = g[edge->startNode()->index()]; auto &endGraphNode = g[edge->endNode()->index()]; if (startGraphNode.index != 0 && endGraphNode.index != 0) { endGraphNode.addParent(startGraphNode.index); } } } return g; }
bool Connection::areInspectorsValid() const { return areNodesValid() && gscene()->getInspector(startNode()) && (drag_state != CONNECTED || gscene()->getInspector(endNode())); }
/** * Call this to start a new PRE block. See bug 86355 for why this * makes some pages much faster. */ void CViewSourceHTML::StartNewPreBlock(void){ CEndToken endToken(eHTMLTag_pre); nsCParserNode endNode(&endToken, 0/*stack token*/); mSink->CloseContainer(eHTMLTag_pre); nsTokenAllocator* theAllocator = mTokenizer->GetTokenAllocator(); if (!theAllocator) { return; } CStartToken* theToken = static_cast<CStartToken*> (theAllocator->CreateTokenOfType(eToken_start, eHTMLTag_pre, NS_LITERAL_STRING("PRE"))); if (!theToken) { return; } nsCParserStartNode startNode(theToken, theAllocator); AddAttrToNode(startNode, theAllocator, NS_LITERAL_STRING("id"), NS_ConvertASCIItoUTF16(nsPrintfCString("line%d", mLineNumber))); mSink->OpenContainer(startNode); IF_FREE(theToken, theAllocator); #ifdef DUMP_TO_FILE if (gDumpFile) { fprintf(gDumpFile, "</pre>\n"); fprintf(gDumpFile, "<pre id=\"line%d\">\n", mLineNumber); } #endif // DUMP_TO_FILE mTokenCount = 0; }
std::vector<LineStringEntity*> LineStringEntity::getLineNeighboursDegree2() { std::vector<LineStringEntity*> vNeighbours; int StartDegree=startNode()->getDegree(); int EndDegree=endNode()->getDegree(); computeNeighbours(); if (StartDegree<=2) { std::vector<LineStringEntity*> vUpNeighbours; vUpNeighbours= getLineOrientUpNeighbours(); vNeighbours.insert (vNeighbours.end(),vUpNeighbours.begin(),vUpNeighbours.end()); } if (EndDegree<=2) { std::vector<LineStringEntity*> vDownNeighbours; vDownNeighbours=getLineOrientDownNeighbours(); vNeighbours.insert (vNeighbours.end(),vDownNeighbours.begin(),vDownNeighbours.end()); } return vNeighbours; }
void LineStringEntity::computeNeighbours() { delete mp_Neighbours; mp_Neighbours = new std::set<LandREntity*>; geos::planargraph::DirectedEdgeStar* UpStar = startNode()->getOutEdges(); geos::planargraph::DirectedEdgeStar* DownStar = endNode()->getOutEdges(); std::vector<geos::planargraph::DirectedEdge*>::iterator it=UpStar->iterator(); std::vector<geos::planargraph::DirectedEdge*>::iterator ite=UpStar->end(); for (; it != ite; ++it) { LandREntity* Ent = dynamic_cast<LandREntity*>((*it)->getEdge()); if (Ent != this) mp_Neighbours->insert(Ent); } it = DownStar->iterator(); ite = DownStar->end(); for (; it != ite; ++it) { LandREntity* Ent = dynamic_cast<LandREntity*>((*it)->getEdge()); if (Ent != this) mp_Neighbours->insert(Ent); } }
NodeInspector* Connection::endInspector() const { Q_ASSERT(drag_state == CONNECTED); NodeInspector* i = gscene()->getInspector(endNode()); Q_ASSERT(i); return i; }
ProftpdConfNode ProftpdParser::parse(const QString & data) const { qDebug() << "data"; qDebug() << data; qDebug() << "dataEND"; ProftpdConfNode node; QRegExp beginNode(BEGIN_NODE_REGEXP, Qt::CaseSensitive, QRegExp::RegExp2); QRegExp datamatch(DATA_NODE_REGEXP, Qt::CaseSensitive, QRegExp::RegExp2); int childpos = 0; int datapos = 0; while ((childpos = beginNode.indexIn(data, childpos)) != -1) { while ((datapos = datamatch.indexIn(data, datapos)) != -1 && datapos < childpos) { datapos += datamatch.matchedLength() - 1; // qDebug() << "DATAA" << data.right(datapos); if (datamatch.cap(1) == QLatin1String("Include")) continue; datamatch.cap(1).isEmpty() ? node.insert(datamatch.cap(3), QString()) : node.insert(datamatch.cap(1), datamatch.cap(2)); } childpos += beginNode.matchedLength() - 1; int beginData = childpos; QRegExp endNode(QString("(</%1>)").arg(beginNode.cap(1).isEmpty() ? beginNode.cap(3) : beginNode.cap(1))); childpos = endNode.indexIn(data, childpos); if (childpos == -1) { std::string err("Misformated configuration file"); std::cerr << err << std::endl; throw ServerConfigHandler::ConfigurationException(err.c_str()); } // qDebug() << "ADD" << beginNode.capturedTexts(); int endData = childpos; childpos += endNode.matchedLength(); datapos = childpos; node.addChild(beginNode.cap(1).isEmpty() ? beginNode.cap(3) : beginNode.cap(1) + " " + beginNode.cap(2), parse(data.mid(beginData).left(endData - beginData))); } // qDebug() << "DATAB" << data.right(datapos)<< "DATABEND"; while ((datapos = datamatch.indexIn(data, datapos)) != -1) { datapos += datamatch.matchedLength() - 1; if (datamatch.cap(1) == QLatin1String("Include")) continue; // qDebug() << "DATA" << data.right(datapos) << "DATA END"; //qDebug() << datamatch.matchedLength() << datamatch.captureCount() << datamatch.capturedTexts(); datamatch.cap(1).isEmpty() ? node.insert(datamatch.cap(3), QString()) : node.insert(datamatch.cap(1), datamatch.cap(2)); } return node; }
int executeShort(SDL_Renderer *ren, SDL_MouseButtonEvent e, Board *B){ //determine if mouse click was on an unlocked arc. //if so lock the arc //else return 1 to sustain turn; int success = 0; for (int i = 0; i < B->num; i++) { for (int j = 0; j < B->num; j++) { if ((B->edges[i][j] == stdArc) || (B->edges[j][i] == stdArc)) //if edge exists test distance { if (arcClicked(B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y, e)){ B->edges[i][j] = lockedArc; B->edges[j][i] = lockedArc; lockArc(ren, B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y); if (B->Vertices[findIndex(B, i)].locked>0){ endNode(ren, B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y); } else{ drawNode(ren, B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y); } if (B->Vertices[findIndex(B, j)].locked>0){ endNode(ren, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y); } else{ drawNode(ren, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y); } success = 1; j = B->num; i = B->num; } } } } //the next two lines rotate the turn display...you should not need to chagne this if (success){ stringColor(ren, 5, 5, "Short's Turn:", white); stringColor(ren, 5, 5, "Cut's Turn:", black); return 0; } else{ return 1; } }
void LineStringEntity::computeLineOrientDownNeighbours() { mp_LODownNeighbours = new std::vector<LineStringEntity*>(); geos::planargraph::DirectedEdgeStar* DownStar = endNode()->getOutEdges(); geos::geom::Coordinate DownNodeCoo = endNode()->getCoordinate(); std::vector<geos::planargraph::DirectedEdge*>::iterator it = DownStar->iterator(); std::vector<geos::planargraph::DirectedEdge*>::iterator ite = DownStar->end(); for (; it != ite; ++it) { LineStringEntity* Unit = dynamic_cast<LineStringEntity*>((*it)->getEdge()); if (Unit->startNode()->getCoordinate().equals(DownNodeCoo)) mp_LODownNeighbours->push_back(Unit); } }
// ------------------------------------------------------------------------- double Pgr_trspHandler::construct_path(int64_t ed_id, Position pos) { pgassert(pos != ILLEGAL); if (m_parent[ed_id].isIllegal(pos)) { Path_t pelement; auto cur_edge = &m_edges[ed_id]; if (pos == RC_EDGE) { pelement.node = cur_edge->startNode(); pelement.cost = cur_edge->cost(); } else { pelement.node = cur_edge->endNode(); pelement.cost = cur_edge->r_cost(); } pelement.edge = cur_edge->edgeID(); m_path.push_back(pelement); pgassert(m_path.start_id() == m_start_vertex); return pelement.cost; } double ret = construct_path(m_parent[ed_id].e_idx[pos], m_parent[ed_id].v_pos[pos]); Path_t pelement; auto cur_edge = &m_edges[ed_id]; if (pos == RC_EDGE) { pelement.node = cur_edge->startNode(); pelement.cost = m_dCost[ed_id].endCost - ret; ret = m_dCost[ed_id].endCost; } else { pelement.node = cur_edge->endNode(); pelement.cost = m_dCost[ed_id].startCost - ret; ret = m_dCost[ed_id].startCost; } pelement.edge = cur_edge->edgeID(); m_path.push_back(pelement); return ret; }
// ------------------------------------------------------------------------- void Pgr_trspHandler::explore( int64_t cur_node, const EdgeInfo cur_edge, bool isStart) { double extra_cost = 0.0; double totalCost; auto vecIndex = cur_edge.get_idx(isStart); for (const auto &index : vecIndex) { auto edge = m_edges[index]; extra_cost = getRestrictionCost( cur_edge.idx(), edge, isStart); if ((edge.startNode() == cur_node) && (edge.cost() >= 0.0)) { totalCost = get_tot_cost( edge.cost() + extra_cost, cur_edge.idx(), isStart); if (totalCost < m_dCost[index].endCost) { m_dCost[index].endCost = totalCost; m_parent[edge.idx()].v_pos[RC_EDGE] = (isStart? C_EDGE : RC_EDGE); m_parent[edge.idx()].e_idx[RC_EDGE] = cur_edge.idx(); add_to_que(totalCost, edge.idx(), true); } } if ((edge.endNode() == cur_node) && (edge.r_cost() >= 0.0)) { totalCost = get_tot_cost( edge.r_cost() + extra_cost, cur_edge.idx(), isStart); if (totalCost < m_dCost[index].startCost) { m_dCost[index].startCost = totalCost; m_parent[edge.idx()].v_pos[C_EDGE] = (isStart? C_EDGE : RC_EDGE); m_parent[edge.idx()].e_idx[C_EDGE] = cur_edge.idx(); add_to_que(totalCost, edge.idx(), false); } } } // for }
void OSMData::endElementHandler (const XML_Char *name) { switch (name[0]) { case 'n' : // XML "node/" element (or "nd/") if (name[1] == 'o') { checkSyntax (!strcmp (name, "node")); endNode (); } break; case 'w' : // XML "way/" element checkSyntax (!strcmp (name, "way")); endWay (); break; } }
/** Parse GCC dump */ void TestParser::parseGCCUnit( DumpUnitInfo *unit) { total_lines_num = 0; DumpPos beg = unit->pos(); DumpPos end = unit->end(); if ( !file.isOpen() && !file.open( QIODevice::ReadOnly)) { return; } file.reset(); /** Read file line by line */ QTextStream in( &file); QString line; unit_beg = 0; unit_id = 0; do { line = in.readLine(); if ( total_lines_num >= beg) { break; } total_lines_num++; } while ( !line.isNull()); cur_line_num = 0; /** Init state */ setStateInit(); #ifdef _DEBUG out( "Started parsing"); #endif do { curr_line = in.readLine(); cur_line_num++; if ( !nextLineGCC( curr_line)) { line.append( curr_line); } else { if ( !line.isNull()) { if ( nodeStopGCC( line)) { endNode(); setStateDefault(); } if ( nodeStartGCC( line)) { setStateNode(); startNode(); } parseLineGCC( line); } line = curr_line; } if ( total_lines_num >= end) break; total_lines_num++; } while ( !curr_line.isNull()); if ( isStateNode()) { endNode(); } #ifdef _DEBUG out( "Finished parsing"); #endif }
void Profile::endFrame() { endNode(); m_timer.stop(); }
void insert(QString & data, QString key, const QString & value, bool toDelete) { QStringList subkeys = key.split(QLatin1Char('#')); const QString & currentKey = subkeys.first(); bool iscurrentKeyNode = (subkeys.count() > 1); QRegExp beginNode(BEGIN_NODE_REGEXP); QRegExp datamatch(DATA_NODE_REGEXP); int childpos = 0; int datapos = 0; while ((childpos = beginNode.indexIn(data, childpos)) != -1) { if (!iscurrentKeyNode) { while ((datapos = datamatch.indexIn(data, datapos)) != -1 && datapos < childpos) { if (datamatch.cap(1) == currentKey) { if (toDelete) { data.replace(datapos, datamatch.matchedLength(), QString()); return; } QString other = data.mid(datapos).left(datamatch.matchedLength()).replace(QRegExp(datamatch.cap(2)), value); data.replace(datapos, datamatch.matchedLength(), other); return; } if (datamatch.cap(3) == currentKey) { if (toDelete) { data.replace(datapos, datamatch.matchedLength(), QString()); return; } const QString other = data.mid(datapos).left(datamatch.matchedLength()) + QString("\t") + value; data.replace(datapos, datamatch.matchedLength(), other); return; } datapos += datamatch.matchedLength() - 1; } } childpos += beginNode.matchedLength() - 1; int beginData = childpos; QRegExp endNode(QString("(</%1>)").arg(beginNode.cap(1).isEmpty() ? beginNode.cap(3) : beginNode.cap(1))); childpos = endNode.indexIn(data, childpos); if (childpos == -1) { std::string err("Misformated configuration file"); std::cerr << err << std::endl; throw ServerConfigHandler::ConfigurationException(err.c_str()); } int endData = childpos; childpos += endNode.matchedLength(); datapos = childpos; if ((currentKey.split(QString(" ")).first() == beginNode.cap(1) || currentKey.split(QString(" ")).first() == beginNode.cap(3)) && !subkeys.isEmpty()) { subkeys.removeFirst(); QString inner = data.mid(beginData).left(endData - beginData); insert(inner, subkeys.join(QString("#")), value, toDelete); data.replace(beginData, endData - beginData, inner); return; } } if (iscurrentKeyNode) { data.prepend(QString("<%1>\n</%2>\n").arg(currentKey, currentKey.split(QString(" ")).first())); insert(data, subkeys.join(QString("#")), value, toDelete); } else { while ((datapos = datamatch.indexIn(data, datapos)) != -1) { if (datamatch.cap(1) == currentKey) { if (toDelete) { data.replace(datapos, datamatch.matchedLength(), QString()); return; } const QString other = data.mid(datapos).left(datamatch.matchedLength()).replace(QRegExp(datamatch.cap(2)), value); data.replace(datapos, datamatch.matchedLength(), other); return; } if (datamatch.cap(3) == currentKey) { if (toDelete) { data.replace(datapos, datamatch.matchedLength(), QString()); return; } const QString other = data.mid(datapos).left(datamatch.matchedLength()) + QString(" ") + value; data.replace(datapos, datamatch.matchedLength(), other); return; } datapos += datamatch.matchedLength() - 1; } if (toDelete) return; if (value.isEmpty()) data.prepend(QString("\n%1").arg(key)); else data.prepend(QString("\n%1\t%2").arg(key, value)); } }
SPpts Pathfinding::FindPath(const Vec2& currentWorldPos, const Vec2& targetWorldPos) { Vec2 currentGridPos = ToGridCoords(currentWorldPos); Vec2 targetGridPos = ToGridCoords(targetWorldPos); if(!TheWorld::Instance()->IsPassable((UINT)targetGridPos.x, (UINT)targetGridPos.y)) return SPpts(); PathNodeSPtr startNode(new PathNode()); PathNodeSPtr endNode(new PathNode()); startNode->Initialize((int)currentGridPos.x, (int)currentGridPos.y, nullptr); endNode->Initialize((int)targetGridPos.x, (int)targetGridPos.y, nullptr); PathNodeVec openList; PathNodeVec closedList; SPpts path(new std::vector<Vec2>); startNode->Heuristic(endNode); openList.push_back(startNode); while(!openList.empty()) { PathNodeSPtr currentNode = GetNextNode(&openList, &closedList); if(currentNode->GetID() == endNode->GetID()) { endNode->SetParent(currentNode->GetParent()); PathNodeSPtr getPath = endNode; // reversing while(getPath->GetParent()) { path->push_back(Engine::Vec2((float)getPath->GetX(), (float)getPath->GetY())); getPath = getPath->GetParent(); } // ---> while parent // ---> swap the path unsigned int size = path->size(); for(unsigned int n = 0; n < size; n++) { if(n == (size - 1 - n)) break; std::swap(path->at(n), path->at(size - 1 - n)); } break; } // ---> if curr == end else { //right AddNode(currentNode->GetX() + 1, currentNode->GetY(), currentNode->GetG() + 1, currentNode, false, &openList, &closedList, endNode); //left AddNode(currentNode->GetX() - 1, currentNode->GetY(), currentNode->GetG() + 1, currentNode, false, &openList, &closedList, endNode); //up AddNode(currentNode->GetX(), currentNode->GetY() - 1, currentNode->GetG() + 1, currentNode, false, &openList, &closedList, endNode); //down AddNode(currentNode->GetX(), currentNode->GetY() + 1, currentNode->GetG() + 1, currentNode, false, &openList, &closedList, endNode); //left up diag AddNode(currentNode->GetX() - 1, currentNode->GetY() - 1, currentNode->GetG() + 1.414f, currentNode, true, &openList, &closedList, endNode); //right up diag AddNode(currentNode->GetX() + 1, currentNode->GetY() - 1, currentNode->GetG() + 1.414f, currentNode, true, &openList, &closedList, endNode); //left down diag AddNode(currentNode->GetX() - 1, currentNode->GetY() + 1, currentNode->GetG() + 1.414f, currentNode, true, &openList, &closedList, endNode); //right down diag AddNode(currentNode->GetX() + 1, currentNode->GetY() + 1, currentNode->GetG() + 1.414f, currentNode, true, &openList, &closedList, endNode); } } // ---> while(){} // ---> converting points to world coords from grid coords unsigned int size = path->size(); for(unsigned int i = 0; i < size; i++) { Vec2 temp = ToWorldCoords(path->at(i)); path->at(i) = temp; } return path; }
//------------------------------ bool NodeLoader::end__node() { return endNode(); }
void VRMLFile::endScript(void) { endNode(); }