i’m working on a virtual village project that is like this. there are 50 men and 50 woman they age and randomly marry with someone, they have kids and when they reach 80 they start to die.
i have a abstract c# class called human:
abstract class Human
{
enum GenderType { Male, Female };
int Age;
bool Alive;
string Name;
GenderType Gender;
Human Father;
Human Mother;
Human Partner;
Human[] Children;
public abstract bool Check(ref List<Human> People, int Index);
}
and two child from Human class called Man and Woman. My question is how can i override Check method in Man/Woman class to be able to detect female/male relatives that is illegal to marry with. for example Mother, sisters, aunts, sisters in law, mothers in law and so on.
Personally I would add helper properties to the base class for the different relationships. Makes the high-level code really easy to follow. You just add new helpers/properties for different relationships as you need them.
Something like this:
I would also put the basic checks, that apply to both male and female, in the
Humanclass and call the base check from the Male and Female checks first (as now shown in code above).I think you will find that most checks apply equally to Male and Female, as the same-sex checking happens early on, so most checks will probably go into the base class
Check.Note: Yes, you can do a lot of this using
yield returninstead of lists, but you also need to take into account the target audience 🙂