Heros and Cowards (emergence extension)

Heros and Cowards (emergence extension) preview image

1 collaborator

Bob_mcleod Bob McLeod (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by the author
Model was written in NetLogo 5.2.0 • Viewed 168 times • Downloaded 11 times • Run 0 times
Download the 'Heros and Cowards (emergence extension)' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


## ACKNOWLEDGMENT

This model is a minor but interesting variation on a model from from Chapter Two of the book "Introduction to Agent-Based Modeling: Modeling Natural, Social and Engineered Complex Systems with NetLogo", by Uri Wilensky & William Rand.

* Wilensky, U. & Rand, W. (2015). Introduction to Agent-Based Modeling: Modeling Natural, Social and Engineered Complex Systems with NetLogo. Cambridge, MA. MIT Press.

This original model is in the IABM Textbook folder of the NetLogo Models Library. The model, as well as any updates to the model, can also be found on the textbook website: http://www.intro-to-abm.com/.

Most of this info is from the "Hero's and Cowards" model. I have added a few comments here and there. Indicated by ;; comment RDM

## UPDATES TO THE MODEL SINCE TEXTBOOK PUBLICATION

In the textbook version of the code, there is a slight chance that a turtle's friend is also its enemy. Here, we prevent this from happening by choosing the enemy of a turtle amongst the set of other turtles not including its friend.

Also, we could not resist adding a few interesting preset configurations. Have fun playing with them!

## WHAT IS IT?

The "Heroes and Cowards" game, also called the "Friends and Enemies" game or the "Aggressors and Defenders" game dates back to the Fratelli Theater Group at the 1999 Embracing Complexity conference, or perhaps earlier.

In the human version of this game, each person arbitrarily chooses someone else in the room to be their perceived friend, and someone to be their perceived enemy. They don't tell anyone who they have chosen, but they all move to position themselves either such that a) they are between their friend and their enemy (BRAVE/DEFENDING), or b) such that they are behind their friend relative to their enemy (COWARDLY/FLEEING).

This simple model demonstrates an idealized form of this game played out by computational agents. Mostly it demonstrates how rich, complex, and surprising behavior can emerge from simple rules and interactions.

## HOW IT WORKS

The rules of this model are that there are two basic personality types. All agents in the model choose a friend and an enemy. If their personality is BRAVE, then the agent tries to stay between their enemy and their friend, protecting their friend. If their personality is COWARDLY, then the agent tries to keep their friend between them and their enemy, hiding behind their friend.

## HOW TO USE IT

Choose the NUMBER of turtles you want to examine, and choose whether the turtles should act COWARDLY, BRAVE, or MIXED. Then press SETUP followed by GO to observe the patterns of behavior formed.

## THINGS TO NOTICE

Run the model many times and observe the different patterns of behavior.

INSPECT or WATCH some turtles so that you can see their individual behavior.

## THINGS TO TRY

Can you find new cool configurations with 68 turtles? How many different type can you find? What happens when you vary the number of turtles?

## EXTENDING THE MODEL

There is a bug we deliberately introduced in the SETUP of the model. Can you find it and fix it? Once you have fixed it, how does it affect the preset configurations?

Can you find new presets?

I believe I fixed the bug at least in this version RDM.

Modify the code to add more control over how many of each type of behavior there is.

Change the world wrapping rules to see how that effects the results.

You can create buttons that capture interesting patterns of behaviors by using the RANDOM-SEED function in NetLogo. First set the RANDOM-SEED to different values. PRESS SETUP then GO and observe the behaviors. We created a `preset` procedure that makes it easy to create your own buttons that produce interesting behaviors. This procedure assumes a population of 68 turtles with "mixed" behaviors, but you could modify it to allow different settings. Create your own buttons that produce interesting behaviors.

I added a couple of very cool buttons that basically introduce a degree of order. As party goers arrive the person that arrives just before them is their friend and just after their enemy. For LinearWrap this resembles a circular buffer, while for LinearNoWrap this resembles a queue. RDM

I also added gender, which was not too interesting as well as links which were informative. Red links are to enemies, blue to friends. RDM

## NETLOGO FEATURES

RANDOM-SEED initializes the NetLogo random number generator so that it always produces the same set of random numbers, enabling exact reproduction of model runs.

## CREDITS AND REFERENCES

Versions of the Model are described in:

Bonabeau, E., & Meyer, C. (2001). Swarm intelligence. A whole new way to think about business. Harvard Business Review, 5, 107-114.

Bonabeau. E. (2012). http://www.icosystem.com/labsdemos/the-game/ .

Bonabeau, E., Funes, P. & Orme, B. (2003). Exploratory Design Of Swarms. 2nd International Workshop on the Mathematics and Algorithms of Social Insects. Georgia Institute of technology, Atlanta, GA.

Sweeney, L. B., & Meadows, D. (2010). The systems thinking playbook: Exercises to stretch and build learning and systems thinking capabilities.

## HOW TO CITE

This model is part of the textbook, “Introduction to Agent-Based Modeling: Modeling Natural, Social and Engineered Complex Systems with NetLogo.”

If you mention this model or the NetLogo software in a publication, we ask that you include the citations below.

For the model itself:

* Stonedahl, F., Wilensky, U., Rand, W. (2014). NetLogo Heroes and Cowards model. http://ccl.northwestern.edu/netlogo/models/HeroesandCowards. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

Please cite the NetLogo software as:

* Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

Please cite the textbook as:

* Wilensky, U. & Rand, W. (2015). Introduction to Agent-Based Modeling: Modeling Natural, Social and Engineered Complex Systems with NetLogo. Cambridge, MA. MIT Press.

## COPYRIGHT AND LICENSE

Copyright 2014 Uri Wilensky.

![CC BY-NC-SA 3.0](http://ccl.northwestern.edu/images/creativecommons/byncsa.png)

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

turtles-own [ friend enemy ]
breed [females female]
breed [males male]
globals [i]
undirected-link-breed [red-links red-link]
undirected-link-breed [blue-links blue-link]

to setup      ;;Minor change added male and females (gender)  RDM
  clear-all
  ask patches [ set pcolor white ]  ;; create a blank background
  create-females number [
    setxy random-xcor random-ycor
    set shape "circle"
    set size 0.5
    ;; set the turtle personalities based on chooser
    if (personalities = "brave")     [ set color magenta ]
    if (personalities = "cowardly")  [ set color green ]
    if (personalities = "mixed")     [ set color one-of [ green magenta ] ]
    if (personalities = "mixed25Coward")   [ set color one-of [ green green magenta ] ]
    if (personalities = "mixed75Coward")   [ set color one-of [ green magenta magenta ] ]

    ;; choose friend and enemy targets
    set friend one-of other females
    set enemy one-of other females
    create-red-link-with enemy [set color red]      ;; Links added RDM
    create-blue-link-with friend [set color blue]   ;; Links added RDM
  ]

  create-males number [
    setxy random-xcor random-ycor
    set shape "circle"
    set size 0.5
    ;; set the turtle personalities based on chooser
    if (personalities = "brave")     [ set color blue ]
    if (personalities = "cowardly")  [ set color red ]
    if (personalities = "mixed")     [ set color one-of [ red blue ] ]
    if (personalities = "mixed25Coward")   [ set color one-of [ red red blue ] ]
    if (personalities = "mixed75Coward")   [ set color one-of [ red blue blue ] ]

    ;; choose friend and enemy targets
    set friend one-of other males
    set enemy one-of other males
    create-red-link-with enemy [set color red]
    create-blue-link-with friend [set color blue]
  ]

  reset-ticks
end 

to go
  ask  turtles with [color = red or color = blue or color = green or color = magenta] [
   ;; print who
    if (color = blue)  [ act-bravely ]
    if (color = red)   [ act-cowardly ]
    if (color = magenta)  [ act-bravely ]
    if (color = green)   [ act-cowardly ]
  ]
  tick
end 

to gomf     ;; Added male female go routine  RDM
  ask  males with [color = red or color = blue] [
   ;; print who
    if (color = blue)  [ act-bravely ]
    if (color = red)   [ act-cowardly ]
  ]
  ask  females with [color = green or color = magenta] [
   ;; print who
    if (color = magenta)  [ act-bravely ]
    if (color = green)   [ act-cowardly ]
  ]
  tick
end 

to act-bravely
  ;; move toward the midpoint of your friend and enemy
  facexy ([xcor] of friend + [xcor] of enemy) / 2
         ([ycor] of friend + [ycor] of enemy) / 2
         ;;fd 0.1
         ;;show [count turtles in-radius 1] of self
         if ([count turtles in-cone 1 60] of self < 20) [fd 0.1]   ;; Added simple collision avoidance RDM
         if ([count turtles in-radius 1] of self > 20)
         [
           facexy random-xcor random-ycor
           fd 0.1
         ]
end 

to act-cowardly
  ;; put your friend between you and your enemy
  facexy ([xcor] of friend + [xcor] of friend - [xcor] of enemy)
         ([ycor] of friend + [ycor] of friend - [ycor] of enemy)
         ;;fd 0.1
         if ([count turtles in-cone 1 60] of self < 20) [fd 0.1]   ;; Added simple collision avoidance RDM
         if ([count turtles in-radius 1] of self > 20)
         [
           facexy random-xcor random-ycor
           fd 0.1
         ]
end 

to preset [ seed ]
  ;; sets up the model for use with a particular random seed and constant
  ;; model parameters, so that a particular pattern can be re-created.
  set personalities "mixed"
  set number 68
  random-seed seed
  setup
end 

to one   ;; Added routine to have one person be everyone's friend and enemy
         ;; set all friends and enemies to the same turtle
         ;; also interesting to set friend and enemy to different turtles
  clear-all
  ask patches [ set pcolor white ]  ;; create a blank background
  create-turtles number [
    setxy random-xcor random-ycor

    ;; set the turtle personalities based on chooser
    if (personalities = "brave")     [ set color blue ]
    if (personalities = "cowardly")  [ set color red ]
    if (personalities = "mixed")     [ set color one-of [ red blue ] ]
    if (personalities = "mixed25Coward")   [ set color one-of [ red red blue ] ]
    if (personalities = "mixed75Coward")   [ set color one-of [ red blue blue ] ]

    ;; choose friend and enemy targets
    set friend turtle 1
    set enemy turtle 1
  ]
  reset-ticks
end 

to linearWrap  ;; Added Linear Wrap around or circular buffer order RDM
               ;; set all friend of turtle i to i+1 and enemy to i-1
               ;; connect first and last turtle
  clear-all
  ask patches [ set pcolor white ]  ;; create a blank background
  create-turtles number [
    setxy random-xcor random-ycor

    ;; set the turtle personalities based on chooser
    if (personalities = "brave")     [ set color blue ]
    if (personalities = "cowardly")  [ set color red ]
    if (personalities = "mixed")     [ set color one-of [ red blue ] ]
    if (personalities = "mixed25Coward")   [ set color one-of [ red red blue ] ]
    if (personalities = "mixed75Coward")   [ set color one-of [ red blue blue ] ]

    ;; choose friend and enemy targets
    set i 1
    while [i < (number - 1)]
    [
      ask turtle i [set friend  turtle (i + 1)]
      ask turtle i [create-link-with  (friend) [set color blue]]
      ask turtle i [set enemy turtle (i - 1)]
      ask turtle i [create-link-with  (enemy) [set color red]]
      set i i + 1
    ]
    ask turtle (number - 1 ) [set friend turtle 0]
    ask turtle (number - 1 ) [set enemy turtle (number - 2)]
    ask turtle 0 [set enemy turtle (number - 1)]
    ask turtle 0 [set friend turtle 1 ]


  ]
  reset-ticks
end 

to linearNoWrap  ;; Added Linear No Wrap around or queue order  RDM
                 ;; set all friend of turtle i to i+1 and enemy to i-1
                 ;; do not connect first and last turtle
  clear-all
  ask patches [ set pcolor white ]  ;; create a blank background
  create-turtles number [
    setxy random-xcor random-ycor

    ;; set the turtle personalities based on chooser
    if (personalities = "brave")     [ set color blue ]
    if (personalities = "cowardly")  [ set color red ]
    if (personalities = "mixed")     [ set color one-of [ red blue ] ]
    if (personalities = "mixed25Coward")   [ set color one-of [ red red blue ] ]
    if (personalities = "mixed75Coward")   [ set color one-of [ red blue blue ] ]

    ;; choose friend and enemy targets
    set i 1
    while [i < (number - 1)]
    [
      ask turtle i [set friend turtle (i + 1)]
      ask turtle i [create-link-with  (friend) [set color blue]]
      ask turtle i [set enemy turtle (i - 1)]
      ask turtle i [create-link-with  (enemy) [set color red]]
      set i i + 1
    ]
    ask turtle (number - 1 ) [set friend turtle (number - 1 )]
    ask turtle (number - 1 ) [set enemy turtle (number - 2)
     ]
    ask turtle 0 [set enemy turtle 0 ]
    ask turtle 0 [set friend turtle 1 ]


  ]
  reset-ticks
end 
; Copyright 2014 Uri Wilensky.
; See Info tab for full copyright and license.

There is only one version of this model, created 10 months ago by Bob McLeod.

Attached files

File Type Description Last updated
Heros and Cowards (emergence extension).png preview Preview for 'Heros and Cowards (emergence extension)' 10 months ago, by Bob McLeod Download

This model does not have any ancestors.

This model does not have any descendants.