ожидаемый ввод будет числом, но вместо этого получил TRUE / FALSE true - PullRequest
0 голосов
/ 15 марта 2020

Я хочу написать эвакуацию с кодом лидера в net -lo go, но у меня есть эта ошибка (И ожидалось, что вход будет ИСТИНА / ЛОЖЬ, но вместо этого получил число 0). Ошибка пришла из функции ( follow_leader). Мой проект состоит в том, чтобы я эвакуировал окружающую среду и эвакуировал ее с ближайшим лидером из толпы. код не идеален, потому что я знал, что нетло go.

это мой код

globals[  goal-x goal-y n number leader
  percent_of_leader wall
window
door largecircle]

patches-own [path?
 obstacle
 goal]
turtles-own [direction
  fast?
  fear?
  leader?
is-leader?
  follower
  other-nearby]


to setup
    clear-all
set-default-shape turtles "person"
  ;create-turtles 50 [ set color yellow ]
  ;ask turtles [fd random 13 ]
  drwa-walls


    ask n-of population patches with [ pcolor = black]
   [sprout 1
   [ set color white
     set size 0.9
     set shape "person"
    set leader? false
      ;set follower self
   if   xcor < 9 and ycor > 9 [set heading 0]
     if xcor >= 9  and ycor >= -10[set heading -90]
   if xcor > -12 and ycor < -10 [set heading 90]
     if  xcor <= -8  and  ycor > -10  and ycor < 0 [set heading 180]
  ]]

    choose-leaders

 end


 to choose-leaders
   ask turtle 6
     [
     set leader? true
     set color yellow
     set size 1
      set shape "default"
     set leader self
      set xcor 3
      set ycor 10
      set heading 0
   ]
 end


to go
  move-for

  ask turtle 6[move-to-exit1
  fd 1 ]

    ask turtles with [shape = "person"][

    ifelse  (xcor < 9 and ycor > 9 ) [follow_leader] [move-to-exit1]
 if xcor >= 9  and ycor >= -10  [move-to-exit2]
     if xcor > -12 and ycor < -10 [move-to-exit3]
     if xcor < -12 and ycor < -10 [move-to-exit3]
    if xcor <= -8  and  ycor > -10  and ycor < 0 [move-to-exit4]
    ;avoid obstcao
    ; avoid_obstacles
 ;ifelse [pcolor] of patch-ahead 1 = blue
    ; [ lt random-float 360 ]   ;; We see a blue patch in front of us. Turn a random amount.
      ;[ fd 1 ]                  ;; Otherwise, it is safe to move forward.

   ; ifelse not is-patch? patch-ahead 3 or [ pcolor ] of patch-ahead 3 =
 ;blue or not is-patch? patch-ahead 2 or [ pcolor ] of patch-ahead 2 =
 ;blue or not is-patch? patch-ahead 1 or [ pcolor ] of patch-ahead 1 =
;blue
    ;[lt random-float 360 ]
   ;[fd 1]
      ;  while [patch-ahead 1 = nobody]
   ;[
     ;lt random-float 360
   ;]
  ;ifelse [pcolor] of patch-ahead 1 = blue
     ; [ lt random-float 360 ]   ;; We see a blue patch in front of us. Turn a random amount.
      ;[ fd 1 ]

      ; ifelse not is-patch? patch-ahead 3 or [ pcolor ] of patch-ahead 3 =
 ;white or not is-patch? patch-ahead 2 or [ pcolor ] of patch-ahead 2 =
 ;white or not is-patch? patch-ahead 1 or [ pcolor ] of patch-ahead 1 =
;white
   ; [lt random-float 360 ]
   ; [fd 1]
        ;ifelse not is-patch? patch-ahead 3 or [ pcolor ] of patch-ahead 3 =
 ;green or not is-patch? patch-ahead 2 or [ pcolor ] of patch-ahead 2 =
;green or not is-patch? patch-ahead 1 or [ pcolor ] of patch-ahead 1 =
;green
    ;[lt random-float 360]
   ; [fd 1]

  ]
   reset-ticks
   tick


  end
to rt-random
   while [patch-ahead 3 = nobody]
   [
     rt random 360
   ]
end

to avoide
ask turtles [
if [pcolor] of patch-ahead 1 = green
[lt random 360 fd 1]

]
end



