Esempio n. 1
0
/*__________________________________________________________________________________________*/
CPoint wzq::AiGo(bool color)
{
	CPoint turnback(-1,-1);
	clear(false);					//pc全部置为255
	fillin(color,false,true);
	fillin(!color,false,false);
	wzq::aitype2 = getAItype();
	unsigned char found = 255;
	for (int ix = 0; ix < 15; ix++)
	{
		for (int iy = 0; iy < 15; iy++)
		{
			for (int im = 0; im <= 3; im++)
			{
				if (pc[ix][iy][im] <= found)
				{
					found = pc[ix][iy][im];
					turnback.x = ix,turnback.y = iy;
				}
			}
		}
	}
	if (found <= 23)
		return turnback;
	else
		return getmax(color);
}
Esempio n. 2
0
void fillin(node *pa, node *qa, boolean contin)
{
  if (!pa->tip) {
    fillin(pa->next->back, qa, contin);
    fillin(pa->next->next->back, qa, contin);
  }
  filltraverse(pa, qa, contin);
}  /* fillin */
Esempio n. 3
0
/*
 * getuinfo_file()
 *	Get user info from passed file
 *
 * Returns 0 on success, 1 on failure
 */
static int
getuinfo_file(FILE *fp, char *name, struct uinfo *u)
{
	char *p, buf[80];

	/*
	 * Get lines out of file until EOF or match
	 */
	while (fgets(buf, sizeof(buf), fp)) {
		buf[strlen(buf)-1] = '\0';

		/*
		 * Chop off first field--account name
		 */
		p = strchr(buf, ':');
		if (p == 0) {
			continue;	/* Malformed */
		}

		/*
		 * Match?
		 */
		*p++ = '\0';
		if (!strcmp(name, buf)) {
			strcpy(u->u_acct, name);
			fillin(p, u);
			return(0);
		}
	}
	return(1);
}
Esempio n. 4
0
File: main.c Progetto: aahud/harvey
static Filter*
fillin(Filter *f, Proto *last)
{
	int i;
	Filter *nf;

	/* hack to make sure top level node is the root */
	if(last == nil){
		if(f->pr == root)
			return f;
		f = fillin(f, root);
		if(f == nil)
			return nil;
		return addnode(f, root);
	}

	/* breadth first search though the protocol graph */
	nf = f;
	for(i = 1; i < 20; i++){
		nf = _fillin(f, last, i);
		if(nf != nil)
			break;
	}
	return nf;
}
Esempio n. 5
0
File: fill.c Progetto: cgd/hmmSNP
/*******************************************************************************
 * fill_and_save - fill in missing genotypes and save the result
 *
 * INPUTS: snp_t *snps - array of snp_t structs
 *         em_params_t *em_params - input parameters for hmm_em()
 *         em_out_t *em_out - output of hmm_em()
 *         int path_option - which path algorithm was used
 *         int sort_option - state sorting option (for path output)
 *         double threshold - confidence threshold for filtered output
 *         int num_emission_types - 2 or 3 depending if missing is a valid emission type
 *         int chromosome - which chromosome was processed
 *         int smooth_out - boolean value to instruct maxSmthPath to write out
 *             the smoothness information
 *         double **fill_probability_matrix - pointer to memory to store filling probabilities 
 *         
 *
 * RETURNS:
 *      funciton returns void, filling probabilities returned via parameter
 *
 * ASSUMES:
 *
 * EFFECTS:  modifies contents of fill_probability_matrix, writes filled file and path file
 *
 * ERROR CONDITIONS:
 *
 * COMMENTS:
 *
 ******************************************************************************/
