如何绘制由两个不同品种创建的孵化品种

How to plot hatch-breed created by two different breeds

我在绘制使用影线创建的对象时遇到了一些麻烦。 我想分别绘制由工程师 A 和工程师 B 创建的对象。 在 JenB 的回答之后,我为此目的使用的代码是

sk one-of turtles with [breed = engineersA or breed = engineersB]

    [ if empty? my-list
      [ set size random-float 1
      ]


        hatch-objects random 10
          [ hide-turtle
            ask myself
            [ set my-list fput self my-list
            ]
          ]
        ]

我尝试做的是

ask engineersA [plotxy ticks objects]

工程师B也一样

不幸的是,由于对象作为一个品种,它不起作用。

希望你能帮帮我。

您的填充对象代码中的上下文存在问题,尤其是 "self" 和 "myself" 所采用的值。编写的代码永远不会将任何对象放在我的列表中。解释起来很困难,所以我写了冗长的代码(运行)?设置中的变量。如果你设置冗长?为真,打印命令将打印出代码的每个步骤中发生的事情。 (如果将其设置为 false,打印命令将不会打印任何内容。)

代码末尾是我用来绘制每种工程师创建的对象计数图的命令。那里的代码中记录了这一点,它工作正常。

我决定在每个对象中存储 "A" 或 "B" 的文本值,以显示创建该对象的品种。将品种存储在该变量中并对其进行测试是一个问题,所以我只使用了有效的文本。

我把海龟做得很大,这样它们很容易点击检查。

这应该足以让您了解如何计算和存储您想做的其他事情。

globals [
verbose?  ;; set this true to print out debugging info
count-type-a  ;; count of objects created by engineersA
count-type-b  ;; count of objects created by engineersB
]

breed [engineersA engineerA]
engineersA-own [ my-list]

breed [engineersB engineerB]
engineersB-own [my-list]

breed [objects object]
objects-own[
creator-breed  ;; set to either "A" or "B"
]

to setup
  clear-all
  set verbose? true   ;; turns on and off debugging print statements

  create-engineersA 3 [
    setxy random-xcor random-ycor
    set label who set size 3
    set my-list []
    ]

 create-engineersB 3 [
    setxy random-xcor random-ycor
    set label who set size 3
    set my-list []
    ]


  reset-ticks
end

to go
  let breed-picked "none"

  ask one-of turtles with [breed = engineersA or breed = engineersB]

    [
    ;;set breed-picked breed   ( produces a result that looks like a string but isn't)

    if-else ( breed = engineersA) [
      if verbose? [ print " this is breed engineersa "]
      set breed-picked "A" ]
    [ set breed-picked "B" ]

    if verbose? [ print ( word  "we are looking at turtle " who  " now, which is breed " breed-picked) ]

    if   my-list = []
      [
        if verbose? [print "my-list is empty"]
        ; set size random-float 1
      ]


        hatch-objects 3
          [
            set size 3 set color yellow set shape "circle"
            set creator-breed breed-picked
            if verbose? [
             print ( word " in hatch-objects, myself = " myself)
             print ( word " in hatch-objects, self = " self)
            ]

            let object-tag self ;; so this will persist into ask myself
            hide-turtle
            ask myself
            [     
                 if verbose? [
                  print ( word " in ask myself, self = " self )
                  print ( word " in ask myself, object-tag = " object-tag)
                  print ( word " who of object-tag " [who] of object-tag )
                 ]

                  set my-list fput object-tag my-list
        if verbose? [ print ( word   "hatched an object,  my-list is now " my-list)]
            ]


          ]
     ]
  if verbose? [ ask objects [ print creator-breed]]

   set count-type-a count objects with[ creator-breed = "A" ]
   set count-type-b count objects with[ creator-breed = "B" ]
   print ( word "count of objects created by engineersA is now " count-type-a)
   print ( word "count of objects created by engineersB is now " count-type-b)

   ;;  The following code works. I'm sure there are better ways to do it.
   ;;  The interface has a plot called "plot 1"
   ;;  Within that plot object, two pens were created, called "type-a" and "type-b"
   ;;      and the pens were given different colors.
   ;;  The check box for "show legend" was checked.
   ;;  Everything else was left at default values. The plot commands were left blank.

   set-current-plot "plot 1"   
   set-current-plot-pen "type-a"
   plot count-type-a

   set-current-plot-pen "type-b"
   plot count-type-b

end