Exemplo n.º 1
0
//---------------------------------------------------------------------------
long SensorSystem::scanBattlefield (void) 
{
	//NOW returns size of largest contact!
	long currentLargest = -1;
	
	if (!owner)
		Fatal(0, " Sensor has no owner ");

	if (!master)
		Fatal(0, " Sensor has no master ");

	if ((masterIndex == -1) || (range < 0.0))
		return(0);

	long numNewContacts = 0;

	long numMovers = ObjectManager->getNumMovers();
	for (long i = 0; i < numMovers; i++) 
	{
		MoverPtr mover = (MoverPtr)ObjectManager->getMover(i);
		if (mover->getExists() && (mover->getTeamId() != owner->getTeamId())) 
		{
			long contactStatus = calcContactStatus(mover);
			if (isContact(mover)) 
			{
				if (contactStatus == CONTACT_NONE)
					removeContact(mover);
				else
				{
					modifyContact(mover, contactStatus == CONTACT_VISUAL ? true : false);
					getLargest(currentLargest,mover,contactStatus);
				}
			}
			else 
			{
				if (contactStatus != CONTACT_NONE) 
				{
					addContact(mover, contactStatus == CONTACT_VISUAL ? true : false);
					getLargest(currentLargest,mover,contactStatus);
					numNewContacts++;
				}
			}
		}
	}

	totalContacts += numNewContacts;
	
	return(currentLargest);
}
Exemplo n.º 2
0
void printResults(ArtistData artists[], int max, VoteCount c, FILE *out) {
    int j;
    fprintf(out, "\nNumber of voters: %d\n", c.valid + c.spoilt);
    fprintf(out, "Number of valid voters: %d\n", c.valid);
    fprintf(out, "Number of spoilt votes: %d\n", c.spoilt);

    sortByVote(artists, 1, MaxCandidates);
    fprintf(out, "\nBy Score");
    fprintf(out, "\n%-15s\tScore\n\n", "Artist");
    for (j = 1; j <= max; j++) {
        fprintf(out, "%-15s %3d\n", artists[j].name, artists[j].numVotes);
    }

    sortByName(artists, 1, MaxCandidates);
    fprintf(out, "\nBy Name");
    fprintf(out, "\n%-15s\tScore\n\n", "Artist");
    for (j = 1; j <= max; j++) {
        fprintf(out, "%-15s %3d\n", artists[j].name, artists[j].numVotes);
    }
    
    fprintf(out, "\nThe Winner(s)\n");
    int win = getLargest(artists, 1, max);
    int winningVote = artists[win].numVotes;

    for (j = 1; j <= max; j++) {
        if (artists[j].numVotes == winningVote) {
            fprintf(out, "%s\n", artists[j].name);
        }
    }
}
Exemplo n.º 3
0
int main(int argc, char* argv[])
{
  std::string str = "abdc";
  SwapList swp = {{1,4}, {3,4}};

  std::cerr << "Largest string is: " << getLargest(str, swp) << std::endl;
  return 0;
}