Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FamilyTreeMember.cfc
- <!----------------------
- Description: FamilyTreeMember
- Author: Dan Wilson (dan@nodans.com)
- Date: 9/23/2011
- CHANGE LOG:
- ------------------------>
- <cfcomponent output="false">
- <cfset variables.config.AttractiveScoreLow = 40 />
- <cfset variables.config.AttractiveScoreHigh = 80 />
- <cfset variables.config.EarliestRecords = createdate(1876, 4, 25) />
- <cfset variables.config.FertilityLow = 30 />
- <cfset variables.config.FertilityHigh = 70 />
- <cfset variables.config.FirstNameArrayMale = ["Adan","Adolfo","Alejandro","Alfonso","Alfredo","Alonso","Alonzo","Alvaro","Andres","Armando","Belen","Bernar","Carlos","Carmelo","Cesar","Cortez","Cruz","Dario","Diego","Emilio","Enrique","Ernesto","Esteban","Estevan","Felipe","Fernando","Francisco","Gerardo","Gilberto","Gonzalo","Guillermo","Gustavo","Itzel"] />
- <cfset variables.config.FirstNameArrayFemale = ["Alejandra","Alondra","Ana","Belinda","Brisa","Catalina","Elisa","Esmeralda","Esperanza","Estefani","Eduardo","Izabella","Jada","Jade","Isabel","Jaquinda","Jardena","Javiera","Jayda","Jayde","Jerusalen","Jesusa","Josefina","Josune","Joyceta","Juana","Juandalyn","Juliana","Julita","Justiniana"] />
- <cfset variables.config.SurnameArray = ["Aguilar","Alcaraz","Alejandro","Almaraz","Almonte","Alva","Alvarado","Aparicio","Apodaca","Archuleta","Arella","Arenas","Barrios","Batista","Benavidez","Caballero","Calvillo","Canales","Carbajal","Cardenas","Carrasquillo","Casanova","Casares","Cavazos","Duenas","Duran","Echevarria","Fierro","Garica","Gurule","Jaquez","Llamas","Malave","Mendez","Montoya","Nieto","Orosco","Patino","Puente","Regalado","Roldan","Saldana","Sevilla","Teran","Vaca","Velez","Zambrano"] />
- <cfset variables.config.MarriageAgeLow = 26 />
- <cfset variables.config.MarriageAgeHigh = 42 />
- <cfset variables.config.PossibleChildrenBaseline = 3 />
- <cfset variables.familytree.patriarch = "" />
- <cfset variables.familytree.results = [] />
- <cffunction name="init" access="public" returntype="FamilyTree">
- <cfreturn this />
- </cffunction>
- <!--- Date: 9/23/2011 Usage: I create the family tree and allow for economic conditions to affect the outcomes --->
- <cffunction name="createFamilyTree" output="false" access="public" returntype="any" hint="I create the family tree and allow for economic conditions to affect the outcomes">
- <cfargument name="EconomicConditions" type="numeric" required="true" hint="0-100 scale where 0 is horror and famine, and 100 is bounty and riches"/>
- <cfset var multiplier = ( EconomicConditions - 50 )/100 />
- <!--- Adjust our Family outlook based on Economic Conditions --->
- <cfset variables.config.MarriageAgeLow = variables.config.MarriageAgeLow - variables.config.MarriageAgeLow * multiplier />
- <cfset variables.config.MarriageAgeHigh = variables.config.MarriageAgeHigh + variables.config.MarriageAgeHigh * multiplier />
- <cfset variables.config.FertilityLow = variables.config.FertilityLow - variables.config.FertilityLow * multiplier />
- <cfset variables.config.FertilityHigh = variables.config.FertilityHigh + variables.config.FertilityHigh * multiplier />
- <cfset variables.config.AttractiveScoreLow = variables.config.AttractiveScoreLow - variables.config.AttractiveScoreLow * multiplier />
- <cfset variables.config.AttractiveScoreHigh = variables.config.AttractiveScoreHigh + variables.config.AttractiveScoreHigh * multiplier />
- <cfset variables.config.PossibleChildrenBaseline = variables.config.PossibleChildrenBaseline + variables.config.PossibleChildrenBaseline* multiplier />
- <!--- Start Procreating --->
- <cfset variables.familytree.patriarch = definePatriarchNode() />
- <cfset makeGeneration( variables.familytree.patriarch, true ) />
- </cffunction>
- <!--- Date: 9/23/2011 Usage: I display the family tree --->
- <cffunction name="display" output="false" access="public" returntype="any" hint="I display the family tree">
- <cfargument name="EconomicConditions" type="numeric" required="true" hint="0-100 scale where 0 is horror and famine, and 100 is bounty and riches"/>
- <cfset createFamilyTree( arguments.EconomicConditions ) />
- <cfreturn variables.familytree.patriarch.makeSnapshot() />
- </cffunction>
- <!--- Don't Touch My Privates --->
- <cffunction name="definePatriarchNode" output="false" access="private" returntype="any" hint="I define the patriarchs">
- <cfset var partiarchConfig = duplicate( getConfig() ) />
- <cfset var patriarch = {
- birthday=variables.config.EarliestRecords,
- firstName=pickMaleName(),
- lastName=pickSurname(),
- isMale=1
- } />
- <cfset var matriarch = {
- birthday=variables.config.EarliestRecords,
- firstName=pickFemaleName(),
- lastName=pickSurname(),
- isMale=0
- } />
- <cfset patriarch = makePerson( argumentcollection:patriarch ) />
- <cfset matriarch = makePerson( argumentcollection:matriarch ) />
- <cfreturn makeNode( patriarch, matriarch ) />
- </cffunction>
- <cffunction name="getConfig" output="false" access="private" returntype="struct" hint="">
- <cfreturn variables.config />
- </cffunction>
- <cffunction name="makeGeneration" output="false" access="private" returntype="void" hint="I make the family tree">
- <cfargument name="ParentNode" type="FamilyTreeNode" required="true"/>
- <cfargument name="IsPatriarch" type="boolean" default="false"/>
- <cfset var config = getConfig() />
- <cfset var ParentNodeKidsCount = arguments.ParentNode.getNakedAndBusy( config ) />
- <cfset var RollOfTheDice = 0 />
- <cfset var KidConfig = {} />
- <cfset var SpouseConfig = {} />
- <cfset var ParentBirthday = arguments.ParentNode.getSomeBirthDate() />
- <cfset var KidSurname = arguments.ParentNode.getSurnameForKid() />
- <cfset var Kid = "" />
- <cfset var Spouse = "" />
- <cfset var NewFamilyNode = "" />
- <cfset var i = "" />
- <cfset var thisKid = "" />
- <!--- Patriatchs with no kids make for boring family trees... --->
- <cfif arguments.IsPatriarch IS true >
- <cfset ParentNodeKidsCount = variables.config.PossibleChildrenBaseline />
- </cfif>
- <cfloop from="1" to="#Min(6, ParentNodeKidsCount)#" index="i">
- <!--- Let's see what fate has brought to these folks --->
- <cfset RollOfTheDice = RandRange( 1, 100 ) />
- <cfset KidConfig = {
- birthday=DateAdd( "yyyy", RandRange(variables.config.MarriageAgeLow, variables.config.MarriageAgeHigh ), ParentBirthday ),
- firstName=pickName(RollOfTheDice MOD 2 IS 1),
- lastName=KidSurname,
- isMale=RollOfTheDice MOD 2
- } />
- <!--- No kids born in the future... --->
- <cfif KidConfig.birthday LT now()>
- <cfset Kid = makePerson( argumentcollection:KidConfig ) />
- <!--- If fate has made this person attractive enough, we'll let them get married. Else, may they die alone and sad. (With lots of cats) --->
- <cfif RollOfTheDice GTE variables.config.AttractiveScoreLow AND RollOfTheDice LTE variables.config.AttractiveScoreHigh>
- <cfset SpouseConfig = {
- birthday=DateAdd("yyyy", -2.5, KidConfig.birthday),
- firstName=pickName(RollOfTheDice MOD 2 IS 0),
- lastName=pickSurname(),
- isMale=RollOfTheDice MOD 2
- } />
- <cfset Spouse = makePerson( argumentcollection:SpouseConfig ) />
- </cfif>
- <cfset NewFamilyNode = makeNode( Kid, Spouse ) />
- <cfset ParentNode.onStorkVisit( NewFamilyNode ) />
- </cfif>
- </cfloop>
- <cfset makeNextGeneration( ParentNode ) />
- </cffunction>
- <cffunction name="makeNextGeneration" output="false" access="private" returntype="void" hint="I make the next generation from a parent node">
- <cfargument name="ParentNode" type="FamilyTreeNode" required="true"/>
- <cfset var KidArray = ParentNode.getKids() />
- <cfset var thisKid = "" />
- <cfloop array="#KidArray#" index="thisKid">
- <cfset makeGeneration( thisKid ) />
- </cfloop>
- </cffunction>
- <cffunction name="makeNode" output="false" access="private" returntype="FamilyTreeNode" hint="I make a family node">
- <cfargument name="Man" type="any" required="false"/>
- <cfargument name="Woman" type="any" required="false"/>
- <cfreturn createobject("component", "FamilyTreeNode").init(argumentcollection:arguments) />
- </cffunction>
- <cffunction name="makePerson" output="false" access="private" returntype="Person" hint="I make a person as described">
- <cfargument name="Birthday" type="string" default=""/>
- <cfargument name="FirstName" type="string" default=""/>
- <cfargument name="LastName" type="string" default=""/>
- <cfargument name="MaidenName" type="string" default=""/>
- <cfargument name="Gender" type="string" default=""/>
- <cfargument name="IsMale" type="string" default=""/>
- <cfargument name="LoadChildren" type="string" default=""/>
- <cfargument name="NumberOfChildren" type="string" default=""/>
- <cfargument name="ParentPerson" type="string" default=""/>
- <cfreturn createobject("component", "Person").init( argumentcollection:arguments) />
- </cffunction>
- <cffunction name="pickName" output="false" access="private" returntype="string" hint="I help pick a gender appropriate name">
- <cfargument name="NeedMale" type="boolean" required="true"/>
- <cfset var newName = pickFemaleName() />
- <cfif arguments.NeedMale IS true>
- <cfset newName = pickMaleName() />
- </cfif>
- <cfreturn newName />
- </cffunction>
- <cffunction name="pickFemaleName" output="false" access="private" returntype="string" hint="I pick a new female name">
- <cfreturn variables.config.FirstNameArrayFemale[ randRange(1, arrayLen( variables.config.FirstNameArrayFemale ) ) ] />
- </cffunction>
- <cffunction name="pickMaleName" output="false" access="private" returntype="string" hint="I pick a new male name">
- <cfreturn variables.config.FirstNameArrayMale[ randRange(1, arrayLen( variables.config.FirstNameArrayMale ) ) ] />
- </cffunction>
- <cffunction name="pickSurname" output="false" access="private" returntype="string" hint="I pick a new surname">
- <cfreturn variables.config.SurnameArray[ randRange(1, arrayLen( variables.config.SurnameArray ) ) ] />
- </cffunction>
- </cfcomponent>
- ===============================END FamilyTree.cfc ======================
- FamilyTreeNode.cfc
- <!----------------------
- Description: FamilyTreeNode
- Author: Dan Wilson (dan@nodans.com)
- Date: 9/23/2011
- CHANGE LOG:
- ------------------------>
- <cfcomponent output="false">
- <cfset variables.family.man = "" />
- <cfset variables.family.woman = "" />
- <cfset variables.family.kids = [] />
- <cffunction name="init" access="public" returntype="FamilyTreeNode">
- <cfargument name="Man" type="any" required="true"/>
- <cfargument name="Woman" type="any" required="true"/>
- <cfif isObject( arguments.Man ) IS true>
- <cfset variables.family.man = arguments.man />
- </cfif>
- <cfif isObject( arguments.Woman ) IS true>
- <cfset variables.family.woman = arguments.woman />
- </cfif>
- <cfreturn this />
- </cffunction>
- <cffunction name="loadNameDetails" output="false" access="public" returntype="any" hint="I make the details about this node">
- <cfset var details = "" />
- <cfset var ManName = "" />
- <cfset var WomanName = "" />
- <cfif hasMan() IS true>
- <cfset ManName = variables.family.man.getFirstName() />
- </cfif>
- <cfif hasWoman() IS true>
- <cfset WomanName = variables.family.woman.getFirstName() />
- </cfif>
- <cfif isMarried() IS true>
- <cfset details = "#ManName# married #WomanName#" />
- <cfelse>
- <cfset details = "#ManName# #WomanName# lives alone" />
- </cfif>
- <cfreturn details />
- </cffunction>
- <cffunction name="getKids" output="false" access="public" returntype="any" hint="I return the kids array">
- <cfset var kids = [] />
- <cfif arrayLen( variables.family.kids ) GT 0 >
- <cfset kids = variables.family.kids />
- </cfif>
- <cfreturn kids />
- </cffunction>
- <cffunction name="getMan" access="public" output="false" returntype="any">
- <cfreturn variables.family.Man/>
- </cffunction>
- <cffunction name="getNakedAndBusy" output="false" access="public" returntype="numeric" hint="You know what this does, right?">
- <cfargument name="config" type="struct" required="true"/>
- <cfset var ReturnKidCount = 0 />
- <cfset var RollOfTheDice = randRange( 1, 100) />
- <!--- Having kids take a bit of effort and a bit of luck, will their luck pay off this time? --->
- <cfif isMarried() IS true AND RollOfTheDice GTE arguments.config.FertilityLow AND RollOfTheDice LTE arguments.config.FertilityHigh >
- <cfset ReturnKidCount = Fix( RollOfTheDice/5 ) />
- </cfif>
- <cfreturn ReturnKidCount />
- </cffunction>
- <cffunction name="getSomeBirthDate" output="false" access="public" returntype="string" hint="I get a birthday by any means necessary">
- <cfset var returnDate= now() />
- <cfif hasWoman() IS true>
- <cfset returnDate = getWoman().getBirthday() />
- <cfelseif hasMan() IS true>
- <cfset returnDate = getMan().getBirthday() />
- </cfif>
- <cfreturn returnDate />
- </cffunction>
- <cffunction name="getSurnameForKid" access="public" output="false" returntype="string">
- <cfset var newSurname = "" />
- <cfif isMarried() IS true>
- <cfset newSurname = "#listFirst( getMan().getLastName(), "-" )#-#listFirst( getWoman().getLastName(), "-" )#" />
- </cfif>
- <cfreturn newSurname />
- </cffunction>
- <cffunction name="getWoman" access="public" output="false" returntype="any">
- <cfreturn variables.family.Woman/>
- </cffunction>
- <cffunction name="hasKids" output="false" access="public" returntype="boolean" hint="I figure out whether there are kids">
- <cfreturn arrayLen( variables.family.kids ) GT 0 />
- </cffunction>
- <cffunction name="hasMan" output="false" access="public" returntype="any" hint="I check to see if there is a male member of this node">
- <cfreturn isObject( variables.family.man ) IS true/>
- </cffunction>
- <cffunction name="hasWoman" output="false" access="public" returntype="any" hint="I check to see if there is a female member of this node">
- <cfreturn isObject( variables.family.woman ) IS true />
- </cffunction>
- <cffunction name="isMarried" output="false" access="public" returntype="boolean" hint="I figure out whether this node is married">
- <cfreturn hasMan() IS true and hasWoman() IS true />
- </cffunction>
- <cffunction name="makeSnapshot" output="false" access="public" returntype="any" hint="I make a snapshot">
- <cfargument name="OurFamilyTree" type="any" default="#structNew()#"/>
- <cfset var thisKid = "" />
- <cfset arguments.OurFamilyTree["1DisplayName"] = "#loadNameDetails()#" />
- <cfset arguments.OurFamilyTree["4Kids"] = "No Kids" />
- <cfset arguments.OurFamilyTree["5KidsArray"] = [] />
- <cfloop array="#getKids()#" index="thisKid">
- <cfset arguments.OurFamilyTree["4Kids"] = arrayLen( getKids() ) />
- <cfset arrayAppend( arguments.OurFamilyTree["5KidsArray"], thisKid.makeSnapshot() ) />
- </cfloop>
- <cfif hasMan() IS true>
- <cfset arguments.OurFamilyTree["2Man"] = getMan().makeSnapshot() />
- </cfif>
- <cfif hasWoman() IS true>
- <cfset arguments.OurFamilyTree["3Woman"] = getWoman().makeSnapshot() />
- </cfif>
- <cfreturn arguments />
- </cffunction>
- <cffunction name="onStorkVisit" output="false" access="public" returntype="void" hint="I handle a visit from the stork">
- <cfargument name="bundleOfJoy" type="any" required="true"/>
- <cfset arrayAppend( variables.family.kids, arguments.bundleOfJoy ) />
- </cffunction>
- </cfcomponent>
- ===============================END FamilyTreeNode.cfc ======================
- Person.cfc
- <!----------------------
- Description: Person
- Author: Dan Wilson (dan@nodans.com)
- Date: 9/23/2011
- CHANGE LOG:
- BirthDay
- FirstName
- LastName
- Gender
- IsMale
- LoadChildren
- NumberOfChildren
- ParentPerson
- SpousePerson
- ------------------------>
- <cfcomponent output="false">
- <cffunction name="init" access="public" returntype="Person">
- <cfargument name="Birthday" type="string" default=""/>
- <cfargument name="FirstName" type="string" default=""/>
- <cfargument name="LastName" type="string" default=""/>
- <cfargument name="Gender" type="string" default=""/>
- <cfargument name="IsMale" type="string" default=""/>
- <cfargument name="LoadChildren" type="string" default=""/>
- <cfargument name="ParentPerson" type="string" default=""/>
- <cfset setBirthday( arguments.Birthday ) />
- <cfset setFirstName( arguments.FirstName ) />
- <cfset setLastName( arguments.LastName ) />
- <cfset setGender( arguments.Gender ) />
- <cfset setIsMale( arguments.IsMale ) />
- <cfset setLoadChildren( arguments.LoadChildren ) />
- <cfset setParentPerson( arguments.ParentPerson ) />
- <cfreturn this />
- </cffunction>
- <cffunction name="getBirthday" access="public" output="false" returntype="any">
- <cfreturn variables.instance.Birthday />
- </cffunction>
- <cffunction name="setBirthday" access="public" output="false" returntype="void">
- <cfargument name="Birthday" type="any" required="true" />
- <cfset variables.instance.Birthday = arguments.Birthday />
- </cffunction>
- <cffunction name="getFirstName" access="public" output="false" returntype="any">
- <cfreturn variables.instance.FirstName />
- </cffunction>
- <cffunction name="setFirstName" access="public" output="false" returntype="void">
- <cfargument name="FirstName" type="any" required="true" />
- <cfset variables.instance.FirstName = arguments.FirstName />
- </cffunction>
- <cffunction name="getGender" access="public" output="false" returntype="any">
- <cfreturn variables.instance.Gender />
- </cffunction>
- <cffunction name="setGender" access="public" output="false" returntype="void">
- <cfargument name="Gender" type="any" required="true" />
- <cfset variables.instance.Gender = arguments.Gender />
- </cffunction>
- <cffunction name="getIsMale" access="public" output="false" returntype="any">
- <cfreturn variables.instance.IsMale />
- </cffunction>
- <cffunction name="setIsMale" access="public" output="false" returntype="void">
- <cfargument name="IsMale" type="any" required="true" />
- <cfset variables.instance.IsMale = arguments.IsMale />
- </cffunction>
- <cffunction name="getLastName" access="public" output="false" returntype="any">
- <cfreturn variables.instance.LastName />
- </cffunction>
- <cffunction name="setLastName" access="public" output="false" returntype="void">
- <cfargument name="LastName" type="any" required="true" />
- <cfset variables.instance.LastName = arguments.LastName />
- </cffunction>
- <cffunction name="getLoadChildren" access="public" output="false" returntype="any">
- <cfreturn variables.instance.LoadChildren />
- </cffunction>
- <cffunction name="setLoadChildren" access="public" output="false" returntype="void">
- <cfargument name="LoadChildren" type="any" required="true" />
- <cfset variables.instance.LoadChildren = arguments.LoadChildren />
- </cffunction>
- <cffunction name="getParentPerson" access="public" output="false" returntype="any">
- <cfreturn variables.instance.ParentPerson />
- </cffunction>
- <cffunction name="setParentPerson" access="public" output="false" returntype="void">
- <cfargument name="ParentPerson" type="any" required="true" />
- <cfset variables.instance.ParentPerson = arguments.ParentPerson />
- </cffunction>
- <cffunction name="makeSnapshot" output="false" access="public" returntype="any" hint="I make a snapshot">
- <cfset var snapshot = {} />
- <cfset snapshot["DisplayName"] = "#getFirstName()# #getLastName()#" />
- <cfset snapshot["Birthday"] = dateFormat( getBirthday(), "long") />
- <cfset snapshot["Gender"] = "Male" />
- <cfif getIsMale() IS 0>
- <cfset snapshot["Gender"] = "Female" />
- </cfif>
- <cfreturn snapshot />
- </cffunction>
- </cfcomponent>
- ===============================END Person.cfc ======================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement