开发者

NetLogo scoring system for distance travelled

I have a problem with my NetLogo scoring system. When a turtle goes over three square blocks I cannot get it to show the increments on my score monitor. Could someone please help?

My code so far:

breed [ defaults default ]
defaults-own  [ new-heading开发者_Go百科 ]

breed [squares1 square]
breed [squares2 square]
breed [squares3 square]

globals [
  score         


]



to setup-row [row colour segments]
  foreach segments
  [
      if pycor = row * row-patches-width and
        (pxcor >= col-patches-width * (item 0 ?)) and (pxcor <= col-patches-width * (item 1 ?))
          [set pcolor colour]
  ]
end

to setup-col [col colour segments]
  foreach segments
  [
      if pxcor = col * col-patches-width and
        (pycor >= row-patches-width * (item 0 ?)) and (pycor <= row-patches-width * (item 1 ?))
          [set pcolor colour]
  ]
end

to setup-arwels-maze

  clear-all
  set score 0
  setup-defaults 
  setup-squares1 
  setup-squares2
  setup-squares3 

  ask patches
  [
      if (pxcor >= min-pxcor and pxcor <= max-pxcor and
        pycor >= min-pycor and pycor <= max-pycor)
          [set pcolor black] 


      setup-row  8  white [[-15 15]]
      setup-row  6  white [[-15 -10][10 15]]
      setup-row  3  white [[-15 -10][10 15]]
      setup-row  6  white [[-4 4]]
      setup-row  4  white [[-6 6]]
      setup-row -1  white [[-2 2]]
      setup-row -3  white [[-4 4]]
      setup-row  1  white [[-3 3]]
      setup-row  0  white [[-15 -10][10 15]]
      setup-row -4  white [[-15 -10][10 15]]
      setup-row -7  white [[-15 -10][10 15]]
      setup-row -6  white [[-3 -2][2 3]]
      setup-row -9  white [[-3 3]]
      setup-row -11 white [[-11 11]]
      setup-row -13 white [[-15 15]]


      setup-col  15 white [[ 0 8][-13 -4]]
      setup-col  10 white [[-7 -4][0 3]]
      setup-col  12 white [[ 3 4]]
      setup-col  7  white [[-7.5 2][6 8]]
      setup-col  3  white [[-9 -6][1 4]]
      setup-col  0  white [[-3 -1]]
      setup-col -3  white [[-9 -6][1 4]]
      setup-col -7  white [[-7.5 2][6 8]]
      setup-col -10 white [[-7 -4][0 3]]
      setup-col -12 white [[ 3 4]]
      setup-col -15 white [[ 0 8][-13 -4]]
  ]

end

to setup-defaults
  create-defaults 1
  [ set color yellow
    set shape "default"
    set size 4
    setxy 2 -48
    set heading 0




      ]
end

to setup-squares1
   create-squares1 1
     [ 
    set shape "square"
    set color random 14 * 10 + 5
    set size 3
    setxy 38 28
    set heading 0


      ]
end

to setup-squares2
   create-squares2 1
     [ 
    set shape "square"
    set color random 14 * 10 + 5
    set size 3
    setxy -5 -8
    set heading 0

      ]
end

to setup-squares3
   create-squares3 1
     [ 
    set shape "square"
    set color random 14 * 10 + 5
    set size 3
    setxy 40 -45
    set heading 0


      ]
end


to move-up
  ask defaults[ fd 1.00 ]

end

to move-right
  ask defaults [ rt 90 ]
end

to move-down
  ask defaults [ bk 1.00 ]
end

to move-left
  ask defaults [ lt 90 ]
end


To determine if there is a square1 in the same patch as a default you can do

ask defaults [ if (any? squares1-here) [...thenpart....][..elsepart...]]

if you want determine if there is a square1 within a distance of 5 of the default then use

ask defaults [if (any? squares1 in-radius 5) [....]]

I also note that your lines

breed [squares1 square]
breed [squares2 square]
breed [squares3 square]

are wrong. You cannot re-use 'square'. It should be

breed [squares1 square1]
breed [squares2 square2]
breed [squares3 square3]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