Archive

Posts Tagged ‘ETG – Spacecraft’

Second Task, First Problem

October 30, 2007 Leave a comment

Well my first task(seen below) was completed without any problems. I made several modifications to make everything correct, and turned it in. Now during the meeting on Monday, I was given my next task. Not as interesting sounding as my first, but here it is:

Refine CTPString class : The class needs to be well documented and made compatible with the std::string class.

This means I will be editing the code, so I need to familiarize myself with the engine and all the components. Therein lies the problem. After 2 hours of trying to force Visual Studio C++ Express Edition to work, we walked away unsuccessful. We had to load all these projects into VC++ and get them to compile and run, but for some reason it didn’t want to work on my machine. The guy who was helping me seems to think he might have found the problem, so we will try again soon.

As for the task itself, I was told I need to study “cyclic redundancy check,” or CRC32 specifically to solve this task. Interesting.

Advertisements

New Team, New Task

October 26, 2007 1 comment

UPDATED 10/29/07: Added guard to remove same first name used as middle name.

So I finally got myself into a project, you can check out an unattended, intended for public viewing page here.

My first assignment is this:

This tool will simply automate the task of producing a long list of trivial character names for the game; by mixing a list of first, second and last names to form unique male and female names for use. No interface is necessary, it should just load XML/INI or other data formats within a fixed file containing the individual names and should create a new file containing the long list of full names.

So the program will read in 3 files: male first names, female first names, and male last names. Now the output will be:

female names in the form of [female first name] + [male first name (used as a middle name)] + [male last name], and
male names in the form [male first name] + [male first name (used as a middle name)] + [male last name].

The program will create every possibility, store them in a vector, then shuffle the vector. After submission and review, here is my final solution:

#include “stdafx.h”

void printFemale(string);
void printMale(string);

ofstream of_completeFemaleNames (“completeFemaleNames.txt”);
ofstream of_completeMaleNames (“completeMaleNames.txt”);

int _tmain(int argc, _TCHAR* argv[])
{
srand(time(NULL));

ifstream if_femaleNames (“femaleNames.txt”);
ifstream if_maleNames (“maleNames.txt”);
ifstream if_malelastNames (“malelastNames.txt”);

vector v_femaleNames;
vector v_maleNames;
vector v_mLastNames;
vector v_completeFemaleNames;
vector v_completeMaleNames;

if(if_femaleNames.is_open())
{
string name;
while( getline(if_femaleNames, name) )
v_femaleNames.push_back(name);
if_femaleNames.close();
}

if(if_maleNames.is_open())
{
string name;
while( getline(if_maleNames, name) )
v_maleNames.push_back(name);
if_maleNames.close();
}

if(if_malelastNames.is_open())
{
string name;
while( getline(if_malelastNames, name) )
v_mLastNames.push_back(name);
if_malelastNames.close();
}

// Create iterators to grab the names
vector::iterator iter1;
vector::iterator iter2;
vector::iterator iter3;

// For each female name, append a male middle name and a male last name
for(iter1 = v_femaleNames.begin(); iter1 != v_femaleNames.end(); ++iter1)
{
string name = *iter1;

for(iter2 = v_maleNames.begin(); iter2 != v_maleNames.end(); ++iter2)
{
name += ” ” + *iter2;

for(iter3 = v_mLastNames.begin(); iter3 != v_mLastNames.end(); ++iter3)
{
v_completeFemaleNames.push_back(name + ” ” + *iter3);
}

name = *iter1;
}
}

// Shuffle the completed female names
random_shuffle(v_completeFemaleNames.begin(), v_completeFemaleNames.end());

// And print them to the output file
for_each(v_completeFemaleNames.begin(), v_completeFemaleNames.end(), printFemale);

// For each male name, append a male middle name and male last name
for(iter1 = v_maleNames.begin(); iter1 != v_maleNames.end(); ++iter1)
{
string name = *iter1;

for(iter2 = v_maleNames.begin(); iter2 != v_maleNames.end(); ++iter2)
{
// This will remove the same First Name being used as the Middle Name
if(*iter2 == name) continue;

name += ” ” + *iter2;

for(iter3 = v_mLastNames.begin(); iter3 != v_mLastNames.end(); ++iter3)
{
v_completeMaleNames.push_back(name + ” ” + *iter3);
}

name = *iter1;
}
}

// Shuffle the completed male names
random_shuffle(v_completeMaleNames.begin(), v_completeMaleNames.end());

// And print them to the output file
for_each(v_completeMaleNames.begin(), v_completeMaleNames.end(), printMale);

return 0;
}

void printFemale(string s)
{
of_completeFemaleNames << s << endl; } void printMale(string s) { of_completeMaleNames << s << endl; }[/sourcecode]