MyLife.hx

enum Gender
{
	male;
	female;
}

class Human implements Dynamic
{
	public var ownFamilly	: Hash<Human>;
	
	var nativeFamilly	: Hash<Human>;
	var gender 			: Gender;	
	var lifeEqualizer	: Array<Float>;
	var partnerTypeId	: Int;
	
	public function new( gender : Gender )
	{
		this.gender = gender;
		nativeFamilly = new Hash();
		ownFamilly = new Hash();
		nativeFamilly.set( "child", this );
		ownFamilly.set( if ( gender == male ) "father" else "mother", this ); 
		
		var complexity = Math.round( Math.random() * 90 ) + 10;
		for ( i in 0...complexity )
			lifeEqualizer.push( Math.round( Math.random() * 100 ) );
		partnerTypeId = Math.round( Math.random() * complexity );
	}
	
	public function fillOwnFamilly()
	{
		if ( !( ownFamilly.exists( "father" ) && ownFamilly.exists( "mother" ) ) )
			return;
		
		var nbrBb = Math.ceil( Math.random() * 5 );
		for ( i in 0...nbrBb )
		{	
			var gender = if ( Math.random() < 0.5 ) male else female;
			ownFamilly.set( "child" + Lambda.count( ownFamilly ), new Human( gender ) );
		}
	}
	
	public function findPartner()
	{
		var preference = lifeEqualizer[ partnerTypeId ];
		var partnerId = Math.round( Math.random() * 100 );
		if ( Math.abs( preference - partnerId ) > 5 )
			findPartner();
		else
			ownFamilly.set( if ( gender == male ) "mother" else "father", this ); 
	}
	
	public function toString()
	{
		return "[object Human(" + gender + ")]";
	}
}

class MyLife
{
	static function main()
	{
		var michel = new Human( male );
		michel.findPartner();
		Happiness.apply( michel.ownFamilly.get( "mother" ), Math.ceil( Math.POSITIVE_INFINITY * 7 ) );
		Happiness.apply( michel, Math.ceil( Math.POSITIVE_INFINITY * 7 ) );
		michel.fillOwnFamilly();
		for ( i in michel.ownFamilly )
			Happiness.apply( i, Math.ceil( Math.POSITIVE_INFINITY * 7 ) );
	}
}

class Happiness
{
	public static function apply( target : Human, n : Int )
	{
		for ( i in 0...n )
		{
			target.endorphin += i;
		}
	}
}