예제 #1
0
species create_new_herb_species(ptrdiff_t seed) {
  species result = create_herb_species();
  herb_species* hsp = get_herb_species(result);

  determine_new_plant_materials(&(hsp->materials), seed);
  seed = prng(seed);

  determine_new_herb_appearance(&(hsp->appearance), seed);
  seed = prng(seed);

  hsp->growth.seed_growth.grammar = BIO_CG_SPROUT_IN_SOIL;
  hsp->growth.seed_growth.sprout_time = (
    posmod(prng(seed + 1771), 5)
  + posmod(prng(seed + 311), 8)
  );
  seed = prng(seed);

  // TODO: Real values here...
  hsp->growth.seed_growth_resist = 5;
  hsp->growth.growth_resist = 10;
  hsp->growth.growth_strength = 8;

  determine_new_herb_core_growth(&(hsp->growth.core_growth), seed);

  return result;
}
예제 #2
0
cg_expansion* pick_expansion(
  cell_grammar *cg,
  chunk_neighborhood* nbh,
  block_index base,
  ptrdiff_t seed
) {
  size_t i;
  int success;
  cg_expansion *exp;
  list *options = create_list();
  block root_block = *nb_block(nbh, base);
  for (i = 0; i < l_get_length(cg->expansions); ++i) {
    exp = (cg_expansion*) l_get_item(cg->expansions, i);
    success = check_expansion(exp, nbh, base, root_block);
    if (success) {
      l_append_element(options, (void*) exp);
    }
  }
  if (l_is_empty(options)) {
    cleanup_list(options);
    return NULL;
  }
  // Choose an option based on our seed:
  i = posmod(prng(seed + 819991), l_get_length(options));
  exp = (cg_expansion*) l_get_item(options, i);
  cleanup_list(options);
  return exp;
}
예제 #3
0
double ThreePeriodicMarkovChain::scoreSubsequence(const Sequence &seq,
						  const BOOM::String &str,
						  int begin,int length,
						  int seqPhase)
{
  // ### This is quick and dirty -- will be optimizing this class next week
  //     to use a suffix-tree-like data structure so that each base is
  //     read only once

  double score=0;
  int end=begin+length;

  switch(getStrand())
    {
    case FORWARD_STRAND:
      for(int pos=begin ; pos<end ; ++pos)
	score+=chains[(seqPhase+pos-begin)%3]->
	  scoreSingleBase(seq,str,pos,seq[pos],str[pos]);
      break;
    case REVERSE_STRAND:
      for(int pos=begin ; pos<end ; ++pos)
	score+=chains[posmod(seqPhase-(pos-begin))]->
	  scoreSingleBase(seq,str,pos,seq[pos],str[pos]);
      break;
    }
  return score;
}
예제 #4
0
파일: Edge.C 프로젝트: ReddyLab/FBI
int Edge::propagateBackward(int phase)
{
  if(isIntergenic()) return (left->getStrand()==FORWARD_STRAND ? 0 : 2);
  if(!isCoding()) return phase;
  int length=getFeatureEnd()-getFeatureBegin();
  switch(getStrand())
    {
    case FORWARD_STRAND:
      return posmod(phase-length);
    case REVERSE_STRAND:
      return (phase+length)%3;
    }
}
예제 #5
0
/* Ensure that the contributing source sample is
* within bounds. If not, reflect, clamp, or wrap.
*/
int Resampler::reflect(const int j, const int src_x, const Boundary_Op boundary_op)
{
   int n;

   if (j < 0)
   {
      if (boundary_op == BOUNDARY_REFLECT)
      {
         n = -j;

         if (n >= src_x)
            n = src_x - 1;
      }
      else if (boundary_op == BOUNDARY_WRAP)
         n = posmod(j, src_x);
      else
         n = 0;
   }
   else if (j >= src_x)
   {
      if (boundary_op == BOUNDARY_REFLECT)
      {
         n = (src_x - j) + (src_x - 1);

         if (n < 0)
            n = 0;
      }
      else if (boundary_op == BOUNDARY_WRAP)
         n = posmod(j, src_x);
      else
         n = src_x - 1;
   }
   else
      n = j;

   return n;
}
예제 #6
0
파일: grow.c 프로젝트: solsword/elf_forest
void grow_block(chunk_neighborhood *nbh, block_index idx, ptrdiff_t t) {
  global_pos cell_position;
  chunk *c = nbh->members[NBH_CENTER];
  block *b = c_block(c, idx);
  cidx__glpos(c, &idx, &cell_position);
  ptrdiff_t growth_rate = get_growth_rate(*b);
  ptrdiff_t growth_offset = posmod(cell_hash(&cell_position), growth_rate);
  if (
     (gri_vitality(*b) != GR_VITALITY_DEAD)
  && ((t - growth_offset) % growth_rate == 0)
  ) {
    if (bi_gcore(*b)) {
      grow_from_core(nbh, idx);
    } else if (bi_gsite(*b)) {
      grow_at_site(nbh, idx);
    }
  }
}