home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / TIERRA40.ZIP / BEAGLE / TSCRAMBL.TXT < prev   
Text File  |  1992-05-30  |  4KB  |  177 lines

  1. /*-----------------------------------------------------------------------*/
  2. extern void PrintInstDist P_((I32s n));
  3. extern void Scramble P_((void));
  4. extern void ScanSoup P_((void));
  5.  
  6.  
  7. /*-----------------------------------------------------------------------*/
  8. void ScanSoup()
  9. {
  10.    I32s si ,p;
  11.  
  12.    for(si = 0; si < INSTNUM; InstD[si++]=0);    /* clean struct bzero ? */
  13.    InstD[INSTNUM] = -1;    /* max hits */
  14.    for(si = 0; si < SoupSize; si++)
  15.       {
  16. #if PLOIDY == 1
  17.       if((InstD[soup[si].inst]++) > InstD[INSTNUM]);
  18.         InstD[INSTNUM] = InstD[soup[si].inst];
  19. #else /* PLOIDY > 1 */
  20.       for(p = 0; p < PLOIDY; p++)
  21.      {
  22.          if((InstD[soup[si][p].inst]++) > InstD[INSTNUM]);
  23.         InstD[INSTNUM] = InstD[soup[si][p].inst];
  24.  
  25.      }
  26. #endif /* PLOIDY > 1 */
  27.       }
  28. }
  29. /*-----------------------------------------------------------------------*/
  30. void PrintInstDist(n)
  31. I32s n;    /* number of lines to print */
  32. {
  33. I32s di,siz,ci,y,total,n_star;
  34. total = 0;
  35. siz = ( n > INSTNUM ) ? INSTNUM : n ;    
  36. siz = ( siz > fe_lines-2 ) ? fe_lines-2 : siz ;    
  37.  
  38. for (y = MSG_Y,di = 0; di < INSTNUM; di++)
  39.    {
  40.  
  41.      if (InstD[di] < 0) break;
  42.      if ((di > 0) && !(di % siz) ) 
  43.         {
  44.         y=MSG_Y;
  45.         FEPrintf(HLP_X,HLP_Y,1,"Press any key for more ...\n");
  46.         FEGetc(); 
  47.         }
  48.      total += InstD[di];
  49.      y = MSG_Y + (di % siz);
  50.      n_star =  1 + (I32s) ((fe_width-15) *
  51.        ( (float)(InstD[di])
  52.         /(float)(InstD[INSTNUM])));    /* max count */
  53.      FEPrintf(MSG_X,y,0,"%7.7s %2.2x %6d|",
  54.            id[di].mn, id[di].op, InstD[di]);
  55.      for (ci = 0; ci < n_star; ci++)
  56.          FEPrintf(MSG_X+18+ci,y,0,"*");
  57.     FEPrintf(MSG_X+18+ci,y,0,"\n");
  58.     }
  59. FEPrintf(MSG_X,y+1 ,0,"Total  --> %6ld\n",total);
  60. FEClrmsg(y+2);
  61.    
  62. }
  63. /*-----------------------------------------------------------------------*/
  64. void Scramble()
  65. {
  66. /* things to do:
  67.     make sure dropdead = 0 -> ignore ...
  68.     turn genebanker off ...
  69.     find prop of SoupSize    (remember ploidy )
  70.     for each soup[] place down a piece 
  71. */
  72. I32s si,i,p,tssiz;
  73. float rr,id_prop[INSTNUM];
  74.  
  75. if (GeneBnker) 
  76.   {
  77.   FEError(-110,NOEXIT,NOWRITE,"Can't Scramble soup with GeneBnker on !");
  78.   return;
  79.   }
  80.  
  81. sprintf(mes[0],
  82. "About to Scramble Soup - are you willing to exercise this control ?"
  83. );
  84. FEMessage(1,mes);
  85. if (FEGetc() != 'y') return;
  86.  
  87. DropDead = 0;
  88. sprintf(mes[0],
  89. "Scrambling Soup - come on!, baby needs a new pair of shoes !..."
  90. );
  91. FEMessage(1,mes);
  92.  
  93. tssiz = PLOIDY * SoupSize;
  94.  
  95. /* calc proportions for redistribution ... */
  96. for(p = 0; p < INSTNUM ; p++)
  97.    {
  98.    id_prop[p] = ((float)  InstD[p]) / ( (float )tssiz); /* anal ... */
  99.    if(p) id_prop[p] += id_prop[p - 1];
  100.    }
  101.  
  102.    for(si = 0; si < SoupSize; si++)
  103.       {
  104.       soup[si].write = tlrand() % 2;
  105.       } 
  106.    for(si = 0; si < SoupSize; si++)
  107.       {
  108. #if PLOIDY > 1
  109.       for(p = 0; p < PLOIDY; p++)
  110.      {
  111. #endif /* PLOIDY > 1 */
  112.       rr = (float)tdrand();
  113.       for(i = 0; i < INSTNUM; i++)
  114.       {   if(rr < id_prop[i]) break;
  115.       }
  116. #if PLOIDY ==  1
  117.       soup[si].inst = (int) i;
  118. #else
  119.       soup[si][p].inst = (int) i;
  120.      }
  121. #endif /* PLOIDY > 1 */
  122.       }
  123. }
  124. /*-----------------------------------------------------------------------*/
  125. /*-----------------------------------------------------------------------*/
  126. void query_bits(bstr)
  127. I8s bstr[32];
  128. {
  129. I32s si,gi,num_hits;
  130.  
  131. if(!GeneBnker) return;
  132. if ((Bits = (BitsType *) thcalloc((NumGenotype+1) , sizeof(BitsType) )) 
  133.     == (BitsType *) NULL)
  134.    {
  135.    FEError(-170,NOEXIT,NOWRITE,
  136.       "Not enough memory to create bits table");
  137.     return;
  138.    }
  139.  
  140. for(num_hits=0,si=0;si < siz_sl; si++)    /* for all sizes */
  141.    {
  142.    if ((I32s)sl[si]->g < 4) continue;
  143.    for(gi=0;si < sl[si]->num_c; gi++)    /* for all geneotypes */
  144.       {
  145.       if ((I32s)sl[si]->g[gi] < 4) continue;
  146.       if (IsInBitSet(bstr,sl[si]->g[gi]->bits))
  147.      {
  148.      Bits[num_hits].size = si;
  149.      Bits[num_hits].lbl = gi;
  150.      Bits[num_hits].bits = sl[si]->g[gi]->bits;
  151.      num_hits++;
  152.      }
  153.  
  154.       }
  155.  
  156.    }
  157. }
  158. /*-----------------------------------------------------------------------*/
  159. void IsInBitSet(bstr,bits)
  160. I8s bstr[32];
  161. I32s bits;
  162. {
  163. I32s b,p;
  164. /* WARNING first 2 bits are not watch bits! */
  165. for(b=1,p=0; p < 32;p++, b = b >> 1;)
  166.    {
  167.    if ((bstr[p] == '?') ||
  168.        (bstr[p] == '1' && (b&bits)) ||
  169.        (bstr[p] == '0' && !(b&bits)) )
  170.        continue;
  171.    return 0;
  172.    }
  173. return 1;
  174. }
  175. /*-----------------------------------------------------------------------*/
  176.  
  177.