-
Notifications
You must be signed in to change notification settings - Fork 0
/
children.js
89 lines (86 loc) · 2.65 KB
/
children.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const utillib = require("./util.js");
const guardlib = require("./guardCode.js");
const { child } = require("winston");
module.exports.showChildren = (children, population, filterName="", hideFathers=false ) =>{
responseMessages = []
childNames = Object.keys(children)
var response = ''
mine = 0
var notPrintedNewAdultHeader = true;
var notStartedMiddleChildren = true;
var notStartedYoungChildren = true;
var notStartedUnborn = true;
var sortedChildren = Object.keys(children);
sortedChildren.sort(function(a, b) {
if (children[a].age == children[b].age){
if ( a < b) {return 1}
else { return -1 }
}
return children[a].age - children[b].age
});
for (childName of sortedChildren) {
if (response.length > 1700){
responseMessages.push(response)
response = ''
}
var child = children[childName]
if ( filterName && !(child.mother == filterName || child.father == filterName) ) {
continue
}
if (filterName){
if (filterName == child.mother){
// do nothing
} else if (filterName == child.father && !hideFathers){
// also do nothing
} else if (filterName == "!hungry") {
if (child.food >= 2){
continue;
}
}else {
continue;
}
}
if (child.dead){
//response += '('+childName+' is dead)\n';
// skip the dead
} else {
if (child.age < 0 && notStartedUnborn){
response += '-----> Unborn <-----\n'
notStartedUnborn = false;
} else if (0 <= child.age && child.age < 4 && notStartedYoungChildren ){
response += '-----> Nursing Children <-----\n'
notStartedYoungChildren = false;
} else if (4 <= child.age && child.age < 24 && notStartedMiddleChildren){
response += '-----> Children <-----\n'
notStartedMiddleChildren = false;
} else if (child.age >= 24 && notPrintedNewAdultHeader){
response += '-----> New Adults <-----\n'
notPrintedNewAdultHeader = false;
}
response += (childName+': '+child.gender).padEnd(30,' ')+'age:'+((child.age)/2)
if (child.newAdult){
response += 'Full grown!'.padStart(16, ' ')
} else {
if (child.food < 2){
response += ' needs '+(2-child.food)+' food'
} else {
response += ' not hungry'.padStart(16, ' ')
}
}
response += ' mother:'+child.mother
if (!hideFathers){
response += ' father:'+child.father
}
if (child.age < 24 ){
response += ' guardValue:'+ utillib.round(guardlib.findGuardValueForChild(childName, population, children))
}
if (child.babysitting){
response += ' watching:'+child.babysitting+' '
}
response += '\n'
}
}
responseMessages.push(response)
responseMessages.push('There are '+childNames.length+' children in total. \n')
return responseMessages
}