예제 #1
0
파일: trytree3.cpp 프로젝트: Malows/aedcode
//---:---<*>---:---<*>---:---<*>---:---<*>---:---<*>---:---<*>---: 
void mirror(tree_t &T,node_t n) {
  list< tree<int> > L;
  node_t c = n.lchild();
  if (c==T.end()) return;
  while (c!=T.end()) {
    printf("passing to list subtree rooted at %d\n",*c);
    L.insert(L.begin(),tree_t());
    tree_t &Q = *L.begin();
    T.splice(Q.begin(),c);
#if 0
    cout << "T: \n";
    T.lisp_print();
    cout << "\nQ: \n";
    Q.lisp_print();
    cout << endl;
#endif
    mirror(Q);
    c = n.lchild();
  }

  c = n.lchild();
  while (!L.empty()) {
    tree_t &Q = *L.begin();
    printf("passing to tree subtree rooted at %d\n",*Q.begin());
    c = T.splice(c,Q.begin());
    c++;
    L.erase(L.begin());
  }
}
 void update() {
   size = 1;
   subtree_value = value;
   if (left != NULL) {
     subtree_value = join_values(subtree_value, left->get_subtree_value());
     size += left->size;
   }
   if (right != NULL) {
     subtree_value = join_values(subtree_value, right->get_subtree_value());
     size += right->size;
   }
 }
 T query(int a, int b) {
   if (!is_connected(a, b)) {
     throw std::runtime_error("Cannot query nodes that are not connected.");
   }
   get_uv(a, b);
   expose(u);
   u->rev = !u->rev;
   expose(v);
   return v->get_subtree_value();
 }
예제 #4
0
//---:---<*>---:---<*>---:---<*>---:---<*>---:---<*>
void split_down(tree<int> &T,node_t p,int n,int g) {
  // Si el valor en la raiz esta OK, entonces no hace falta
  // hacer nada. 
  if (*p <= n) return;
  // Llama a `distrib()' para ver como es la distribucion
  // del valor en el nodo `*p'
  vector<int> v; distrib(*p,g,v);
  // Va iterando, creando los nuevos nodos
  node_t c = p.lchild();
  for (unsigned int j=0; j<v.size(); j++) {
    c = T.insert(c,v[j]);
    // Aplica recursivamente la funcion
    split_down(T,c++,n,g);
  }
}
예제 #5
0
파일: closed_hash.hpp 프로젝트: Syntaf/GG
 void set_state(std::size_t x) { return node_m->set_state(x); }
예제 #6
0
파일: closed_hash.hpp 프로젝트: Syntaf/GG
 std::size_t state() const { return node_m->state(); }
예제 #7
0
파일: closed_hash.hpp 프로젝트: Syntaf/GG
 void decrement() { node_m = node_m->prior(); }
예제 #8
0
파일: closed_hash.hpp 프로젝트: Syntaf/GG
 void increment() { node_m = node_m->next(); }           
예제 #9
0
bool
tablebase_t::operator()(const node_t& node, const std::uint_fast8_t height, score_t& score) const
{
	std::uint32_t rgiCounters[10];
	unsigned int rgsqWhite[C_PIECES * 5 + 1];
	unsigned int rgsqBlack[C_PIECES * 5 + 1];

	// initialize counters and piece arrays so the probe code
	// can compute the modified Godel number.
	init(rgiCounters, rgsqWhite, 0, node.board_pawns_white());
	init(rgiCounters, rgsqWhite, 1, node.board_knights_white());
	init(rgiCounters, rgsqWhite, 2, node.board_bishops_white());
	init(rgiCounters, rgsqWhite, 3, node.board_rooks_white());
	init(rgiCounters, rgsqWhite, 4, node.board_queens_white());
	init(rgiCounters + 5, rgsqBlack, 0, node.board_pawns_black());
	init(rgiCounters + 5, rgsqBlack, 1, node.board_knights_black());
	init(rgiCounters + 5, rgsqBlack, 2, node.board_bishops_black());
	init(rgiCounters + 5, rgsqBlack, 3, node.board_rooks_black());
	init(rgiCounters + 5, rgsqBlack, 4, node.board_queens_black());

	std::lock_guard<std::mutex> lock(const_cast<std::mutex&>(_mutex));

	// tablebase registered ?
	int iTb = IDescFindFromCounters((int*)rgiCounters);
	if (!iTb)
		return false;

	// set up tablebase parameters
	std::uint32_t invert;
	int side;
	unsigned int* psqW;
	unsigned int* psqB;

	rgsqWhite[C_PIECES * 5] = node.square_king_white();
	rgsqBlack[C_PIECES * 5] = node.square_king_black();
	if (iTb > 0)
	{
		side = node.color() == black;
		invert = false;
		psqW = rgsqWhite;
		psqB = rgsqBlack;
	}
	else
	{
		side = node.color() == white;
		invert = true;
		psqW = rgsqBlack;
		psqB = rgsqWhite;
		iTb = -iTb;
	}

	// tablebase registered ?
	if (!FRegisteredFun(iTb, side))
		return false;

	// get tbValue
	const unsigned int sqEnP = node.square_en_passant() ? node.square_en_passant() : 127;
	const std::uint64_t index = PfnIndCalcFun(iTb, side) ((unsigned int *)psqW, (unsigned int *)psqB, sqEnP, invert);
	const score_t tbValue = L_TbtProbeTable(iTb, side, index);
	if (tbValue == L_bev_broken)
		return false;

	// convert tbValue to score
	if (tbValue > 0)
		score = /*Score::max*/ +30000 + 2 * (-L_bev_mi1 + tbValue - 1) - (score_t)height + 1;
	else if (tbValue < 0)
		score = /*Score::min*/ -30000 + 2 * (+L_bev_mi1 + tbValue) + (score_t)height;
	else
		score = 0;//Score::remis;

	return true;
}
예제 #10
0
 node_t* next(char c){
     if (g(c) != NULL) return g(c);
     child[c] = failure->next(c);
     return child[c];
 }
예제 #11
0
	void walk( int d = 0 ){
		if(l) l->walk(d+1);
		REP( i, d ) cout << "\t";
		cout << key << endl;
		if(r) r->walk(d+1);
	}
예제 #12
0
 bool operator> (const node_t& n2) const
 {
     return cost_f() < n2.cost_f();
 }
예제 #13
0
 bool operator< (const node_t& n2) const
 {
     return cost_f() > n2.cost_f();
 }
예제 #14
0
 auto operator()(const node_t& a, const node_t& b)
 {
     return _matrix(a.id(), b.id());
 }
예제 #15
0
파일: test.cpp 프로젝트: js850/kmc_rates
 void examining_node(node_t u, Graph & g){
     cout << "    examining node " << u->id() << "\n";
 }
예제 #16
0
파일: test.cpp 프로젝트: js850/kmc_rates
 void discover_node(node_t u, Graph & g){
     cout << "discovered node " << u->id() << "\n";
 }
예제 #17
0
// foreach functor example
static void enumerate(const std::string& key, const node_t& node,
        store_t store) {
    const data_t& data = node.data();
    std::cout << "'" << key << "' -> '" << data.str(store) << "'" << std::endl;
}