MovePicker::MovePicker(Position &p, bool pvnode, Move ttm, Move mk,
                       Move k1, Move k2, Depth dpth) {
  pos = &p;
  pvNode = pvnode;
  ttMove = ttm;
  mateKiller = (mk == ttm)? MOVE_NONE : mk;
  killer1 = k1;
  killer2 = k2;
  depth = dpth;
  movesPicked = 0;
  numOfMoves = 0;
  numOfBadCaptures = 0;
  dc = p.discovered_check_candidates(p.side_to_move());

  if(p.is_check())
    phaseIndex = EvasionsPhaseIndex;
  else if(depth > Depth(0))
    phaseIndex = MainSearchPhaseIndex;
  else if(depth == Depth(0))
    phaseIndex = QsearchWithChecksPhaseIndex;
  else
    phaseIndex = QsearchWithoutChecksPhaseIndex;

  pinned = p.pinned_pieces(p.side_to_move());

  finished = false;
}
Beispiel #2
0
static bool isBalance(BSTreeNode<T>* pbs)
{
	if (pbs==NULL)
		return true;
	int dis = Depth(pbs->left) - Depth(pbs->right);
	if (dis>1 || dis<-1 )
		return false;
	else
		return isBalance(pbs->left) && isBalance(pbs->right);
}
Beispiel #3
0
int Depth (struct NODE *Node, int Level)
{
	if (Node != NULL)
	{
		if (Level > depth)
			depth = Level;
		Depth (Node->Left_Child, Level + 1);
		Depth (Node->Right_Child, Level + 1);
	}
	return (depth);
}
Beispiel #4
0
static int Depth(BSTreeNode<T>* pbs)
{
	if (pbs==NULL)
		return 0;
	else
	{
		int ld = Depth(pbs->left);
		int rd = Depth(pbs->right);
		return 1 + (ld >rd ? ld : rd);
	}
}
Beispiel #5
0
int Depth(BiTree T)
{ 
    int dep=0,depl,depr; 
    if(!T)
        dep=0; 
    else { 
        depl = Depth(T->lchild); 
        depr = Depth(T->rchild); 
        dep  = 1 + (depl > depr ? depl : depr); 
    } 
    return dep; 
}
Beispiel #6
0
int Depth(TreeNode *root)
{

    if (root == NULL)
    {
        return 0;
    }

    int l = Depth(root->left);
    int r = Depth(root->right);

    return  1 + (l>r ? l : r);

}
Beispiel #7
0
	bool _apply_sphere(const Vec3f& center, GLfloat radius)
	{
		assert(radius > 0.0f);
		bool something_updated = false;
		Vec3f c = center*0.5f + Vec3f(0.5f, 0.5f, 0.5f);
		GLfloat r = radius*0.5f;
		GLsizei w = Width(), h = Height(), d = Depth();
		GLubyte* data = _begin_ub();
		for(GLsizei k=(c.z()-r)*d, ke=(c.z()+r)*d; k!=ke; ++k)
		for(GLsizei j=(c.y()-r)*h, je=(c.y()+r)*h; j!=je; ++j)
		for(GLsizei i=(c.x()-r)*w, ie=(c.x()+r)*w; i!=ie; ++i)
		{
			assert(k >= 0 && k < d);
			assert(j >= 0 && j < h);
			assert(i >= 0 && i < w);
			GLsizei n = k*w*h + j*w + i;
			GLubyte b = data[n];
			if(b != 0xFF)
			{
				GLfloat cd = GLfloat(b)/GLfloat(0xFF);
				Vec3f p(GLfloat(i)/w, GLfloat(j)/h, GLfloat(k)/d);
				GLfloat nd = (r - Distance(c, p))/r;
				if(nd < 0.0f) nd = 0.0f;
				nd = std::sqrt(nd);
				nd += cd;
				if(nd > 1.0f) nd = 1.0f;
				data[n] = GLubyte(0xFF * nd);
				something_updated = true;
			}
		}
		return something_updated;
	}