void fill_and_save(snp_t *snps, em_params_t *em_params, em_out_t *em_out, 
                   int path_option, int sort_option, double threshold,
                   int num_emission_types, int chromosome, int smooth_out,
                   double **fill_probability_matrix)
{
  clock_t tStart;
  clock_t tEnd;
  int **path_matrix;
  double **log_prob_matrix = NULL;

  assert(path_option == PATH_VITERBI || path_option == PATH_MAXSMTH);
  
  path_matrix = allocate2Di(em_params->num_snps, em_params->num_strains);

  tStart = clock();
  
  if (path_option == PATH_VITERBI)
  {
    printf("Calculating Viterbi path...");
    log_prob_matrix = allocate2Dd(em_params->num_snps, em_params->num_strains);

    viterbiPath(em_params, em_out, path_matrix, log_prob_matrix,
               fill_probability_matrix);
  }
  else
  {
    printf("Calculating max smooth path...");
    maxSmthPath(em_params, em_out, em_params->file_prefix, smooth_out, 
                path_matrix, fill_probability_matrix);
  }
  
  tEnd = clock();
  
  printf("Done (%.2fs)\n", ((double)(tEnd - tStart)) / CLOCKS_PER_SEC);
          
  /* write the path to a file */                
  writePath(snps, path_matrix, em_params->num_snps, 
            em_params->num_strains, em_params->file_prefix, 
            path_option, chromosome, sort_option, 
            em_out->last_emission_matrix);
  
  /* if random missing then fill in using path */
  if ( em_params->miss_option > 0)
  {
    fillin(em_params->snps,  path_matrix, em_out->last_emission_matrix, 
           em_params->num_snps, em_params->num_strains, num_emission_types, 
           fill_probability_matrix);
  
    writeFilledData(snps, chromosome, fill_probability_matrix,
                    em_params->file_prefix, path_option, sort_option, 
                    threshold, em_params->num_snps);
  }

  free2Di(path_matrix, em_params->num_snps);
  if (path_option == PATH_VITERBI)
  {
    free2Dd(log_prob_matrix, em_params->num_snps);
  }
}
Esempio n. 6
0
void	refreshall(t_struct *vals, t_booly *booh, int *j)
{
  vals->turn = 1;
  free(booh);
  booh = fillin(*vals);
  tputs(vals->tget->clears, 1, my_putchar);
  afffile(*vals, booh);
  affturn(*vals, booh);
  *j = 0;
}
Esempio n. 7
0
void filltrav(node2 *r, long fullset, boolean full, bitptr wagner,
                        bitptr zeroanc)
{
  /* traverse to fill in interior node states */
  if (r->tip)
    return;
  filltrav(r->next->back, fullset, full, wagner, zeroanc);
  filltrav(r->next->next->back, fullset, full, wagner, zeroanc);
  fillin(r, fullset, full, wagner, zeroanc);
}  /* filltrav */
Esempio n. 8
0
void postorder(node2 *p, long fullset, boolean full, bitptr wagner,
                        bitptr zeroanc)
{
  /* traverses a binary tree, calling PROCEDURE fillin at a
     node's descendants before calling fillin at the node2 */
  /* used in mix & penny */
  if (p->tip)
    return;
  postorder(p->next->back, fullset, full, wagner, zeroanc);
  postorder(p->next->next->back, fullset, full, wagner, zeroanc);
  if (!p->visited) {
    fillin(p, fullset, full, wagner, zeroanc);
    if (!full) p->visited = true;
  }
}  /* postorder */
Esempio n. 9
0
t_bres				bresenham(t_jig a, t_jig b)
{
	t_bres			ret;

	ret.a = a;
	ret.b = b;
	ret.x1 = a.x;
	ret.y1 = a.y;
	ret.x2 = b.x;
	ret.y2 = b.y;
	ret.i = -1;
	ret.w = ret.x2 - ret.x1;
	ret.h = ret.y2 - ret.y1;
	ret.dx1 = 0;
	ret.dy1 = 0;
	ret.dx2 = 0;
	ret.dy2 = 0;
	fillin(&ret);
	return (ret);
}
Esempio n. 10
0
void insert_(node *p, node *q, boolean contin_)
{
  /* put p and q together and iterate info. on resulting tree */
  double x=0.0, oldlike, dummy;
  hookup(p->next->next, q->back);
  hookup(p->next, q);
  x = q->v / 2.0;
  p->v = 0.0;
  p->back->v = 0.0;
  p->next->v = x;
  p->next->back->v = x;
  p->next->next->back->v = x;
  p->next->next->v = x;
  fillin(p->back, p, contin_);
  dummy = evaluate(&curtree);
  do {
    oldlike = curtree.likelihood;
    smooth(p);
    smooth(p->back);
    dummy = evaluate(&curtree);
  } while (fabs(curtree.likelihood - oldlike) > delta);
}  /* insert_ */
Esempio n. 11
0
int			main(int ac, char **av, char **environ)
{
  char			*term;
  int			a;
  t_struct		vals;
  t_booly		*booh;

  vals = checkfonc(ac, vals, av);
  booh = fillin(vals);
  if ((term = getterm(environ)) == NULL)
    return (1);
  a = tgetent(NULL, term);
  if (dogent(a) == 1)
    return (1);
  checkwinsize(&vals);
  fillstruct(&vals);
  tputs(vals.tget->hidecurs, 1, my_putchar);
  tputs(vals.tget->clears, 1, my_putchar);
  afffile(vals, booh);
  makeread(vals, booh);
  return (0);
}
Esempio n. 12
0
File: main.c Progetto: aahud/harvey
/*
 *  massage tree so that all paths from the root to a leaf
 *  contain a filter node for each header.
 *
 *  also, set f->pr where possible
 */
