void EntityResolver::getEntity(std::basic_ostream<Char>& os, Char ch) const { unsigned u = 0; unsigned o = sizeof(rent)/sizeof(Ent) - 1; while (o - u > 1) { unsigned m = (o + u) / 2; if (rent[m].charValue == ch.value()) { printEntity(os, rent[m].entity); return; } if (ch.value() < rent[m].charValue) o = m; else u = m; } if (rent[u].charValue == ch.value()) printEntity(os, rent[u].entity); else if (rent[o].charValue == ch.value()) printEntity(os, rent[o].entity); else if (ch.value() >= ' ' && ch.value() <= 0x7F) os << ch; else os << Char('&') << Char('#') << static_cast<uint32_t>(ch.value()) << Char(';'); }
void STEPWrapper::printEntityAggregate(STEPaggregate *sa, int level) { std::string strVal; for (int i = 0; i < level; i++) { std::cout << " "; } std::cout << "Aggregate:" << sa->asStr(strVal) << std::endl; EntityNode *sn = (EntityNode *)sa->GetHead(); SDAI_Application_instance *sse; while (sn != NULL) { sse = (SDAI_Application_instance *)sn->node; if (((sse->eDesc->Type() == SET_TYPE) || (sse->eDesc->Type() == LIST_TYPE)) && (sse->eDesc->BaseType() == ENTITY_TYPE)) { printEntityAggregate((STEPaggregate *)sse, level + 2); } else if (sse->eDesc->Type() == ENTITY_TYPE) { printEntity(sse, level + 2); } else { std::cout << "Instance Type not handled:" << std::endl; } //std::cout << "sn - " << sn->asStr(attrval) << std::endl; sn = (EntityNode *)sn->NextNode(); } //std::cout << std::endl << std::endl; }
void initPlayer(entity *playerChar)// i think these init<name> functions should be quite clear { playerChar->representScreen = '@'; playerChar->entityType = TYPE_PLAYER; playerChar->position.xPos = 10; playerChar->position.yPos = 10; playerChar->dead = FALSE; printEntity(playerChar, PAIR_PLAYER); }
int main (int argc, const char * argv[]) { /** * The pole must remain upright within ±r the pole failure angle * The cart must remain within ±h of origin * The controller must always exert a non-zero force F */ /** * The movement of cart and pivot is completely frictionless * The electrical system for response is instantaneous * The wheels of cart do not slip * The motor torque limit is not encountered */ srand(time(NULL)); printf("Pole Balance\n"); Generation g = getRandomGeneration(); printf("\n"); FILE *stream; char output_file[254]; sprintf(output_file, "average_fitness.%i.txt", GENERATION_SIZE); stream = fopen(output_file, "wt"); int i; for (i = 0; i < GENERATION_COUNT; i++) { printf("\rgenerating %0.2f%%", 100 * ((float) i + 1) / (float) GENERATION_COUNT); if (i % 5 == 0 && i == 20) { Entity best = getBestEntity(&g); writeEntity(&best, i, "-best"); Entity worst = getWorstEntity(&g); writeEntity(&worst, i, "-worst"); } fflush(stdout); g = getNextGeneration(&g); fprintf(stream, "%i\t%f\n", i + 1, getGenerationAverageFitness(&g)); } fclose(stream); printf("\nbest solution:\n"); Entity solution = getBestEntity(&g); printEntity(&solution); writeEntity(&solution, i, "-best"); Entity worst = getWorstEntity(&g); writeEntity(&worst, i, "-worst"); return 0; }
void STEPWrapper::printEntity(SDAI_Application_instance *se, int level) { for (int i = 0; i < level; i++) { std::cout << " "; } std::cout << "Entity:" << se->EntityName() << "(" << se->STEPfile_id << ")" << std::endl; for (int i = 0; i < level; i++) { std::cout << " "; } std::cout << "Description:" << se->eDesc->Description() << std::endl; for (int i = 0; i < level; i++) { std::cout << " "; } std::cout << "Entity Type:" << se->eDesc->Type() << std::endl; for (int i = 0; i < level; i++) { std::cout << " "; } std::cout << "Attributes:" << std::endl; STEPattribute *attr; se->ResetAttributes(); while ((attr = se->NextAttribute()) != NULL) { std::string attrval; for (int i = 0; i <= level; i++) { std::cout << " "; } std::cout << attr->Name() << ": " << attr->asStr(attrval) << " TypeName: " << attr->TypeName() << " Type: " << attr->Type() << std::endl; if (attr->Type() == 256) { if (attr->IsDerived()) { for (int i = 0; i <= level; i++) { std::cout << " "; } std::cout << " ********* DERIVED *********" << std::endl; } else { printEntity(*(attr->ptr.c), level + 2); } } else if ((attr->Type() == SET_TYPE) || (attr->Type() == LIST_TYPE)) { STEPaggregate *sa = (STEPaggregate *)(attr->ptr.a); // std::cout << "aggr:" << sa->asStr(attrval) << " BaseType:" << attr->BaseType() << std::endl; if (attr->BaseType() == ENTITY_TYPE) { printEntityAggregate(sa, level + 2); } } } //std::cout << std::endl << std::endl; }
void printEntityList(entity *entityList, int sizeOfList) { int mainLooper = 0; for(mainLooper = 0; mainLooper < sizeOfList; mainLooper++) { if(entityList[mainLooper].dead != TRUE)//why would we print "dead" pits? { if(entityList[mainLooper].entityType == TYPE_ZOMBIE) { printEntity(&entityList[mainLooper], PAIR_DEFAULT); } else if(entityList[mainLooper].entityType == TYPE_PIT) { printEntity(&entityList[mainLooper], PAIR_PIT); } } } }