Bird Breeders

Bird Breeders preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

ccl 

Tagged by Uri Wilensky over 12 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.3 • Viewed 575 times • Downloaded 51 times • Run 0 times
Download the 'Bird Breeders' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Info tab cannot be displayed because of an encoding error

Comments and Questions

Click to Run Model

globals [
  player-1 player-2 player-3 player-4       ;; player names
  player-1-cage-color player-2-cage-color   ;; colors for cages (patches) for each player
  player-3-cage-color player-4-cage-color
  player-1-tag-color  player-2-tag-color    ;; colors for tags (visualization of where the destination patch is for a moving bird)
  player-3-tag-color  player-4-tag-color

  genes-to-phenotype                        ;; a list that contains a map of genotypes to phenotypes
  parent-female  parent-male                ;; the two parents of a breeding event - used for determining genotype of any potential eggs

  frequency-allele-dominant-second-trait    ;; keeps track of allele frequencies in the gene pool of the current population (of birds, but not eggs)
  frequency-allele-dominant-first-trait
  frequency-allele-recessive-second-trait
  frequency-allele-recessive-first-trait
  frequency-allele-dominant-third-trait
  frequency-allele-recessive-third-trait
  frequency-allele-dominant-fourth-trait
  frequency-allele-recessive-fourth-trait

  #-birds-with-1-target-trait               ;; used for keeping track of phenotype frequencies
  #-birds-with-2-target-traits
  #-birds-with-3-target-traits
  #-birds-with-4-target-traits

  breeding-site-color-1                     ;; colors for the patches that are breeding sites
  breeding-site-color-2
  bird-body-color                           ;; color of the bird body shape
  bird-size                                 ;; size of bird shape
  egg-size                                  ;; size of egg shape
  current-instruction                       ;; which instruction the player is viewing

  number-of-goal-birds                      ;; keeps track of how many birds you have currently that have the phenotype combinations you have been trying to breed for.
  sequencings-performed                     ;; keeps track of the number of DNA sequencings performed
  sequencings-left                          ;; keeps track of the number of sequencings left
  number-offspring                          ;; keeps track of number of eggs laid
  number-hatchings                          ;; keeps track of number of eggs hatched at cages
  number-releases                           ;; keeps track of number of eggs and birds released into the wild (grass patches)
  number-matings                            ;; keeps track of number of matings
  number-selections                         ;; keeps track of number of releases + number of eggs hatched at cages
  new-selection-event-occurred?             ;; turns true when number-selections increments by 1.  This is used for updating the genotype and phenotype graphs
]


breed [grasses grass]                      ;; used for the shapes on the patches that are considered the "wild"
breed [DNA-sequencers DNA-sequencer]       ;; used for the shape that shows the location of where DNA tests can be conducted for eggs or birds (test tube shape)
breed [cages cage]                         ;; used for the shape of cages - black lined square
breed [selection-tags selection-tag]       ;; the selection tag is a visualization tool - it is assigned to a bird or egg that is selected with the mouse
breed [destination-flags destination-flag] ;; the destination flag is a visualization tool - it is a turtle showing the target patch where the bird or egg is headed
breed [karyotype-tags karyotype-tag]         ;; the karyotype tag is a visualization tool - it allows the genotype to be displayed off center of the bird
breed [birds bird]                         ;; the creature that is being bred
breed [eggs egg]                           ;; what is laid by birds and must be returned to cages to hatch into birds
breed [first-traits  first-trait]          ;; shape that is the crest in birds
breed [second-traits second-trait]         ;; shape that is the wings in birds
breed [third-traits  third-trait]          ;; shape that determines breast in birds
breed [fourth-traits  fourth-trait]          ;; shape that determines tail in birds
breed [players player]                     ;; one player is assigned to each participant



patches-own [site-id patch-owned-by closed? reserved?]
players-own [user-id player-number moving-a-bird? origin-patch assigned?]

birds-own [
  owned-by                                                                ;; birds are owned-by a particular user-id.
  first-genes second-genes third-genes fourth-genes fifth-genes sex-gene   ;; genetic information is stored in these five variables
  transporting? breeding? selected? just-bred? sequenced? released?       ;; the state of the bird is stored in these seven variables
  destination-patch                                                       ;; this variable is used for keeping track of where the bird is moving toward
  release-counter                                                         ;; this variable counts down to keep track of how to visualize the "fading" out of a released bird
]

eggs-own  [
  owned-by                                                                ;; eggs are owned-by a particular user-id.
  first-genes second-genes third-genes fourth-genes fifth-genes sex-gene   ;; genetic information is stored in these five variables
  transporting? breeding? selected? just-bred? sequenced? released?       ;; the state of the egg is stored in these seven variables
  destination-patch                                                       ;; this variable is used for keeping track of where the egg is moving toward
  release-counter                                                         ;; this variable counts down to keep track of how to visualize the "fading" out of a released egg
]