void GSSetupPrimCodeGenerator::Generate()
{
	const int params = 0;

	const int _vertices = params + 4;
	const int _dscan = params + 8;

	mov(ecx, dword[esp + _vertices]);
	mov(edx, dword[esp + _dscan]);

	if((m_en.z || m_en.f) && !m_env.sel.sprite || m_en.t || m_en.c && m_env.sel.iip)
	{
		for(int i = 0; i < 5; i++)
		{
			movaps(Xmm(3 + i), xmmword[&m_shift[i]]);
		}
	}

	Depth();

	Texture();

	Color();

	ret();
}
Beispiel #9
0
void cSubtitleRegion::UpdateTextData(cSubtitleClut *Clut)
{
  const cPalette *palette = Clut ? Clut->GetPalette(Depth()) : NULL;
  for (cSubtitleObject *so = objects.First(); so && palette; so = objects.Next(so)) {
      if (Utf8StrLen(so->TextData()) > 0) {
         cFont *font = cFont::CreateFont(Setup.FontOsd, Setup.FontOsdSize);
         cBitmap tmp(font->Width(so->TextData()), font->Height(), Depth());
         double factor = (double)lineHeight / font->Height();
         tmp.DrawText(0, 0, so->TextData(), palette->Color(so->ForegroundPixelCode()), palette->Color(so->BackgroundPixelCode()), font);
         cBitmap *scaled = tmp.Scaled(factor, factor, true);
         DrawBitmap(so->X(), so->Y(), *scaled);
         delete scaled;
         delete font;
         }
      }
}
Beispiel #10
0
int  main()
{
	int Number = 0;
	char Info ;
	char choice;
	int depth;
	struct NODE *T = (struct NODE *) malloc(sizeof(struct NODE));
	T = NULL;
	//printf("\n Input choice 'b' to break:");
	//choice = getchar();

	while(1)
	{
		fflush(stdin);
		printf("\n Input information of the node: ");
		scanf("%c", &Info);
		if(Info=='Z') break;
		T=Create_Tree(Info, T);
		printf("%x\n",T);		
Number++;
		fflush(stdin);
		//printf("\n Input choice 'b' to break:");
		//choice = getchar();
	}
	printf("\n Number of elements in the list is  %d", Number);
	printf("\n Tree is \n");
	Output(T, 1,a);

	depth = Depth(T, 0);
	printf("\n Depth of the above tree is:  %d", depth);

return 0;
}
Beispiel #11
0
void Node::PrintBernTree(FILE *out)
{
int i;
	int d;

	d=Depth(this);

	for(i=1;i<=d;i++) fprintf(out," ");

	fprintf(out,"node:%X",1);
	fprintf(out,"/%d",DataList.length);
	fprintf(out," TBN:%d%d%d",Top,Bot,Nog);
	fprintf(out," Avail:");
	for(i=1;i<=NumX;i++) fprintf(out,"%d",VarAvail[i]);
	if(!Top) fprintf(out," parent:%X",2);
	if(!Bot) {
		fprintf(out," Var:%d ",rule.Var);
		if(VarType[rule.Var]==CAT) {
			fprintf(out,"CATRule: ");
			for(i=1;i<=RuleNum[rule.Var];i++) fprintf(out,"%d",rule.CatRule[i]);
		} else {
			fprintf(out,"ORDRule:");
			fprintf(out,"(%d)=%f",rule.OrdRule,rule.SplitVal());
		}
	}
	fprintf(out,"\n");

	if(!Bot) {
		LeftC->PrintBernTree(out);
		RightC->PrintBernTree(out);
	}

}
Beispiel #12
0
void Node::PrintTree()
{
	int i;
	int d;

	d=Depth(this);

	for(i=1;i<=d;i++) printf(" ");

	//printf("node:%X",this);
	std::cout << "node:" << this;
	printf(" n:%d",DataList.length);
	printf(" TBN: %d%d%d",Top,Bot,Nog);
	printf(" Avail:");
	for(i=1;i<=NumX;i++) printf("%d",VarAvail[i]);
	if(!Top) std::cout << "parent:" << Parent << " ";
	if(!Bot) {
		printf(" Var:%d ",rule.Var);
		if(VarType[rule.Var]==CAT) {
			printf("CATRule: ");
			for(i=1;i<=RuleNum[rule.Var];i++) printf(" %d",rule.CatRule[i]);
		} else {
			printf("ORDRule:");
			printf("(%d)=%f",rule.OrdRule, rule.SplitVal());
		}
	}
	printf("\n");

	if(!Bot) {
		LeftC->PrintTree();
		RightC->PrintTree();
	}

}
// A node corresponds to a rule pattern that has been partially applied to a
// sentence (the terminals have fixed positions, but the spans of gap symbols
// may be unknown).  This function determines the range of possible start
// values for the partially-applied pattern.
void PatternApplicationTrie::DetermineStartRange(int sentenceLength,
    int &minStart,
    int &maxStart) const
{
  // Find the leftmost terminal symbol, if any.
  const PatternApplicationTrie *n = GetHighestTerminalNode();
  if (!n) {
    // The pattern contains only gap symbols.
    minStart = 0;
    maxStart = sentenceLength-Depth();
    return;
  }
  assert(n->m_parent);
  if (!n->m_parent->m_parent) {
    // The pattern begins with a terminal symbol so the start position is
    // fixed.
    minStart = n->m_start;
    maxStart = n->m_start;
  } else {
    // The pattern begins with a gap symbol but it contains at least one
    // terminal symbol.  The maximum start position is the start position of
    // the leftmost terminal minus one position for each leading gap symbol.
    minStart = 0;
    maxStart = n->m_start - (n->Depth()-1);
  }
}
Beispiel #14
0
const nsString*
nsQuoteNode::Text()
{
  NS_ASSERTION(mType == eStyleContentType_OpenQuote ||
               mType == eStyleContentType_CloseQuote,
               "should only be called when mText should be non-null");
  const nsStyleQuotes* styleQuotes = mPseudoFrame->GetStyleQuotes();
  PRInt32 quotesCount = styleQuotes->QuotesCount(); // 0 if 'quotes:none'
  PRInt32 quoteDepth = Depth();

  // Reuse the last pair when the depth is greater than the number of
  // pairs of quotes.  (Also make 'quotes: none' and close-quote from
  // a depth of 0 equivalent for the next test.)
  if (quoteDepth >= quotesCount)
    quoteDepth = quotesCount - 1;

  const nsString *result;
  if (quoteDepth == -1) {
    // close-quote from a depth of 0 or 'quotes: none' (we want a node
    // with the empty string so dynamic changes are easier to handle)
    result = & EmptyString();
  } else {
    result = eStyleContentType_OpenQuote == mType
               ? styleQuotes->OpenQuoteAt(quoteDepth)
               : styleQuotes->CloseQuoteAt(quoteDepth);
  }
  return result;
}
Beispiel #15
0
void Manager::updateAllSprites(Uint32 ticks){ 
	std::size_t size = sprites.size();
	for(unsigned int i = 0; i < size; ++i){
		sprites[i] -> update(ticks, clock.isPaused());
	}
  	std::sort(sprites.begin(), sprites.end(), Depth());
}
Beispiel #16
0
const nsString*
nsQuoteNode::Text()
{
  NS_ASSERTION(mType == eStyleContentType_OpenQuote ||
               mType == eStyleContentType_CloseQuote,
               "should only be called when mText should be non-null");
  const nsStyleQuoteValues::QuotePairArray& quotePairs =
    mPseudoFrame->StyleList()->GetQuotePairs();
  int32_t quotesCount = quotePairs.Length(); // 0 if 'quotes:none'
  int32_t quoteDepth = Depth();

  // Reuse the last pair when the depth is greater than the number of
  // pairs of quotes.  (Also make 'quotes: none' and close-quote from
  // a depth of 0 equivalent for the next test.)
  if (quoteDepth >= quotesCount)
    quoteDepth = quotesCount - 1;

  const nsString* result;
  if (quoteDepth == -1) {
    // close-quote from a depth of 0 or 'quotes: none' (we want a node
    // with the empty string so dynamic changes are easier to handle)
    result = &EmptyString();
  } else {
    result = eStyleContentType_OpenQuote == mType
               ? &quotePairs[quoteDepth].first
               : &quotePairs[quoteDepth].second;
  }
  return result;
}
void test_Depth(void) {
	GENERALIZED_LIST_TYPE list = NULL;
	CU_ASSERT_EQUAL(Depth(list), 0);

	list = getGeneralizedList("(1,2)");
	CU_ASSERT_EQUAL(Depth(list), 1);

	list = getGeneralizedList("(1,2,3,4)");
	CU_ASSERT_EQUAL(Depth(list), 1);

	list = getGeneralizedList("((11,12,13),(21,22,23,24,25),3)");
	CU_ASSERT_EQUAL(Depth(list), 2);

	list = getGeneralizedList(
			"((11,12,13),(21,22,23,24,25),3,(4,(51,52,53,(501,502))))");
	CU_ASSERT_EQUAL(Depth(list), 4);
}
Beispiel #18
0
void History::AddData(int i, HistoryAtom state)
{
    data[i].data.push_front(state);
    data[i].newdata = true;

    // discard obsolete data
    while(state.ticks - data[i].data.back().ticks > Depth(i))
        data[i].data.pop_back();
}
void test_Depth(void) {
	BINARY_TREE_TYPE tree = NULL;

	tree = get_test_tree("");
	CU_ASSERT_EQUAL(Depth(tree), 0);

	tree = get_test_tree("1");
	CU_ASSERT_EQUAL(Depth(tree), 1);

	tree = get_test_tree("1, 2");
	CU_ASSERT_EQUAL(Depth(tree), 2);

	tree = get_test_tree("1, 2, 3, 4");
	CU_ASSERT_EQUAL(Depth(tree), 3);

	tree = get_test_tree("1, , 3, , , 6, 7, , , , , 61, 62, 71, 72");
	CU_ASSERT_EQUAL(Depth(tree), 4);
}
double Nonleaf::AbsVofLevel(int i, short ftype, short dim) const {
double AbsV=0.0;
if (i>Depth()-1) print_error("Nonleaf::AbsVofLevel","can not go further"); 
if (i==0) return pow(sqrt(this->Fitness(ftype)),dim);
else { for (int j=0; j<actsize; j++) 
	AbsV+=child[j]->AbsVofLevel(i-1,ftype,dim);
       return AbsV;
       }
}
Beispiel #21
0
void Manager::updateAllEnemies(Uint32 ticks){ 
	std::size_t size = enemies.size();
	for(unsigned int i = 0; i < size; ++i){
		enemies[i] -> update(ticks, clock.isPaused());
	}
	size = explodingEnemies.size();
	for(unsigned int i = 0; i< size; ++i){
		explodingEnemies[i] -> update(ticks, clock.isPaused());
	}
  	std::sort(enemies.begin(), enemies.end(), Depth());
}
void PatternApplicationTrie::ReadOffPatternApplicationKey(
  PatternApplicationKey &key) const
{
  const int depth = Depth();
  key.resize(depth);
  const PatternApplicationTrie *p = this;
  std::size_t i = depth-1;
  while (p->m_parent != 0) {
    key[i--] = p;
    p = p->m_parent;
  }
}
Beispiel #23
0
int main() {
  ChainBinTree *root = NULL;
  char select;
  void (*oper1)(); //指向函数的指针
  oper1 = oper;
  do {

    printf("\n1.设置二叉树根元素    2.添加二叉树结点\n");
    printf("3.前序遍历    4.中序遍历\n");
    printf("5.后序遍历    6.二叉树深度\n");
    printf("0.退出\n");
    printf("你的选择:");
    select = getchar();
    switch (select) {
      case '1':
        root = InitRoot();
        break;
      case '2':
        AddNode(root);
        break;
      case '3':
        printf("------------------------------\n");
        printf("前序遍历的结果:\n");
        BinTree_DLR(root,oper1);

        printf("------------------------------\n");
        break;
      case '4':
        printf("------------------------------\n");
        printf("中序遍历的结果:\n");
        BinTree_LDR(root,oper1);
        printf("------------------------------\n");
        break;
      case '5':
        printf("------------------------------\n");
        printf("后序遍历的结果:\n");
        BinTree_LRD(root,oper1);
        printf("------------------------------\n");
        break;
      case '6':
        printf("------------------------------\n");
        printf("二叉树的深度为:%d\n", Depth(root));
        printf("------------------------------\n");
        break;
      case '0':
        break;
      }
      getchar(); //抵消 \n
    }while(select!='0');
    Clear(root);
    return 0;

}
int Depth(TREE_TYPE tree) {
	if (tree == NULL)
		return 0;

	int depth = 0, child_depth = 0;
	TREE_NODE *child = tree -> first_child;
	while (child) {
		child_depth = Depth(child);
		if (child_depth > depth)
			depth = child_depth;
		child = child -> next_sibling;
	}
	return depth + 1;
}
Beispiel #25
0
int
Graphic::operator <= (const Graphic& g) const
{
    if (!infinite && g.infinite)
    return 1;

    else if (infinite && !g.infinite)
    return 0;

    double za = fabs(Depth());
    double zb = fabs(g.Depth());

    return (za <= zb);
}
Beispiel #26
0
 void TextureData3D :: Upload ( GLenum target )
 {
     glTexImage3D (
         target               /* the target texture */,
         0                    /* the level-of-detail number */,
         InternalFormat ( )   /* the number of color components */,
         Width ( )            /* the width of the texture with border */,
         Height ( )           /* the height of the texture with border */,
         Depth ( )            /* the depth of the texture with border */,
         0                    /* the width of the border */,
         PixelFormat ( )      /* the format of the pixel data */,
         Type ( )             /* the data type of the pixel data */,
         fPixels              /* a pointer to the image data */ );
 }
