void G_parser::store_rules(string& nc){
    
    //new rule
    if (nc=="rule:"){
        //cout << "rules: entered and harn_rh==" << harm_rh << " and form_length==" << form_length << endl;
        all_rules.push_back(rule());
        all_rules[rule_pop].is_optional = false;
        
        nc = get_nc();
        
        //left side
        while(nc!="->"){
            all_rules[rule_pop].left_str.push_back(nc);
            store_opt_data(nc);
            nc = get_nc();
        }
        
        //if (nc!="->") cout << "ERROR in line " << i << ": arrow required" << endl;
        int prod_pop=0;//production population
        
        while(nc!=":end_rule"){//store right_side
            all_rules[rule_pop].right_side.push_back(right_s());
            nc = get_nc();//production probability
            all_rules[rule_pop].right_side[prod_pop].prob = atof(nc.c_str());
            nc = get_nc();
            
            //store right_str
            while(nc!="->" && nc!=":end_rule"){
                all_rules[rule_pop].right_side[prod_pop].right_str.push_back(nc);//={"STR1", "STR2"};//
                nc = get_nc();
            }
            
            prod_pop++;
        }
        
        bool is_timed = false;
        vector<int> rule_time = {0, 0};//{beat, bar}
        
        //categorise (timed vs general)
        for (int i=0; i<all_rules[rule_pop].left_str.size(); i++) {
            
            for (int j=0; j<all_rules[rule_pop].left_str[i].length(); j++){
                
                if (all_rules[rule_pop].left_str[i][j]=='_'){
                    
                    is_timed = true;
                    int left_centre = i;
                    
                    //rule_time.clear();
                    
                    string bar_time_str, beat_time_str; // rule_semiq_str;//could be one variable only
                    j++;
                    
                    while(all_rules[rule_pop].left_str[i][j] != '_' && j<all_rules[rule_pop].left_str[i].length()){
                        bar_time_str.push_back(all_rules[rule_pop].left_str[i][j]);
                        j++;
                    }
                    
                    rule_time[1] = atoi(bar_time_str.c_str()) - 1;
                    
                    if (all_rules[rule_pop].left_str[i][j] == '_'){
                        
                        while (j<all_rules[rule_pop].left_str[i].length()){
                            j++;
                            beat_time_str.push_back(all_rules[rule_pop].left_str[i][j]);
                        }
                        
                        rule_time[0] = atoi(beat_time_str.c_str()) - 1;
                        
                    } else rule_time[0] = 0;
                    
                    all_rules[rule_pop].leftmost_time =  {rule_time[0], rule_time[1] - (i / harm_rh)};
                    
                    //exclude "_*.."
                    all_rules[rule_pop].left_str[i] = exclude_time(all_rules[rule_pop].left_str[i]);
                    
                    //existing_rules.push_back();
                    break;
                    
                } else all_rules[rule_pop].leftmost_time = {0, 0};
                
            }
            
            if (is_timed) break;
            
        }
        
        all_rules[rule_pop].timed = is_timed;
        
        if (is_timed) {
            //cout << "rule_time: " << rule_time[0] << " " << rule_time[1] << endl;
            existing_times.push_back(rule_time);//to test existence of rule_time, ELSE general_rules
            timed_rules[rule_time].push_back(all_rules[rule_pop]);
            
        } else {
            
            general_rules.push_back(all_rules[rule_pop]);
            //cout << "general rule" << endl;
        }
        
        rule_pop++;
    }
}
Exemplo n.º 2
0
__RAMFUNC void Scan()
{
    int i = 0,j = 0,part_num = 0;
    uint16 x[10] = {0},y[60] = {0};
    uint8 center_x = 0,center_y = 0;
    /*************模式1**************/
    if(model == 0)
    {
        /*************不解压**************/
        if(model == 0)
        {
          for(i = 0;i < 10; i++)
            for(j = 0;j < 60; j++)
               x[i] += imgbuff[j*10 + i];
          for(i = 0;i < 9;i++)
          {
             if(x[i+1] < x[i])
               center_x = i+1;
          }
          if(center_x == 0 && x[center_x] == 15300)
          {         
              if(speed_out > SPEED_SLOW)
              {
                speed_out = SPEED_SLOW;
                go();
              }
              if(steer_mid != STEER_RIGHT_MAX)
               right();
          }
          else
          {
             if(center_x < 1)
             {
                 left_s(center_x);
             }
             else if(center_x > 4)
             {
                 right_s(center_x);
             }
             else go_s();
//             wdog_feed();
          }
        }
        /*************解压*************/
        else
        {
          for(i = 0;i < 10;i++)
            y[0] += imgbuff[i];
          for(i = 1;i < 60; i++)
          {
            for(j = 0;j < 10; j++)
              y[i] += imgbuff[i*10 + j];
            if(y[i] < y[i - 1])
              center_y = i;
          }      
          if(center_y == 0 && y[center_y] == 15300)
          {         
              if(speed_out > SPEED_SLOW)
              {
                speed_out = SPEED_SLOW;
                go();
              }
              if(steer_mid != STEER_LEFT_MAX)
               left();
          }
          else
          {
            uint8 l = 0,r = 9;
            for(i = 0;i < 10 ;i++)
              if(imgbuff[center_y*10 + i] < 0xFF){l = i;break;}
            for(;i < 10;i++)
              if(imgbuff[center_y*10 + i] == 0xFF){r = i - 1;break;}
            uint8 l_8 = imgbuff[center_y + l],r_8 = imgbuff[center_y + r];
            for(i = 0;i < 8;i++)
              if((l_8 << i) & 0x80 == 1)
                break;
            l = l * 8 + i - 1;
            for(i = 0;i < 8;i++)
              if((r_8 >> i) & 0x01 == 1)
                break;
            r = r * 8 - i + 1;
            center_x = (l + r) / 2;   
            turn_s(center_x);
//            wdog_feed();
          }
        }
    }
    else if(model == 1)