【问题标题】:Run multiple procedures at the same time in netlogo在netlogo中同时运行多个程序
【发布时间】:2015-02-25 02:13:59
【问题描述】:

您好,我有以下代码:

        to go
            move
            play-papelvstije
            play-papelvsrock
            play-tijevsrock
            play-tijevspapel
            play-rockvspapel
            play-rockvstije
        end


        to play-rockvspapel
            ask turtles with [color = red]
                [
                let nearby other turtles in-radius 1
                if any? nearby with [color = green]
                [
                set color green 
                ]
                ]
        end

        to play-papelvstije 
            ask turtles with [color = green]
            [
            let nearby other turtles in-radius 1
            if any? nearby with [color = blue]
            [
            set color blue  
            ]
            ]
        end

       to play-tijevsrock
            ask turtles with [color = blue]
            [ 
            let nearby other turtles in-radius 1
            if any? nearby with [color = red]
            [
            set color red  
            ] 
            ]
        end

        to play-rockvstije
            ask turtles with [color = red]
            [
            let nearby other turtles in-radius 1
            if any? nearby with [color = blue]
            [
            set color red 
            ]
            ]
            end

        to play-papelvsrock
            ask turtles with [color = green]
            [
            let nearby other turtles in-radius 1
            if any? nearby with [color = red]
            [
            set color green 
            ]
            ]
        end

        to play-tijevspapel
            ask turtles with [color = blue]
            [
            let nearby other turtles in-radius 1
            if any? nearby with [color = green]
            [
            set color blue
            ]
            ]
        end

如你所见,我运行这个程序 play-papelvstije play-papelvsrock play-tijevsrock, play-tijevspapel, play-rockvspapel, play-rockvstije 以这个确切的顺序运行,所以当运行模拟时,我的结果,因为要运行的第一个命令是最终人口增加的命令,所以我想做的是找到一种方法来运行此过程,但只需一个命令。我尝试过使用“foreach”和“map”命令,但没有得到结果。有什么建议吗?

【问题讨论】:

    标签: performance command netlogo procedures agents


    【解决方案1】:

    一种解决方案可以是不直接询问蓝海龟,而是询问所有海龟......类似

    to setup
      clear-all
      create-turtles 100 [
       set color red
       setxy random-pxcor random-pycor
      ]
      ask n-of 10 turtles [
       set color green 
      ]
      ask n-of 10 turtles with [color = red][
       set color blue 
      ]
    
    
      reset-ticks
    end
    
    to go
      move
      changeColor
      tick
    end
    
    to move
      ask turtles [
        rt random-float 90
        lt random-float 90
        fd 1
      ]
    end
    
    to changeColor
      ask turtles [
        let mycolor color
        let nearby other turtles in-radius 1
        if mycolor = blue [
           if any? nearby with [color = green]
            [
              set color blue
            ]
           if any? nearby with [color = red]
            [
              set color red  
            ]  
        ]
        if mycolor = green [
           if any? nearby with [color = red]
            [
              set color green 
            ]
           if any? nearby with [color = blue]
            [
              set color blue  
            ]
        ]
        if mycolor = red [
           if any? nearby with [color = red][
            if any? nearby with [color = blue]
            [
              set color red 
            ]
            if any? nearby with [color = green]
            [
              set color green 
            ]
           ]
        ]
      ]
    end
    

    【讨论】:

      猜你喜欢
      • 2014-08-22
      • 1970-01-01
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-20
      • 2019-07-06
      相关资源
      最近更新 更多