Foxes and Rabbits NetLogo Model

Produced for the book series "Artificial Intelligence";

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

powered by NetLogo

view/download model file: Foxes-and-Rabbits.nlogo

WHAT IS IT?

This model shows how to use breeds to create two different breeds of turtle agents - foxes and rabbits - that can have different properties such as colour. It creates 100 fox agents and 1000 rabbit agents at random locations in the environment.


THE INTERFACE

The setup button will recreate a new population of foxes and rabbits at random locations.


HOW IT WORKS

It uses two turtle agent breeds, foxes and rabbits, and shows how you can use the turtles-own command so that both breeds end up with common variables - age and gender.

The setup command simply calls the create-foxes and create-rabbits command to create the agents.


HOW TO USE IT

You can't really use it for anything, except for pressing the setup button several times to see how the agents spread themselves throughout the environment.


WHAT IS ITS PURPOSE?

Its purpose is to show how to define and create breeds of agents.


EXTENDING THE MODEL

Try adding two sliders that control the number of agents created when the setup button is pressed.

Try changing the shapes of the agents so that they look like foxes and rabbits. Hint: You will need to use the Turtle Shapes Editor to create the shapes.


RELATED MODELS

See the Foxes and Rabbits 2 model.


CREDITS AND REFERENCES

To refer to this model in publications, please use:

Teahan, W. J. (2010). Foxes and Rabbits NetLogo model.
Artificial Intelligence. Ventus Publishing Aps.


PROCEDURES

; Foxes and Rabbits model.
;
; Creates some fox and rabbit turtle agents in the environment at random.
;
; Copyright 2010 William John Teahan. All Rights Reserved.
;
breed [foxes fox]
breed [rabbits rabbit]

turtles-own [age gender]

to setup
  clear-all ;; clear everything
  
  create-foxes 100 [
    set age 0
    set size 2
    set color brown
    ifelse random 2 = 0
      [set gender "Male"]
      [set gender "Female"]
    setxy random-xcor random-ycor
  ]

  create-rabbits 1000 [
    set age 0
    set size 2
    set color white
    ifelse random 2 = 0
      [set gender "Male"]
      [set gender "Female"]
    setxy random-xcor random-ycor
  ]
end
;
; Copyright 2010 by William John Teahan.  All rights reserved.
;
; Permission to use, modify or redistribute this model is hereby granted,
; provided that both of the following requirements are followed:
; a) this copyright notice is included.
; b) this model will not be redistributed for profit without permission
;    from William John Teahan.
; Contact William John Teahan for appropriate licenses for redistribution for
; profit.
;
; To refer to this model in publications, please use:
;
; Teahan, W. J. (2010).  Foxes and Rabbits NetLogo model.
;   Artificial Intelligence. Ventus Publishing Aps
;