///Generate next move by taking into account the most connected cells. ///@param emptyindicators: boolean array to indicate the empty positions ///@param queue the priority queue stores the empty positions with the priority as the connections to the position adding some randomness ///@param counter the auxiliary vector which stores the index of position and priority ///@return next move represent as index or position on the hex board int Strategy::genNextFill(hexgame::shared_ptr<bool>& emptyindicators, PriorityQueue<int, int>&queue, int& proportionofempty) { int nexloc = queue.minPrioirty(); emptyindicators.get()[nexloc - 1] = false; --proportionofempty; return nexloc; }
void Prim::mst(int root,Color color){ Q.clear(); int size=G->V(); // number of vertices for(int i=0;i<size;i++){ dist[i]=1000.0; edges[i]=NO_EDGE; if(G->get_node_value(i)==color){ // only choose the same color //dist[i]=INF; // equal to infinite //cout<<"insert node!"<<i<<" and dist is "<<dist[i]<<endl; Q.Insert(Type_Queue_Element (i,dist[i])); // assign V[G] to Q } } dist[root]=0.0; if(!Q.contains(root)) cout<<"not include root !!"<<endl; else { Q.chgPrioirity(root,dist[root]); //dist[i] and priority value in priority queue must be synchronized edges[root]=ROOT_EDGE; while(!Q.empty()){ Type_Queue_Element currElement=Q.top(); Q.minPrioirty(); // remove from priority queue int currNode=currElement.first; if(edges[currNode]!=NO_EDGE){ dist[currNode]=currElement.second; vector<int> neibs=G->neighbors(currNode,color); for(unsigned int i=0;i<neibs.size();i++){ if(Q.contains(neibs[i]) && (G->get_edge_value(neibs[i],currNode)<dist[neibs[i]]) ){ edges[neibs[i]]=currNode; dist[neibs[i]]=G->get_edge_value(neibs[i],currNode); Q.chgPrioirity(neibs[i],dist[neibs[i]]); } } } } } }