-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommunityTree.nlogo
More file actions
2074 lines (1726 loc) · 38.8 KB
/
CommunityTree.nlogo
File metadata and controls
2074 lines (1726 loc) · 38.8 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;COMMUNITY TREE
;;MADE BY LLEWELYN GRIFFITHS
;; 01/07/2015
;; Useful info
;; LINKS
;; Red - Married to
;; Green - Child of
;; Brown - Divorced
;; Black - Afair
;;TODO/IDEAS
;; - Check for previous divorces/afairs when selecting a partner
;; - Add random names for each turtle
;; - Rework intrigue cycle by incrementing years, the age of a turtle effects certain events.
;; - Rework generation checking to be more elegant and customisable.
;; - Make visual representation more clear.
;; - Print what happens with each intrigue cycle.
globals[year]
breed[people person]
breed[occupations occupation]
people-own[forename surname partner children gender mother father homosexual had-children afairs afair-avaliable divorces age occ contacts job-history alive sad-happy afraid-angry stress]
occupations-own[boss full-time part-time capacity previous]
links-own[strength]
to setup
set year 0
clear-all
set-default-shape people "person"
set-default-shape occupations "house"
ask patches[
set pcolor white
]
repeat STARTING-COUPLES [
make-couple
]
repeat STARTING-OCCUPATIONS [
create-job
]
end
to demo
setup
repeat 3[
generation-cycle
intrigue-cycle
]
end
to generation-cycle
create-families
find-partners
end
to intrigue-cycle
process-divorces
process-afairs
end
to year-cycle
set year year + 1
ask people[
if alive = true[
set age age + 1
]
]
process-divorces
process-births
process-deaths
process-retirement
process-redundancy
process-job-change
process-new-bosses
process-applications
;process-afairs
find-partners
process-new-contacts
end
to process-divorces
ask people[
if partner != -1 or partner != who[
let rand random(101)
if rand < DIVORCE-CHANCE[
divorce who
]
]
]
end
to process-redundancy
ask people[
let me-who who
if occ != -1[
let rand-int random(101)
if rand-int < REDUNDANCY-CHANCE[
ask occupation occ[
set full-time remove me-who full-time
set part-time remove me-who part-time
if boss = me-who[
set boss -1
]
]
set job-history fput "made redundant" job-history
set job-history fput age job-history
set job-history fput occ job-history
remove-links-between who occ
set occ -1
]
]
]
end
to process-new-contacts
ask people [
let me-contacts contacts
let me-who who
let occ-pt (list)
let occ-ft (list)
if occ != -1 [
ask occupation occ [
set occ-pt part-time
set occ-ft full-time
]
foreach occ-pt [
let pt-who ?
let already false
if pt-who != who[
foreach contacts[
if pt-who = ? [
set already true
]
]
if already = false[
let rand random(101)
if rand < NEW-CONTACT-CHANCE[
set contacts fput pt-who contacts
]
]
]
]
foreach occ-ft[
let ft-who ?
let already false
if ft-who != who[
foreach contacts[
if ft-who = ? [
set already true
]
]
if already = false[
let rand random(101)
if rand < NEW-CONTACT-CHANCE[
set contacts fput ft-who contacts
create-link-with person ft-who[
set color white
set strength random(101) - random(101)
set hidden? true
]
]
]
]
]
]
]
end
to process-job-change
ask people [
if occ != -1[
let rand-int random(101)
if rand-int < NEW-JOB-CHANCE[
let prev-occ occ
let new-job occ
let me-who who
let me-occ occ
ask occupations [
if who != me-occ[
let occ-who who
let employees (length part-time) + (length full-time)
if employees < capacity[
ask person me-who[
set job-history fput "applied for" job-history
set job-history fput age job-history
set job-history fput occ-who job-history
]
let randInt random(101)
if randInt < APPLICATION-CHANCE[
set new-job who
stop
]
]
]
]
if new-job != prev-occ [
remove-links-between who occ
ask occupation occ[
set full-time remove me-who full-time
set part-time remove me-who part-time
if boss = me-who[
set boss -1
]
]
set occ new-job
set job-history fput "changed job" job-history
set job-history fput age job-history
set job-history fput new-job job-history
ask occupation occ[
let randInt random(2)
if randInt = 0 [
set full-time fput me-who full-time
]
if randInt = 1 [
set part-time fput me-who part-time
]
]
create-link-with occupation occ [
set strength 0
set color green
]
]
]
]
]
end
to process-retirement
ask people[
let me-who who
if occ != -1[
if age >= RETIREMENT-AGE[
let rand-int random(101)
if rand-int < RETIREMENT-CHANCE[
ask occupation occ[
set full-time remove me-who full-time
set part-time remove me-who part-time
if boss = me-who[
set boss -1
]
]
set job-history fput "retired" job-history
set job-history fput age job-history
set job-history fput occ job-history
remove-links-between who occ
set occ -1
]
]
]
]
end
to process-deaths
ask people [
if alive = true[
let rand -1
if age <= 4[
set rand random(4386)
]
if age > 4 and age <= 14[
set rand random(8333)
]
if age > 14 and age <= 24[
set rand random(1908)
]
if age > 24 and age <= 34[
set rand random(1215)
]
if age > 34 and age <= 44[
set rand random(663)
]
if age > 44 and age <= 54[
set rand random(279)
]
if age > 54 and age <= 64[
set rand random(112)
]
if age > 64 and age <= 74[
set rand random(42)
]
if age > 74 and age <= 84[
set rand random(15)
]
if age >= 85[
set rand random(6)
]
if rand = 1[
dead-clean-up who
output-print (word who " died horribly age " age)
]
]
]
end
to process-births
ask people [
if alive = true[
let rand-int random(101)
if rand-int < BIRTH-CHANCE[
if homosexual = false[
if partner != -1[
let partner-age -1
ask person partner [
set partner-age age
]
if age < 60 and partner-age < 60[
if gender = "m"[
make-child who partner
]
if gender = "f" [
make-child partner who
]
]
]
]
]
]
]
end
to process-afairs
ask people[
let rand random(101)
set afair-avaliable false
if rand < AFAIR-CHANCE[
set afair-avaliable true
]
]
ask people[
let me-who who
if afair-avaliable = true[
ask other people [
if afair-avaliable = true[
if generations-away 2 me-who who = true [
have-afair me-who who
]
]
]
]
]
end
to have-afair[me them]
ask person me[
set afairs fput them afairs
create-link-with person them [
set strength 0
set color black
]
]
ask person them[
set afairs fput me afairs
]
end
to divorce[me]
let them -1
ask person me[
if alive = true [
set them partner
set partner -1
set had-children false
if them != -1[
set divorces fput them divorces
]
if father != -1[
let original-surname ""
ask person father[
set original-surname surname
]
set surname original-surname
]
if father = -1[
set surname generate-surname
]
]
]
if them != -1[
ask person them[
set partner -1
set had-children false
set divorces fput me divorces
if father != -1[
let original-surname ""
ask person father[
set original-surname surname
]
set surname original-surname
]
if father = -1[
set surname generate-surname
]
]
]
;remove-links-between me them
if is-link? link me them[
ask link me them [
set color brown
set strength strength - 50
]
]
; ask person me[
; if them != -1[
; create-link-with person them [
; set color brown
; ]
; ]
; ]
end
to remove-links-between [ a b ]
if is-link? link a b [ ask link a b [ die ] ]
if is-link? link b a [ ask link b a [ die ] ]
end
to create-job
create-occupations 1 [
setxy random-xcor random-ycor
set boss -1
set full-time (list)
set part-time (list)
set previous (list)
set capacity 99
]
end
to process-new-bosses
ask occupations[
let occ-who who
let new-boss ""
if boss = -1[
ask people[
if alive = true[
if age >= 18[
if occ = -1 [
if random(101) < BOSS-CHANCE[
set new-boss who
stop
]
]
]
]
]
if new-boss = "" [
set new-boss make-outsider-boss
]
set boss new-boss
ask person boss [
set occ occ-who
set job-history fput "became boss" job-history
set job-history fput age job-history
set job-history fput occ-who job-history
]
create-link-with person boss [
set color red
set strength 75
]
]
]
end
to process-applications
ask people [
let new-job -1
let me-who who
if alive = true[
if age >= 18 and age < RETIREMENT-AGE [
if occ = -1[
ask occupations [
let occ-who who
let employees (length part-time) + (length full-time)
if employees < capacity[
ask person me-who[
set job-history fput "applied for" job-history
set job-history fput age job-history
set job-history fput occ-who job-history
]
let randInt random(101)
if randInt < APPLICATION-CHANCE[
set new-job who
stop
]
]
]
]
if new-job != -1 [
set occ new-job
set job-history fput "new job" job-history
set job-history fput age job-history
set job-history fput new-job job-history
ask occupation occ[
let randInt random(2)
if randInt = 0 [
set full-time fput me-who full-time
]
if randInt = 1 [
set part-time fput me-who part-time
]
]
create-link-with occupation occ [
set strength 0
set color green
]
]
]
]
]
end
to create-families
ask people [
if homosexual = false[
if partner != -1[
if had-children = false[
if gender = "m"[
make-family who partner
]
if gender = "f" [
make-family partner who
]
set had-children true
ask person partner [
set had-children true
]
]
]
]
]
end
to find-partners
ask people [
let me who
let me-homosexual homosexual
let match -1
let g gender
let last-name surname
if alive[
if age >= 18[
if partner = -1[
ask other people [
if generations-away 2 me who = true [
if partner = -1 [
if homosexual = false [
if gender != g[
set match who
]
]
if homosexual = true [
if me-homosexual = homosexual[
if gender = g [
set match who
]
]
]
]
]
]
if match != -1[
let m-surname ""
ask person match [
set partner me
set m-surname surname
if homosexual = false[
if gender = "f"[
set surname last-name
]
]
if homosexual = true[
set surname last-name
]
create-link-with person me [
set strength 50
set color red
]
]
if homosexual = false [
if gender = "f"[
set surname m-surname
]
]
]
if match = -1 [
let rand random(101)
if rand < OUTSIDER-CHANCE[
make-outsider-couple who
]
]
if match != -1 [
set partner match
]
]
]
]
]
end
to-report generations-away[g me target]
;;g parpameter currently unused
let me-m -1
let me-f -1
let ta-m -1
let ta-f -1
let result true
ask person me [
set me-m mother
set me-f father
]
ask person target [
if who = me-m or who = me-f [
set result false
]
if mother = me-m or father = me-f[
set result false
]
set ta-f father
set ta-m mother
]
if ta-f != -1 and ta-m != -1[
ask person ta-f [
if mother = me-m or father = me-f[
set result false
]
]
ask person ta-m [
if mother = me-m or father = me-f[
set result false
]
]
foreach children[
ask person ? [
if who = me-m or who = me-f[
set result false
]
foreach children[
ask person ? [
if who = me-m or who = me-f[
set result false
]
]
]
]
]
]
report result
end
to make-couple
let c1 -1
let c1-surname ""
let c1-age 0
let c2 -1
create-people 1 [
setxy random-xcor random-ycor
set color blue
set forename generate-forename "m"
set surname generate-surname
set c1-surname surname
set afair-avaliable false
set afairs (list)
set divorces (list)
set partner -1
set children (list)
set gender "m"
set mother -1
set father -1
set homosexual false
set had-children false
set occ -1
set age random(82) + 18
set contacts (list)
set sad-happy 0
set stress 50
set afraid-angry 0
set alive true
set job-history (list)
set c1-age age
set c1 who
]
create-people 1 [
setxy random-xcor random-ycor
set color red
set forename generate-forename "f"
set surname c1-surname
set afair-avaliable false
set afairs (list)
set divorces (list)
set partner c1
set children (list)
set gender "f"
set mother -1
set father -1
set homosexual false
set had-children false
set occ -1
set age random(82) + 18
set contacts (list)
set sad-happy 0
set afraid-angry 0
set alive true
set job-history (list)
set c2 who
]
ask person c1 [
set partner c2
create-link-with person c2 [
set strength 50
set color red
]
]
end
to make-outsider-couple[them]
let outsider -1
let them-gender "m"
ask person them [
set them-gender gender
]
hatch 1 [
setxy random-xcor random-ycor
set partner them
set children (list)
if homosexual = false [
if them-gender = "m"[
set gender "f"
set color red
]
if them-gender = "f" [
set gender "m"
set color blue
]
]
if homosexual = true [
set gender them-gender
if them-gender = "m"[
set color blue
]
if them-gender = "f"[
set color red
]
]
set forename generate-forename gender
set mother -1
set father -1
set homosexual false
set had-children false
set occ -1
set contacts (list)
set sad-happy 0
set afraid-angry 0
set alive true
set job-history (list)
set afair-avaliable false
set afairs (list)
set divorces (list)
set outsider who
]
ask person them [
set partner outsider
create-link-with person outsider [
set strength 50
set color red
]
]
end
to-report make-outsider-boss
let new-boss-who ""
hatch-people 1 [
set new-boss-who who
let rand-int random(2)
if rand-int = 0[
set gender "m"
set color blue
]
if rand-int = 1 [
set gender "f"
set color red
]
set rand-int random(2)
if rand-int = 0[
set homosexual true
]
if rand-int = 1 [
set homosexual false
]
set forename generate-forename gender
set surname generate-surname
set age random(82) + 18
set mother -1
set father -1
set had-children false
set afair-avaliable false
set afairs (list)
set divorces (list)
set children (list)
set contacts (list)
set sad-happy 0
set afraid-angry 0
set partner -1
set alive true
set job-history (list)
]
report new-boss-who
end
to make-child[m f] ;m : male - f : female
let c-who -1
hatch 1 [
set age 0
set partner -1
set children (list)
set mother f
set father m
set afair-avaliable false
set afairs (list)
set divorces (list)
set had-children false
set occ -1
set contacts (list)
set sad-happy 0
set afraid-angry 0
set alive true
set job-history (list)
set c-who who
set homosexual false
if random(101) < HOMOSEXUAL-CHANCE[
set homosexual true
]
let rand random(2)
if rand = 1 [
set gender "m"
set color blue
]
if rand = 0 [
set gender "f"
set color red
]
set forename generate-forename gender