void CBwfind::select(int flag) { int step,i,j,cut=1000000,tf=flag; int tb[8][8]; for(i=0;i<8;i++)for(j=0;j<8;j++) tb[i][j]=board[i][j]; step=CountNum(); //开局 if(step<searchend){ int ss=0; findfirst(tb,ss,tf,cut); } //终局 else if(step>=searchend){ preview=true; outcome=findlast(tb,step,tf,cut); } }
int CBwfind::findlast(int tb[][8], int &step, int &flag, int cut) { int value=0,max=-100000,min=100000,k=0,i,j; int temp[8][8]; if(step==64){ if(ComChoice==1) return(black(tb)-white(tb)); else return(white(tb)-black(tb)); } for(i=0;i<8;i++)for(j=0;j<8;j++) temp[i][j]=tb[i][j]; for(i=0;i<8;i++)for(j=0;j<8;j++){ if(judge(tb,i,j,flag)){ int ii,jj; k=1;//存在合理的步子 newboard(tb,i,j,flag); flag=-flag; step++; if(-flag==ComChoice){ value=findlast(tb,step,flag,max); } if(-flag==ManChoice){ value=findlast(tb,step,flag,min); } step--; flag=-flag; //恢复棋盘 for(ii=0;ii<8;ii++)for(jj=0;jj<8;jj++) tb[ii][jj]=temp[ii][jj]; if(flag-ManChoice==0&&value<cut) return value; if(flag-ComChoice==0&&value>cut) return value; if(flag-ManChoice==0){ if(value<min){ min=value; } } if(flag-ComChoice==0){ if(value>max){ max=value; if(step==CountNum()){ stepx=i; stepy=j; } } } }//if }//for //当前没有步可走 if(k==0){ flag=-flag; if(search(tb,flag)){ value=findlast(tb,step,flag,cut); flag=-flag; return value; } else{ flag=-flag; if(ComChoice==1) return(black(tb)-white(tb)); else return(white(tb)-black(tb)); } } //存在合理步 else{ if(flag-ManChoice==0) return min; if(flag-ComChoice==0){ return max; } } }
void StaticPersistence<D, CT, OT, E, Cmp>:: pair_simplices(iterator bg, iterator end, bool store_negative, const Visitor& visitor) { #if LOGGING typename ContainerTraits::OutputMap outmap(order_); #endif // FIXME: need sane output for logging rLog(rlPersistence, "Entered: pair_simplices"); for (iterator j = bg; j != end; ++j) { visitor.init(j); rLog(rlPersistence, "Simplex %s", outmap(j).c_str()); Cycle z; swap_cycle(j, z); rLog(rlPersistence, " has boundary: %s", z.tostring(outmap).c_str()); // Sparsify the cycle by removing the negative elements if (!store_negative) { typename OrderElement::Cycle zz; BOOST_FOREACH(OrderIndex i, z) if (i->sign()) // positive zz.push_back(i); z.swap(zz); } // -------------------------- CountNum(cPersistencePairBoundaries, z.size()); #ifdef COUNTERS Count(cPersistencePair); #endif // COUNTERS while(!z.empty()) { OrderIndex i = z.top(ocmp_); // take the youngest element with respect to the OrderComparison rLog(rlPersistence, " %s: %s", outmap(i).c_str(), outmap(i->pair).c_str()); // TODO: is this even a meaningful assert? AssertMsg(!ocmp_(i, index(j)), "Simplices in the cycle must precede current simplex: (%s in cycle of %s)", outmap(i).c_str(), outmap(j).c_str()); // i is not paired, so we pair j with i if (iterator_to(i->pair) == iterator_to(i)) { rLog(rlPersistence, " Pairing %s and %s with cycle %s", outmap(i).c_str(), outmap(j).c_str(), z.tostring(outmap).c_str()); set_pair(i, j); swap_cycle(j, z); set_pair(j, i); CountNum(cPersistencePairCycleLength, j->cycle.size()); CountBy (cPersistencePairCycleLength, j->cycle.size()); break; } // update element z.add(i->pair->cycle, ocmp_); visitor.update(j, iterator_to(i)); rLog(rlPersistence, " new cycle: %s", z.tostring(outmap).c_str()); } // if z was empty, so is (already) j->cycle, so nothing to do visitor.finished(j); rLog(rlPersistence, "Finished with %s: %s", outmap(j).c_str(), outmap(j->pair).c_str()); }