Beispiel #27
0
bool isBalanced(TreeNode *root)
{
    /*
    Given a binary tree, determine if it is height-balanced.

    For this problem, a height-balanced binary tree is defined as a binary tree
    in which the depth of the two subtrees of every ListNode never differ by more than 1.
    */

    /*

    */

    if (root == NULL)
        return true;
    int v = Depth(root->left) - Depth(root->right);
    if (v>1 || v<-1)
        return false;
    else
        return isBalanced(root->left) && isBalanced(root->right);

    return false;
}
// A node corresponds to a rule pattern that has been partially applied to a
// sentence (the terminals have fixed positions, but the spans of gap symbols
// may be unknown).  This function determines the range of possible end values
// for the partially-applied pattern.
void PatternApplicationTrie::DetermineEndRange(int sentenceLength,
    int &minEnd,
    int &maxEnd) const
{
  // Find the rightmost terminal symbol, if any.
  const PatternApplicationTrie *n = GetLowestTerminalNode();
  if (!n) {
    // The pattern contains only gap symbols.
    minEnd = Depth()-1;
    maxEnd = sentenceLength-1;
    return;
  }
  if (n == this) {
    // The pattern ends with a terminal symbol so the end position is fixed.
    minEnd = m_end;
    maxEnd = m_end;
  } else {
    // The pattern ends with a gap symbol but it contains at least one terminal
    // symbol.  The minimum end position is the end position of the rightmost
    // terminal + one position for each trailing gap symbol.
    minEnd = n->m_end + (Depth()-n->Depth());
    maxEnd = sentenceLength-1;
  }
}
Beispiel #29
0
    /**
     * サンプリング
     * @param ret サンプルされたボリュームバッファ値
     * @param x X位置
     * @param y Y位置
     * @param z Z位置
     */
    void Sample(float* ret, float x, float y, float z) {

        float xx = x;
        float yy = y;
        float zz = z;

        if (m_isNonUniform) {

            // remap coordinate.

            if (SpacingX()->GetNum() > 0) {
                xx = remap(xx, static_cast<const float*>(SpacingX()->GetBuffer()), SpacingX()->GetNum());
            }

            if (SpacingX()->GetNum() > 0) {
                yy = remap(yy, static_cast<const float*>(SpacingY()->GetBuffer()), SpacingY()->GetNum());
            }

            if (SpacingX()->GetNum() > 0) {
                zz = remap(zz, static_cast<const float*>(SpacingZ()->GetBuffer()), SpacingZ()->GetNum());
            }

        }

        size_t ix = (std::min)((std::max)((size_t)(xx * Width()), (size_t)(Width()-1)), (size_t)0);
        size_t iy = (std::min)((std::max)((size_t)(yy * Height()), (size_t)(Height()-1)), (size_t)0);
        size_t iz = (std::min)((std::max)((size_t)(zz * Depth()), (size_t)(Depth()-1)), (size_t)0);

        size_t idx = Component() * (iz * Width() * Height() + iy * Width() + ix);

        const float* buf = static_cast<const float*>(m_buffer->GetBuffer());
        for (size_t c = 0; c < Component(); c++) {
            ret[c] = buf[idx + c];
        }

    }
