# Partners Example

### 1 collaborator

Uri Wilensky (Author)

### Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 308 times • Downloaded 20 times • Run 2 times

Click to Run Model

```turtles-own
[
partner   ;;  the turtle that is our partner, or "nobody" if we don't have one
]

;;  This procedure will setup 150 turtles, by randomly placing them around the world.

to setup
clear-all
create-turtles 150
[
;;  turtles get random coordinates, and they are
;;  light gray (to show they don't have partners yet).
setxy random-xcor random-ycor
set color gray + 2
set partner nobody
]
reset-ticks
end

;; have each turtle move until they find a partner at which point they turn red

to find-partners
let singles turtles with [partner = nobody]
if not any? singles [ stop ]

;;  In this example, only turtles that haven't found a partner can move around.
[
;;  Randomly move about the world
lt random 40
rt random 40
fd 1
]

;;  Now that all unpartnered turtles have moved, ask the unpartnered turtles to check if they
;;  are on a patch with a turtle that also don't have a partner.
[
if (partner = nobody) and (any? other turtles-here with [partner = nobody])
[
;;  There could be more than one partner to choose from, so we use one-of
;;  to randomly choose one of the turtle without a partner
set partner one-of other turtles-here with [partner = nobody]

;;  We graphically show that we have a partner by turning red.
set color red

;; Ask our partner to partner with ourselves.
set partner myself
;;  Color my partner red too
set color red
]
]
]

;;  As a check on the correctness of the code, let's make sure that
;;  the partner assignments are consistent.
if any? turtles with [partner != nobody and [partner] of partner != self]
[
ask one-of turtles with [[partner] of partner != self]
[
user-message (word "Oops! Partner mismatch: " self
" is not partnered to " myself)
]
stop
]
tick
end

; Public Domain:
; To the extent possible under law, Uri Wilensky has waived all
; copyright and related or neighboring rights to this model.
```

There are 10 versions of this model.

Uri Wilensky over 9 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 10 years ago Updated version tag Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 12 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 12 years ago Model from NetLogo distribution Download this version