当前位置: 首页>>代码示例>>C++>>正文


C++ Bot::mass方法代码示例

本文整理汇总了C++中Bot::mass方法的典型用法代码示例。如果您正苦于以下问题:C++ Bot::mass方法的具体用法?C++ Bot::mass怎么用?C++ Bot::mass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bot的用法示例。


在下文中一共展示了Bot::mass方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: writeTeamData

//write team data to file
bool TeamData::writeTeamData(QString filename, Team* team){

   // check if team success
   if (!team){
      return false;
   }
   
   //open the text file, if already exists overwrite
   QFile xmlFile(filename);
   if (xmlFile.open(IO_WriteOnly)){ //file opened as overwrite
      QTextStream ts(&xmlFile);
      QString str;

      //write team tag
      ts << "<team ";
      ts << "name=\"" << team->name() << "\" ";
      ts << "wins=\"" << QString::number(team->wins()) << "\" ";
      ts << "losses=\"" << QString::number(team->losses()) << "\" ";
      ts << "generations=\"" << QString::number(team->generations()) << "\" ";
      ts << "ties=\"" << QString::number(team->ties()) << "\">\n";
      
      //write bot tag
      Bot *b;
      for (unsigned int i = 0; i < team->size(); i++){
         b = team->bot(i); //get bot in sequence
	 ts << "<bot ";
	 ts << "mass=\"" << QString::number(b->mass()) << "\" ";
         ts << "goals=\"" << QString::number(b->goals()) << "\" ";
	 ts << "interceptions=\"" << QString::number(b->interceptions()) << "\">\n";
	 ts << "<gaRule>\n";

	 //write rule tag
	 GARule *r;
	 for (unsigned int j = 0; j < b->ruleSetSize(); j++){
            r = b->rule(j);
	    ts << "<rule ";
	    ts << "teamBall=\"" << QString::number(r->teamBall()) << "\" ";
	    ts << "myBall=\""; (r->myBall()) ? ts << "T" : ts << "F"; ts << "\" ";
	    ts << "fire=\""; (r->fire()) ? ts << "T" : ts << "F";
	    ts << "\" ";
	    ts << "move=\""; (r->move()) ? ts << "T" : ts << "F";
	    ts << "\" ";
	    ts << "turn=\""; (r->turn() == Left) ? ts << "left" :
	                     (r->turn() == Right) ? ts << "right" : ts << "none";
	    ts << "\">\n";
	    
	    //write sensors tag
	    Thing* sen = r->sensors();
	    ts << "<sensors "; 
	    for (unsigned int k = 0; k < 8; k++){
	       QString t;
	       switch(sen[k]) {
	          case Nothing:  t = "nothing"; break;
	          case MyBot:    t = "mybot"; break;
	          case OtherBot: t = "otherbot"; break;
	          case TheBall:  t = "ball"; break;
	          case Wall:     t = "wall"; break;
	          case Net:      t = "net"; break;
	       }//end switch
	       
	       //put the appropriate end tag
               ts << "s" << QString::number(k) << "=\"" << t;
	       if (k < 7){
                  ts << "\" ";
	       }else{
                  ts << "\"/>\n";
	       }//end if
	       
	    }//end putting sensor tag
	    ts << "</rule>\n";
	 }//end for
	 
	 ts << "</gaRule>\n";
	 ts << "</bot>\n";
      }//end for

      ts << "</team>\n"; 
      
      xmlFile.close(); //close file
   }//end if
   return(true);
   
}//end writeTeamData
开发者ID:edlau,项目名称:GABot,代码行数:84,代码来源:teamdata.cpp


注:本文中的Bot::mass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。