Beispiel #30
0
	Path Path::GetParentAtDepthN(UInt32 nDepth)
	{    
		if(!IsValid() ||
		nDepth >= Depth())
		{
			return *this;
		}
			
		// create Path object to parent object at depth N relative to this
		// path object.
		bool bHasFSOnStart = (m_sPath.length() > 0 && m_sPath[0] == PATH_SEPARATOR_CHAR);
		
		// create a copy of m_sPath.
		std::vector<TCHAR> pPath(m_sPath.length() + 1);
		strcpy(&pPath[0], m_sPath.c_str());
		
		// reset m_sPath as required.
		std::string sTmpPath = bHasFSOnStart ? PATH_SEPARATOR_STR : "";
		
		// split path into it tokens.
		LPSTR p = strtok(&pPath[0], PATH_SEPARATOR_STR);
			
		while(p && nDepth > 0)
		{
			if(sTmpPath.length() > 0 && sTmpPath[sTmpPath.length() - 1] != PATH_SEPARATOR_CHAR)
			{
				sTmpPath += PATH_SEPARATOR_CHAR;
			}
			
			sTmpPath += p;
			--nDepth;
			
			p = strtok(NULL, PATH_SEPARATOR_STR);
		}
		
		// put / on end as required
		if(sTmpPath.length() > 0 ? (sTmpPath[sTmpPath.length() - 1] != PATH_SEPARATOR_CHAR) : true)
		{
			sTmpPath += PATH_SEPARATOR_CHAR;
		}
	
	#if defined(_WINDOWS)
		return Path(m_sDrive + sTmpPath, false);
	#else
		return Path(sTmpPath, false);
	#endif
	}