Vision Cone Example 2 NetLogo Model

Produced for the book series "Artificial Intelligence";

Author: W. J. Teahan; Publisher: Ventus Publishing Aps, Denmark.

powered by NetLogo

view/download model file: Vision-Cone-Example-2.nlogo

WHAT IS IT?

This example demonstrates how to give a turtle a "cone of vision" in front of it. It uses the IN-CONE primitive to filter an agentset according to whether the turtles or patches in it are in the calling turtle's cone of vision.

In addition to IN-CONE, also available is IN-CONE-NOWRAP.

The code written by Uri Wilensky has been slightly modified by Bill Teahan for the following book:

Teahan, W. J. (2010). Artificial Intelligence. Ventus Publishing Aps.


PROCEDURES

; This code written by Uri Wilensky (see copyright message below)
; has been slightly modified by Bill Teahan for the following
; book:
;
; Teahan, W. J. (2010). Artificial Intelligence. Ventus Publishing Aps.
;
breed [ wanderers wanderer ]  ;; big red turtle that moves around
breed [ standers stander ]    ;; little gray turtles that just stand there

to setup
  clear-all
  ;; make a background of lots of randomly scattered
  ;; stationary gray turtles
  create-standers number-of-standers
  [
    setxy random-xcor random-ycor
    set color gray
  ]
  ;; make one big red turtle that is going to move around
  create-wanderers number-of-wanderers
  [
    set color red
    set size 15
  ]
  ;; make the vision cone initially visible
  go
end

to go
  ask standers [ set color gray ]
  ask wanderers
  [
    rt random 20
    lt random 20
    fd 1
    ;; could use IN-CONE-NOWRAP here instead of IN-CONE
    ask standers in-cone vision-radius vision-angle
    [
      set color white
    ]
  ]
  tick
end


; *** NetLogo 4.0.4 Code Example Copyright Notice ***
;
; (C) 2004 Uri Wilensky.  This code may be freely copied, distributed,
; altered, or otherwise used by anyone for any legal purpose.
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
; A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT
; OWNERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;
; *** End of NetLogo 4.0.4 Code Example Copyright Notice ***