;; owned-by corresponds a particular user-id
dna-sequencers-own    [owned-by]
selection-tags-own    [owned-by]
destination-flags-own [owned-by]
first-traits-own      [owned-by first-genes  ]
second-traits-own     [owned-by second-genes ]
third-traits-own      [owned-by third-genes  ]
fourth-traits-own      [owned-by fourth-genes fifth-genes sex-gene ]       ;; the fourth trait related to presence of feathers (head cap) is sex linked - it only appears if the individual is male)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;  setup procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to startup
  setup
  hubnet-reset
  make-players
end 

to setup
  ;; these clear commands are used in place of clear all, because SETUP should not remove the players from the simulation
  clear-patches
  clear-drawing
  clear-all-plots
  clear-non-player-turtles
  reset-player-numbers

  set parent-female nobody
  set parent-male nobody
  set number-of-goal-birds 0
  set number-selections 0
  set number-matings 0
  set number-releases 0
  set number-hatchings 0
  set number-offspring 0
  set sequencings-performed 0
  set sequencings-left (max-#-of-DNA-tests - sequencings-performed)
  set new-selection-event-occurred? false
  set #-birds-with-1-target-trait 0
  set #-birds-with-2-target-traits 0
  set #-birds-with-3-target-traits 0
  set #-birds-with-4-target-traits 0
  set bird-body-color       [200 200 200 255]
  set breeding-site-color-1 (gray + 2.0)
  set breeding-site-color-2 (gray + 4.0)
  set player-1-cage-color   (pink + 1.5)
  set player-2-cage-color   (green + 1.5)
  set player-3-cage-color   (brown + 1.5)
  set player-4-cage-color   (turquoise + 1.5)
  set player-1-tag-color   player-1-cage-color  - 5
  set player-2-tag-color   player-2-cage-color  - 5
  set player-3-tag-color   player-3-cage-color  - 5
  set player-4-tag-color   player-4-cage-color  - 5
  set bird-size 0.8
  set egg-size  0.55

  set genes-to-phenotype [
    ["AA" "set color [150 150 150 255]"] ["Aa" "set color [150 150 150 255]"] ["aA" "set color [150 150 150 255]"] ["aa" "set color [0 150 255 255]"]        ;; sets crest colors
    ["BB" "set color [150 150 150 255]"] ["Bb" "set color [150 150 150 255]"] ["bB" "set color [150 150 150 255]"] ["bb" "set color [155 0 100 255]"]        ;; sets wing colors
    ["CC" "set color [150 150 150 255]"] ["Cc" "set color [150 150 150 255]"] ["cC" "set color [150 150 150 255]"] ["cc" "set color [255 0 200 255]"]        ;; sets chest colors
    ["DD" "set color [150 150 150 255]"] ["Dd" "set color [150 150 150 255]"] ["dD" "set color [150 150 150 255]"] ["dd" "set color [255 0 0 255]" ]         ;; sets tail colors
  ]

  set-default-shape birds "bird"
  set-default-shape first-traits "bird-cap"
  set-default-shape second-traits "bird-wing"
  set-default-shape third-traits "bird-breast"
  set-default-shape fourth-traits "bird-tail"
  set-default-shape karyotype-tags "karyotype-tag"
  set-default-shape DNA-sequencers "test-tubes"
  set-default-shape selection-tags "tag"
  set-default-shape destination-flags "flag"
  set-default-shape DNA-sequencers "test-tubes"

  ask patches [set pcolor white set reserved? false]
  setup-cages
  setup-DNA-sequencers
  setup-breeding-sites
  setup-grasses
  calculate-all-alleles

  show-instruction 1
  reset-ticks
end 

to make-players
  let player-number-counter 1
  create-players 4 [
    set hidden? true  ;; players are invisible agents
    set player-number player-number-counter
    set player-number-counter player-number-counter + 1
    set user-id ""        ;; this player is currently unassigned to a participant
    set assigned? false
  ]
end 

to clear-non-player-turtles
   ask grasses [die]
   ask cages [die]
   ask DNA-sequencers [die]
   ask birds [die]
   ask eggs [die]
   ask selection-tags [die]
   ask destination-flags [die]
   ask karyotype-tags [die]
   ask first-traits [die]
   ask second-traits [die]
   ask third-traits [die]
   ask fourth-traits [die]
end 

to reset-player-numbers
  set player-1 ""  set player-2 ""  set player-3 ""   set player-4 ""
  ask players [
    if player-number = 1 [set player-1 user-id]
    if player-number = 2 [set player-2 user-id]
    if player-number = 3 [set player-3 user-id]
    if player-number = 4 [set player-4 user-id]
  ]
end 

to setup-cages
   let these-cages nobody
   show count players with [assigned?]
   ;; make cages and birds for player 1
   set these-cages patches with [pxcor = -4 and pycor <= 3 and pycor >= -2]
   ask these-cages [set pcolor player-1-cage-color  set patch-owned-by 1 sprout 1 [set breed cages set shape "cage"]]
   ask n-of 3 these-cages  [setup-birds]
   ;; make cages and birds for player 2
   set these-cages patches with [pxcor <= 3 and pxcor >= -2 and pycor = 5]
   ask these-cages [set pcolor player-2-cage-color set patch-owned-by 2 sprout 1 [set breed cages set shape "cage"]]
   ask n-of 3 these-cages  [setup-birds]
   ;; make cages and birds for player 3
   set these-cages patches with [pxcor = 5 and pycor >= -2 and pycor <= 3]
   ask these-cages [set pcolor player-3-cage-color  set patch-owned-by 3 sprout 1 [set breed cages set shape "cage"]]
   ask n-of 3 these-cages  [setup-birds]
   ;; make cages and birds for player 4
   set these-cages patches with [pycor = -4 and pxcor >= -2 and pxcor <= 3]
   ask these-cages [set pcolor player-4-cage-color set patch-owned-by 4 sprout 1 [set breed cages set shape "cage"]]
   ask n-of 3 these-cages  [setup-birds]
end 

to setup-birds
   let this-cage patch-owned-by
   sprout 1 [
     build-body-base
     set owned-by this-cage
     assign-all-genes
     build-body-parts
   ]
end 

to setup-DNA-sequencers
  ask patch min-pxcor max-pycor [
    set patch-owned-by 1
    sprout 1 [set breed DNA-sequencers]
  ]
  ask patch (max-pxcor) max-pycor  [
    set patch-owned-by 2
    sprout 1 [set breed DNA-sequencers]
  ]
  ask patch max-pxcor min-pycor [
    set patch-owned-by 3
    sprout 1 [set breed DNA-sequencers]
  ]
  ask patch (min-pxcor ) min-pycor  [
    set patch-owned-by 4
    sprout 1 [set breed DNA-sequencers]
  ]
  ask DNA-sequencers [
    set color 68
    set label-color gray - 2.5
    set label (word patch-owned-by " ")
  ]
end 

to setup-breeding-sites
   ask patches with [pxcor >= -2 and pxcor <= -1 and pycor <= 3 and pycor >= 1]
     [set pcolor breeding-site-color-1   set site-id 1]
   ask patches with [pxcor >= 0 and pxcor <= 1 and pycor <= 3 and pycor >= 1]
     [set pcolor breeding-site-color-2    set site-id 2]
   ask patches with [pxcor >= 2 and pxcor <= 3 and pycor <= 3 and pycor >= 1]
     [set pcolor breeding-site-color-1    set site-id 3]
   ask patches with [pxcor >= -2 and pxcor <= -1 and pycor <= 0 and pycor >= -2]
     [set pcolor breeding-site-color-2  set site-id 4]
   ask patches with [pxcor >= 0 and pxcor <= 1 and pycor <= 0 and pycor >= -2]
     [set pcolor breeding-site-color-1 set site-id 5]
   ask patches with [pxcor >= 2 and pxcor <= 3 and pycor <= 0 and pycor >= -2]
     [set pcolor breeding-site-color-2 set site-id 6]
end 

to setup-grasses
  ask patches with [is-a-release-site?] [
    sprout 1 [
      set breed grasses
      set shape "grass"
      set color [50 150 50 150]
      set heading random 360
      fd random-float .45   ;; move the grass shape a bit within the patch
      set size 0.35 + random-float 0.15
   ]
   set pcolor [205 235 205]]   ;; set the color of the patch to a light green
end 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;  runtime procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
  initialize-mating
  open-eggs
  check-for-DNA-test
  update-mating-ready-visualization
;;  every 0.1 [
    ask (turtle-set birds eggs) with [released?] [release-this-bird-or-egg]
    visualize-bird-and-egg-movement
    ask selection-tags [rt 5]
    listen-clients
    if any? players with [assigned?] [send-common-info]
;;  ]
  calculate-all-alleles
  check-for-meeting-goals
  
  tick
end 

to update-mating-ready-visualization
  ask birds  [
    ifelse just-bred?
      [ set shape (word "bird-ready-to-go-home-" which-player-bird-or-egg-is-this? self) ]
      [ ifelse is-at-mating-site?  [set shape "bird-ready-to-mate"] [set shape "bird-waiting"]]
  ]
end 

to visualize-bird-and-egg-movement
  ask (turtle-set birds eggs) with [transporting? and destination-patch != nobody] [
    let bird-owned-by owned-by
    ifelse distance destination-patch < .25
      [ setxy [pxcor] of destination-patch [pycor] of destination-patch
          set transporting? false set breeding? false set selected? false
          set destination-patch nobody
          set reserved? false
          ask destination-flags-here [die]
          ask selection-tags-here [die]
          if is-a-release-site? [set released? true]
          if in-cage? [set just-bred? false]
      ]
      [set heading towards destination-patch fd .2 set heading 0]
  ]
end 

to check-for-DNA-test
    set sequencings-left (max-#-of-DNA-tests - sequencings-performed)
    if sequencings-left <= 0 [set sequencings-left 0]
    ask birds with [not sequenced? and is-a-sequencer-site?] [sequence-this-bird]
end 

to release-this-bird-or-egg
  let bird-transparency 0
  let color-list []
  set release-counter release-counter - 1
  let this-release-counter release-counter
  set color-list but-last color
  set bird-transparency (release-counter * 60 / 6)
  set color-list lput bird-transparency color-list
  set color color-list
  ask out-link-neighbors [
     set color-list but-last color
     set color-list lput bird-transparency color-list
     set color color-list
     ask out-link-neighbors [set color color-list]
  ]
  remove-this-bird-or-egg
end 

to remove-this-bird-or-egg
  if release-counter <= 0 [
    set number-releases number-releases + 1
    ask out-link-neighbors [ask out-link-neighbors [die]]
    ask out-link-neighbors [die]
    die
  ]
end 

to sequence-this-bird
  let tag-label  ( word first-genes second-genes  fourth-genes third-genes sex-gene " ")
  let this-owner owned-by
  let this-bird-wing one-of out-link-neighbors with [breed = second-traits]
  if not sequenced? and is-bird? self [
    set sequenced? true
    set heading 0
    hatch 1 [
      set breed karyotype-tags
      set hidden? false
      set heading 55
      fd .55
      set heading 0
      create-link-from this-bird-wing [set tie-mode "free" tie set hidden? true]
      set size .2
      set label tag-label
      set label-color [255 0 0]
    ]
    set sequencings-performed sequencings-performed + 1
    set sequencings-left (max-#-of-DNA-tests - sequencings-performed)
  ]
end 




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Handle client interactions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to listen-clients
  while [ hubnet-message-waiting? ]   [
    hubnet-fetch-message
    ifelse hubnet-enter-message?
    [ assign-new-player ]
    [
      ifelse hubnet-exit-message?
      [ remove-player ]
      [ ask players with [user-id = hubnet-message-source] [  execute-command hubnet-message-tag hubnet-message ]]
    ]
  ]
end 

to execute-command [command msg]
  if command = "View" [check-click-on-bird-or-egg msg]
  if command = "Mouse Up" [ check-release-mouse-button msg]
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; player enter / exit procedures  ;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to assign-new-player
  if not any? players with [user-id = hubnet-message-source and assigned?]  [  ;; no players with this id and is assigned
    ask one-of players with [not assigned?] [ set user-id hubnet-message-source set assigned? true]
  ]
  reset-player-numbers
end 

to remove-player
  ask players with [user-id = hubnet-message-source] [ set assigned? false set user-id ""]
  reset-player-numbers
end 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;  send info to client procedures ;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to send-common-info
  hubnet-broadcast "Player 1:" player-1
  hubnet-broadcast "Player 2:" player-2
  hubnet-broadcast "Player 3:" player-3
  hubnet-broadcast "Player 4:" player-4
  hubnet-broadcast "# eggs laid" number-offspring
  hubnet-broadcast "# of birds/eggs released" number-releases
  hubnet-broadcast "# matings" number-matings
  hubnet-broadcast "# of DNA tests remaining" sequencings-left
end 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;  check for meeting goals procedures ;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to check-for-meeting-goals
  set new-selection-event-occurred? false
  let new-number-selections (number-releases + number-hatchings)
  ;; number-selections updates everytime an action is done that would potentially change the gene pool of the population
  if new-number-selections > number-selections [
    set number-selections new-number-selections
    set new-selection-event-occurred? true
  ]
  set number-of-goal-birds count birds with [is-goal-bird-and-in-cage?]
  if (number-of-goal-birds >= #-of-required-goal-birds)  [ announce-winner]
end 

to announce-winner
  user-message (word "You met your team goal and now can sell your stock of birds to rare pet collectors! Press HALT. Then Press SETUP to play again.")
  ask patch 2 4 [set plabel "You have met your breeding goal.  Press SETUP to play again." set plabel-color black]
end 

to calculate-all-alleles
  ;; check to make sure one of each allele exists somewhere in the starting population
  ;; otherwise breeding for the target bird would be impossible

  set #-birds-with-1-target-trait  count birds with [ how-many-target-traits = 1]
  set #-birds-with-2-target-traits count birds with [ how-many-target-traits = 2]
  set #-birds-with-3-target-traits count birds with [ how-many-target-traits = 3]
  set #-birds-with-4-target-traits count birds with [ how-many-target-traits = 4]

  set frequency-allele-dominant-first-trait   (count birds with [(item 0 first-genes)  = "A"]) + (count birds with [(item 1 first-genes)  = "A"])
  set frequency-allele-recessive-first-trait  (count birds with [(item 0 first-genes)  = "a"]) + (count birds with [(item 1 first-genes)  = "a"])
  set frequency-allele-dominant-second-trait  (count birds with [(item 0 second-genes) = "B"]) + (count birds with [(item 1 second-genes) = "B"])
  set frequency-allele-recessive-second-trait (count birds with [(item 0 second-genes) = "b"]) + (count birds with [(item 1 second-genes) = "b"])
  set frequency-allele-dominant-third-trait   (count birds with [(item 0 third-genes)  = "C"]) + (count birds with [(item 1 third-genes)  = "C"])
  set frequency-allele-recessive-third-trait  (count birds with [(item 0 third-genes)  = "c"]) + (count birds with [(item 1 third-genes)  = "c"])
  set frequency-allele-dominant-fourth-trait   (count birds with [(item 0 fourth-genes)  = "D"]) + (count birds with [(item 1 fourth-genes)  = "D"])
  set frequency-allele-recessive-fourth-trait  (count birds with [(item 0 fourth-genes)  = "d"]) + (count birds with [(item 1 fourth-genes)  = "d"])

  if ((both-second-trait-alleles-exist? and both-first-trait-alleles-exist? and both-fourth-alleles-exist? and both-third-trait-alleles-exist? and both-sexes-exist?) = false)
   [user-message (word "The current of birds in all the cages of all the player does not have"
    " enough genetic diversity for it to be possible for you to find a way to develop the desired breed."
    "  Press HALT then press SETUP to start the model over and try again.")
    ]
end 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;  breed birds ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to initialize-mating
  ;; when a female bird lands at a breeding site... it becomes breeding ready
  ;; when a mate lands at this location eggs are hatched....eggs have an owner (one of two parents)
  ask birds with [is-ready-for-mating?] [
    let this-site-id site-id
    let female-owned-by [owned-by] of self
    set parent-female self
    remove-eggs-at-nest
    if (has-one-mate-in-nest? this-site-id ) [
      make-eggs this-site-id
      set just-bred? true
      set breeding? false
      ask parent-male [ set just-bred? true set breeding? false]
      set number-matings number-matings + 1
    ]
  ]
end 

to remove-eggs-at-nest
  let this-site-id site-id
  ask eggs with [site-id = this-site-id and not transporting?] [set number-releases number-releases + 1 die]
end 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;  make eggs or hatch  convert eggs;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to open-eggs
  ask eggs with [in-cage? and not transporting? and not breeding? and not selected? ] [
    build-body-base
    build-body-parts
    set number-hatchings number-hatchings + 1
    reset-egg-or-bird-state
  ]
end 

to make-eggs [this-site-id]  ;; make eggs in all open patches at this breeding site
   let egg-counter 0
   let number-of-existing-female-eggs 0
   let number-of-existing-male-eggs 0
   let open-patches patches with [site-id = this-site-id and not any? birds-here]  ;;;  number of open patches is equal to number of eggs created
   ask open-patches  [
     ifelse egg-counter mod 2 = 0
        [sprout 1 [make-an-egg parent-female]]   ;; every even egg (0, 2) will be owned by player who contributed the female bird
        [sprout 1 [make-an-egg parent-male]]     ;; every odd egg  (1, 3) will be owned by player who contribute the male bird
     set egg-counter egg-counter + 1
   ]
   set number-offspring number-offspring + egg-counter
end 

to make-an-egg [which-bird]
  set breed eggs
  set first-genes inherited-first-genes
  set third-genes inherited-third-genes
  set second-genes inherited-second-genes
  set fourth-genes inherited-fourth-genes
  set sex-gene inherited-sex-genes
  reset-egg-or-bird-state
  set release-counter 6
  set owned-by which-player-bird-or-egg-is-this? which-bird
  set shape (word "egg-ready-to-go-home-" owned-by)
  set color [200 200 255 255]
  set size egg-size
  set label-color black
  set label owned-by
end 

to reset-egg-or-bird-state
  set breeding? false
  set selected? false
  set sequenced? false
  set transporting? false
  set just-bred? false
  set released? false
  set destination-patch nobody
end 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;  build birds ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to build-body-base
  set breed birds
  set shape "bird-waiting"
  set size bird-size
  set color bird-body-color
  set heading 0
  set transporting? false
  set breeding? false
  set just-bred? false
  set selected? false
  set sequenced? false
  set release-counter 6
  set released? false
  set destination-patch nobody
end 

to assign-all-genes
  set first-genes  (word random-first-genes random-first-genes)
  set second-genes (word random-second-genes random-second-genes)
  set third-genes  (word random-third-genes random-third-genes)
  set fourth-genes  (word random-fourth-genes random-fourth-genes)
  set sex-gene random-sex-genes
end 

to build-body-parts
  let body-label owned-by
  set label ""  ;; temporarily remove the label during building the body parts (so the label is not assigned to the parts)
  set size bird-size
  set heading 0
  if is-male? [
    hatch 1 [run lookup-phenotype-for-gene first-genes set breed first-traits   create-link-from myself  [tie] ]
  ]
  hatch 1 [run lookup-phenotype-for-gene second-genes set breed second-traits  create-link-from myself  [tie] ]
  hatch 1 [run lookup-phenotype-for-gene fourth-genes  set breed fourth-traits   create-link-from myself  [tie] ]
  hatch 1 [run lookup-phenotype-for-gene third-genes  set breed third-traits   create-link-from myself  [tie] ]
  set label-color black
  set label body-label
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;  select the birds ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;; when a complete mouse drag is finished here is what should occur;
;; a mouse action number is assigned to the bird or and egg  and the destination patch
;; the origin patch should hatch a destination-flag to show where the egg or bird/egg is headed.
;; A selection-tag is also attached to the bird when a bird/egg is clicked on, the bird/egg becomes
;; selected? = true and a visual selection "selection-tag" is assigned to it.

;; when a mouse drag is released the selected birds is assigned a destination patch (a bird/egg variable)
;; The patch itself also is given a "reserved?" = true state so that it can not be set as a destination patch by other
;; mouse drags nor have eggs hatched on it.  And now the bird/egg becomes unselected and becomes a "moving" bird/egg.
;; moving birds can not be stopped in mid flight (they are not valid birds to be selected)
;; once moving birds reach their destination patch, the patch is no longer reserved

;; destination patches must be different than origin patches, otherwise if it is the same, then the
;; bird/egg becomes a non selected bird/egg.

;; when a moving bird/egg reaches the destination patch (or within its radius), the reserved patches for this bird/egg are
;; cleared to be unreserved (both origin and destination).  The selected bird/egg is the agent then that is assigned
;; a patch and a destination flag for a valid destination.  Valid destination patches are then switched to reserved
;; until the bird gets to the patch.  Reserved patches then can not be destinations.

to check-click-on-bird-or-egg [msg]
  let snap-xcor round item 0 msg
  let snap-ycor round item 1 msg
  let this-player-number player-number
  let this-bird-or-egg nobody

  ;; birds-available is agent set of players birds at mouse location
  let birds-or-eggs-selectable-at-clicked-patch (turtle-set birds eggs) with [pxcor = snap-xcor and pycor = snap-ycor and is-selectable-by-me? this-player-number]
  if any? birds-or-eggs-selectable-at-clicked-patch    [
    ;; when a bird is clicked on (mouse down, that is the players bird, the bird becomes a "selected bird"
    ;; and a visual selection "selection-tag" is assigned to it. All other tags need to be wiped out
    ;; ask all birds/eggs owned to deselect
    deselect-all-my-birds-and-eggs this-player-number
    ask one-of birds-or-eggs-selectable-at-clicked-patch [
      set-as-only-selected
      set destination-patch nobody
      set this-bird-or-egg self
      hatch 1 [
        set breed selection-tags set owned-by this-player-number set color (lput 150 extract-rgb (player-tag-and-destination-flag-color this-player-number ) ) set heading 0 set size 1.0 set label ""
        create-link-from this-bird-or-egg [set hidden? true tie]
      ]
    ]
  ]
end 

to check-release-mouse-button [msg]
  let snap-xcor round item 0 msg
  let snap-ycor round item 1 msg
  let is-destination-patch-illegal? true
  let this-player-number player-number
  let this-user-id user-id
  let currently-selected-birds-or-eggs (turtle-set birds eggs) with [selected? and is-bird-or-egg-owned-by-this-player? this-player-number]

  if any? currently-selected-birds-or-eggs [
    let this-selected-bird-or-egg one-of currently-selected-birds-or-eggs
    let this-selected-is-an-egg? is-egg? this-selected-bird-or-egg
    let tag-for-this-destination-flag one-of selection-tags with [owned-by = this-player-number]
    let possible-destination-patch patch-at snap-xcor snap-ycor

    ask possible-destination-patch [set is-destination-patch-illegal? is-other-players-cage-or-occupied-site? this-player-number this-user-id ]

    ifelse is-destination-patch-illegal? [
    ;; deselect all bird and start over in detecting selection
       deselect-all-my-birds-and-eggs this-player-number
    ]
    ;; the destination patch is not illegal, so assign destination patch to the bird
    [
      ask currently-selected-birds-or-eggs [set destination-patch  possible-destination-patch set-as-only-transporting]
      ask possible-destination-patch [
        set reserved? true
        sprout 1 [
          set breed destination-flags
          set owned-by this-user-id
          set color (lput 150 extract-rgb (player-tag-and-destination-flag-color this-player-number ) )
          set size 1.0
        ]
      ]
    ]
  ]
end 

to set-as-only-selected
  set transporting? false
  set selected? true
  set breeding? false
end 

to set-as-only-transporting
  set transporting? true
  set selected? false
  set breeding? false
end 

to set-as-only-breeding
  set transporting? true
  set selected? false
  set breeding? false
end 

to deselect-all-my-birds-and-eggs [my-player-number]
   ask (turtle-set birds eggs) with [selected?] [set selected? false]
   ask selection-tags with [owned-by = my-player-number]  [die]
end 

to remove-tags [bird-owned-by]
  ask selection-tags with [bird-owned-by = owned-by]  [die]
end 

to remove-destination-flags [bird-owned-by]
  ask destination-flags with [bird-owned-by = owned-by]  [die]
end 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;; genotype & phenotype reporters  ;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to-report inherited-first-genes
  let mother-loci (random 2)
  let father-loci (random 2)
  let mother-allele ""
  let father-allele ""
  ask parent-female [set mother-allele (item mother-loci first-genes)]
  ask parent-male [set father-allele  (item father-loci first-genes)]
  report (word mother-allele father-allele)
end 

to-report inherited-third-genes
  let mother-loci (random 2)
  let father-loci (random 2)
  let mother-allele ""
  let father-allele ""
  ask parent-female [set mother-allele (item mother-loci third-genes)]
  ask parent-male [set father-allele  (item father-loci third-genes)]
  report (word mother-allele father-allele)
end 

to-report inherited-second-genes
  let mother-loci (random 2)
  let father-loci (random 2)
  let mother-allele ""
  let father-allele ""
  ask parent-female [set mother-allele (item mother-loci second-genes)]
  ask parent-male [set father-allele  (item father-loci second-genes)]
  report (word mother-allele father-allele)
end 

to-report inherited-fourth-genes
  let mother-loci (random 2)
  let father-loci (random 2)
  let mother-allele ""
  let father-allele ""
  ask parent-female [set mother-allele (item mother-loci fourth-genes)]
  ask parent-male [set father-allele  (item father-loci fourth-genes)]
  report (word mother-allele father-allele)
end 

to-report inherited-sex-genes
  let mother-loci (random 2)
  let father-loci (random 2)
  let mother-allele ""
  let father-allele ""
  ask parent-female [set mother-allele (item mother-loci sex-gene)]
  ask parent-male [set father-allele  (item father-loci sex-gene)]
  report (word mother-allele father-allele)
end 

to-report random-first-genes
  ifelse random 2 = 0 [report "A"] [report "a"]
end 

to-report random-second-genes
  ifelse random 2 = 0 [report "B"] [report "b"]
end 

to-report random-third-genes
  ifelse random 2 = 0 [report "C"] [report "c"]
end 

to-report random-fourth-genes
  ifelse random 2 = 0 [report "D"] [report "d"]
end 

to-report random-sex-genes  ;; sex chromosomes in birds are designated either W or Z
  ifelse random 2 = 0 [report "WZ"] [report "ZZ"]
end 

to-report is-male?   ;; male birds are the homozygote (this is unlike humans where the male is XY)
  ifelse sex-gene = "ZZ" [report true] [report false]
end 

to-report is-female?  ;; female birds are the heterozygote (this is unlike humans where the female is XX)
  ifelse sex-gene = "WZ" [report true] [report false]
end 

to-report both-sexes-exist?
  ifelse (any? birds with [is-male?] and any? birds with [is-female?])  [report true] [report false]
end 

to-report both-first-trait-alleles-exist?
  ifelse (frequency-allele-dominant-first-trait > 0 and frequency-allele-recessive-first-trait  > 0)  [report true] [report false]
end 

to-report both-second-trait-alleles-exist?
  ifelse (frequency-allele-dominant-second-trait > 0 and frequency-allele-recessive-second-trait  > 0) [report true] [report false]
end 

to-report both-third-trait-alleles-exist?
  ifelse (frequency-allele-dominant-third-trait > 0 and frequency-allele-recessive-third-trait  > 0) [report true] [report false]
end 

to-report both-fourth-alleles-exist?
  ifelse (frequency-allele-dominant-fourth-trait > 0 and frequency-allele-recessive-fourth-trait  > 0) [report true] [report false]
end 

to-report how-many-target-traits  ;; used to determine how many desirable traits a bird has, based on its genotype
   let #-target-traits 0
   if first-genes  =  "aa"  [set #-target-traits #-target-traits + 1]
   if second-genes =  "bb"  [set #-target-traits #-target-traits + 1]
   if third-genes  =  "cc"  [set #-target-traits #-target-traits + 1]
   if fourth-genes  =  "dd"  [set #-target-traits #-target-traits + 1]
   report #-target-traits
end 

to-report lookup-phenotype-for-gene [x]
  let item-counter 0
  let target-phenotype 0
  let target-item 0
  repeat length genes-to-phenotype [   ;; go through the entire genes to phenotype map
    if (item 0 (item item-counter genes-to-phenotype)) = x
      [set target-phenotype (item 1 (item item-counter genes-to-phenotype))]   ;; when the genotype is find, assign the corresponding phenotype to target-phenotype
    set item-counter (item-counter + 1)
  ]
  set item-counter 0
  report target-phenotype
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;; eligibility & state of bird/egg reporters  ;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to-report has-one-mate-in-nest? [this-site-id]
  let birds-at-site-id birds-on patches with [site-id = this-site-id]
  let report? false
  let eligible-males birds-at-site-id with [is-male? and not selected? and not transporting? and not just-bred?]
  if (count eligible-males = 1)  [
    set report? true
    set parent-male one-of eligible-males
    ask eligible-males [set breeding? true]
  ]
  report report?
end 

to-report in-cage?
  ifelse (patch-owned-by != 0) [report true] [report false]
end 

to-report is-bird-or-egg-owned-by-this-player? [this-player-number]
  ifelse this-player-number = owned-by [report true] [report false]
end 

to-report is-my-egg? [my-player-number]
  ifelse my-player-number = owned-by and breed  = eggs [report true] [ report false]
end 

to-report which-player-bird-or-egg-is-this? [bird]
  let this-is-owned-by 0
  ask bird [set this-is-owned-by owned-by]
  report this-is-owned-by
end 

to-report player-tag-and-destination-flag-color [this-player-number]
  let the-color 0
  if this-player-number = 1 [set the-color player-1-tag-color]
  if this-player-number = 2 [set the-color player-2-tag-color]
  if this-player-number = 3 [set the-color player-3-tag-color]
  if this-player-number = 4 [set the-color player-4-tag-color]
  report the-color
end 

to-report is-selectable-by-me? [my-player-number]
  ifelse not breeding? and not selected? and not transporting? and is-bird-or-egg-owned-by-this-player? my-player-number
    [report true]
    [report false]
end 

to-report is-ready-for-mating?
  let response false
  if is-female? and is-at-mating-site? and not breeding? and not transporting? and not selected? and not just-bred? and destination-patch = nobody
    [set response true]
  report response
end 

to-report is-at-mating-site?
  ifelse site-id != 0 [report true][report false]
end 

to-report is-goal-bird-and-in-cage?
  ifelse ( first-genes = "aa" and second-genes = "bb" and third-genes = "cc" and fourth-genes = "dd" and sex-gene = "ZZ" and breed = birds and is-a-cage?)
    [report true]
    [report false]
end 

to-report is-other-players-cage-or-occupied-site? [this-player-number this-user-id ]
  let validity? false
  if ((patch-owned-by >= 1 and patch-owned-by <= 4) and patch-owned-by != this-player-number)  [set validity? true ]   ;;You can not move a bird/egg to another players cage or dna sequencer
  if (any? other birds-here or any? other eggs-here) [set validity? true ]                 ;; You can not move a bird/egg on top of another bird/egg
  report validity?
end 

to-report is-a-cage?
  ifelse (patch-owned-by > 0 and patch-owned-by <= 4) [report true] [report false]
end 

to-report is-a-release-site?
   ifelse (patch-owned-by = 0 and site-id = 0) [report true]  [report false]
end 

to-report is-a-sequencer-site?
   ifelse (patch-owned-by = owned-by and any? DNA-sequencers-here) [report true]  [report false]
end 

to-report this-players-short-name [this-owned-by]
  let name-of-player ""
  if any? players with [player-number = this-owned-by] [
     ask one-of players with [player-number = this-owned-by] [set name-of-player user-id ]]
  if length name-of-player > 6 [set name-of-player substring name-of-player 1 7 ]
  report name-of-player
end 

to-report game-not-filled?
  ifelse count players with [not assigned?] < 4  [report true] [report false]
end 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;; instructions for players ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to-report current-instruction-label
  report ifelse-value (current-instruction = 0)
    [ "press setup" ]
    [ (word current-instruction " / " length instructions) ]
end 

to next-instruction
  show-instruction current-instruction + 1
end 

to previous-instruction
  show-instruction current-instruction - 1
end 

to show-instruction [ i ]
  if i >= 1 and i <= length instructions [
    set current-instruction i
    clear-output
    foreach item (current-instruction - 1) instructions output-print
  ]
end 

to-report instructions
  report [
    [
     "You will be running a selective breeding"
     "program, attempting to develop a breed "
     "of fancy looking birds."
    ]
    [
     "There are 4 players working together on"
     "a team and you are one of them.  Each "
     "player starts with 3 birds in six of the"
     "cages they own."
    ]
    [
      "To breed birds, a male and female bird"
      "must be moved to one of the 6 breeding"
      "rectangles in the middle of the world."
    ]
    [
      "To do this click on a bird and hold the"
      "mouse button down the entire time while"
      "you drag the cursor to the breeding"
      "rectangle.  Then release the mouse button."
      "Eggs will appear where birds have bred."
    ]
    [
      "You must move an egg back to your cage to "
      "hatch it.  Birds that have mated also need"
      "to be returned to a cage before it is"
      "ready to mate again"
    ]
    [
      "You can set an egg or a bird that you"
      "own free.  To do so, click the mouse"
      "button, and hold and drag the egg or "
      "bird onto one of the grassy squares."
      "Then release the mouse button."
    ]
    [
      "You ultimate goal is to breed the"
      "#-of-required-goal-birds, each"
      "having a blue head cap, pink chest,"
      "purple wing and red tail."
    ]
    [
      "See if you can accomplish your goal "
      "in less matings than other teams."
      "Press GO if you are ready to begin."
      "Good luck!"
    ]
  ]
end 


; Copyright 2011 Uri Wilensky.
; See Info tab for full copyright and license.

There are 4 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky about 12 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 5.0 Download this version

Attached files

File Type Description Last updated
Bird Breeders.png preview Preview for 'Bird Breeders' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.