to avoid_obstacles ;; all obstacles set as green patches
 let i 1
 while [[pcolor] of patch-ahead i != blue ]
 [set i (i + 1) ]
  if ([pcolor] of patch-ahead i = blue)
   [
    ifelse [pcolor] of patch-at-heading-and-distance (heading - 20) i + 1 = blue
    [
        ifelse [pcolor] of patch-at-heading-and-distance (heading + 20) i + 1 = blue
        [
            ifelse random 1 = 0
            [ rt 360 ]
            [ lt 360]
        ]
        [ rt 360 ]
    ]
    [lt 360]
   ]
 end

;;;;;;;;;;;;;;;;;;;;;;;;;;;
to bounce
  if [pcolor] of patch-at dx 8 = blue [
    set heading (90)
  ]
  if [pcolor] of patch-at 0 dy = blue [
    set heading (-90)
  ]
end
;;;;;;;;;;;;;;;;;;;;;;;
to move-for
  ask turtles with [shape = "person"][fd 1]


end
to drwa-walls
  draw-exit1
  draw-exit2
  draw-exit3
  draw-exit4
  ;rows x
  ask patches with [pxcor <= 30 and pxcor >= 0 and pycor = -10]
  [set pcolor blue]
    ask patches with [pxcor >= -30 and pxcor <= 0 and pycor = 9]
  [set pcolor blue]
  ;coilmn
  ;ask patches with [pycor <= 9 and pycor >= -10 and pxcor = 0]
  ;[set pcolor green]
   ;ask patches with [pycor <= 4 and pycor >= 0 and pxcor = 0]
  ;[set pcolor green]
  ;circle shape

  ask patch -14 -9 [
  set largecircle patches in-radius (2)
]
;set color of largecircle patches green
ask largecircle [
  set pcolor green
]
   ask patch 16 16 [
  set largecircle patches in-radius (2)
]
;set color of largecircle patches green
ask largecircle [
  set pcolor white
]
end

to draw-exit1
  ;exits at top of concourse area, where turtles will leave
  set goal-x -1
  set goal-y -30
  ask patch goal-x goal-y [
    sprout 1 [ set pcolor red
      set shape "square"
    ]
  ]
end

to draw-exit2
  set goal-x -1
  set goal-y 30
  ask patch goal-x goal-y [
    sprout 1 [ set pcolor red
      set shape "square"
    ]
  ]
end

to draw-exit3
  set goal-x -30
  set goal-y -6
  ask patch goal-x goal-y [
    sprout 1 [ set pcolor red
      set shape "square"
    ]
  ]
end

to draw-exit4
  set goal-x 30
  set goal-y 4
  ask patch goal-x goal-y [
    sprout 1 [ set pcolor red
      set shape "square"
    ]
  ]
end

;;;;;;;;;;;;;;;;;;;;;;exit goals;;
to move-to-exit1
  facexy -1 30
end

to move-to-exit2
  facexy 30 4
end

to move-to-exit3
  facexy -1 -30
end

to move-to-exit4
  facexy -30 -6
end
;;;;;;;;;;;;;;;;;;;;;;;;;;

;to follow-leader
     ;if not leader?           ;; we only want to ask non-leaders
    ;[let nearby-leaders turtles with [leader? and distance myself < 3] ;; find nearby leaders
    ;if any? nearby-leaders                                            ;; to avoid 'nobody'-error, check if there are any first
   ;  [ set heading (towards min-one-of nearby-leaders [distance myself]) ]]              ;; then face the one closest to myself
  ; end
;;;;;;;;;;;;;;;;;;;;;;;;;;
to follow_leader
  let nearby-leaders turtles with [is-leader? and distance myself < 10] ;; nearby leaders
  if any? nearby-leaders[
    face min-one-of nearby-leaders [distance myself]
  fd 0.5]

end

1 Ответ

1 голос
/ 15 марта 2020

В будущем, пожалуйста, предоставьте только соответствующий код. Для NetLo go это обычно процедура, которая выдает ошибку (или не работает правильно и т. Д. c) и какую бы процедуру она ни вызывала.

В вашем случае это процедура, которую вы упомянули:

to follow_leader
  let nearby-leaders turtles with [is-leader? and distance myself < 10]
  if any? nearby-leaders[
    face min-one-of nearby-leaders [distance myself]
  fd 0.5]
end

Таким образом, and, который выдает ошибку, должен быть [is-leader? and distance myself < 10] (также, пожалуйста, укажите, какая строка, если вы это знаете). Я думаю, что вы не инициализировали переменную is-leader? так что это 0 (значение по умолчанию) вместо true или false.

Если это проблема, где бы вы ни создавали черепах, начните с set is-leader? false

...