breed [species3 a-species3] ;;
turtles-own [energy rnumber dnumber]

to setup
  clear-all

  settle-species1
     set-default-shape species3 "frog top"
  create-species3 sp3-start-number [
    set color green
    set size 2.5
    setxy random-xcor random-ycor
    set energy 15
    set rnumber random-normal 50 5
    set dnumber random-normal 52 5
  ] ;; use slider for initial number, starting energy level is 15

reset-ticks

if (file-exists? "speciesgrowth.csv")
  [file-delete "speciesgrowth.csv"]

  file-open "speciesgrowth.csv"
  file-type "time,"
  file-type "N1,"
  file-print "N3"
  file-close

  ifelse count turtles = 0 [ ]

  [file-open "speciesgrowth.csv"
  ask one-of turtles
  [
  file-type (word ticks ",")
  file-type (word count patches with [ pcolor = 5 ] ",")
  file-print count species3
  ]
  file-close
  ]

  if ( file-exists? "sp3output.csv") ; output file setup
  [file-delete "sp3output.csv"]
file-open "sp3output.csv"
file-type "individual,"
file-type "rnumber,"
file-print "dnumber,"
file-close

  ifelse count turtles = 0 [ ]

  [file-open "sp3output.csv"
  ask turtles
  [
    file-type (word who "," )
    file-type (word rnumber ",")
    file-print (word dnumber )
  ]
  file-close
  ]

end



to go
  grow-species1
  ask species3
  [ move
    sp3-eat-species1
    sp3-reproduce
    death ]

  file-open "speciesgrowth.csv"
  file-type (word ticks ",")
  file-type (word count patches with [ pcolor = 5 ] ",")
  file-print count species3
  file-close

  tick

end

to settle-species1 ;; slider determines initial number of species 1 patches
  ask n-of sp1-start-number patches [ set pcolor 5 ]
end

to grow-species1 ;; determines numbers of species 1 added each step
 ask n-of sp1-growth-rate patches [ set pcolor 5 ]
end


to sp3-eat-species1
  if pcolor = 5
  [ set pcolor black
    set energy energy + 5 ]
end


to sp3-reproduce
  if energy > 100
    [ set energy (energy - (0.25 * energy))
      hatch 1 [
        set color green
        set rnumber random-normal 50 5
        set dnumber random-normal 52 5
        set energy ((energy / 0.75) - energy)
        bk 1 ] ]
end


to move ;; turtle with cost of 1 energy for each movement
  rt random 50
  lt random 50
  fd 2
  set energy energy - 1
end

to death
  if energy < 0 [ die
  ]
end