Filter*
complete(Filter *f, Proto *last)
{
	Proto *pr;

	if(f == nil)
		return f;

	/* do a depth first traversal of the filter tree */
	switch(f->op){
	case '!':
		f->l = complete(f->l, last);
		break;
	case LAND:
	case LOR:
		f->l = complete(f->l, last);
		f->r = complete(f->r, last);
		break;
	case '=':
		break;
	case WORD:
		pr = findproto(f->s);
		f->pr = pr;
		if(pr == nil){
			if(f->l != nil){
				fprint(2, "%s unknown proto, ignoring params\n",
					f->s);
				f->l = nil;
			}
		} else {
			f->l = complete(f->l, pr);
			f = fillin(f, last);
			if(f == nil)
				sysfatal("internal error: can't get to %s", pr->name);
		}
		break;
	}
	return f;
}
Esempio n. 13
0
/*_____________________________________________________________________________________*/
void wzq::checkgo(int x,int y,bool color,int num,int inx,int iny)//预测函数 
{
	wzq::trygo[x][y] = (char)color + 1;
	clear(true);
	fillin(color,true,true);
	fillin(!color,true,false);
	CPoint temp = get_victory(true);
	bool four1 = false, four2 = false, three1 = false,three2 = false;
	bool four3 = false, four4 = false, three3 = false,three4 = false;
	for (int i = 0; i <= 3; i++)
	{
		if (user[temp.x][temp.y][i] >= 3 && user[temp.x][temp.y][i] <= 5)
		{
			wzq::nicest[inx][iny] = 2;//lose 
			return;
		}
		else
		{
			if (user[temp.x][temp.y][i] < 3)//win
			{
				wzq::nicest[inx][iny] = 1;
				return;
			}
			else
			{
				if (user[temp.x][temp.y][i] >= 6 && user[temp.x][temp.y][i] <= 14)
				{
					if(four1 == true)
						four2=true;
					else 
						four1=true;
				}
				else
				{
					if (user[temp.x][temp.y][i] >= 15 && user[temp.x][temp.y][i] <= 23)
					{
							if(four3==true)
								four4=true;
							else 
								four3=true;
					}
					else
					{
						if (user[temp.x][temp.y][i] == 24 || user[temp.x][temp.y][i] == 25)
						{
								if(three1==true)
									three2=true;
								else 
									three1=true;
						}
						else
						{
							if (user[temp.x][temp.y][i] == 26 || user[temp.x][temp.y][i] == 27)
							{		
								if(three3 == true)
									three4 = true;
								else
									three3 = true;
							}
						}
					}
				}
			}
		}
	}
	/*++此处添加更多的胜败判断++*/
	if (three1 + three2 + four1 + four2 >= 2)
	{
		wzq::nicest[inx][iny] = 1;//lose
		return;
	}
	else
	{
		if (three3+three4+four3+four4>=2)
		{
			wzq::nicest[inx][iny] = 2;//win
			return;
		}
	}
	if (num >= wzq::aitype2)
	{
		wzq::nicest[inx][iny] = 3;
		return;
	}
	int xxx = num + 1;
	checkgo(temp.x,temp.y,!color,xxx,inx,iny);
}