Dark room

Dark room preview image

1 collaborator

Default-person Dajun Yue (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.4 • Viewed 244 times • Downloaded 17 times • Run 0 times
Download the 'Dark room' modelDownload this modelEmbed this model

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


Comments and Questions

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

Click to Run Model

breed [students student]

students-own 
[
  user-id 
  step-size
  dark-region
  visible-region
]

to startup
  hubnet-reset
end 

to setup
  clear-patches
  clear-drawing
  clear-output
  
  color-patches
  
  ask turtles
  [
    set step-size 1
    update-vision    ;; update vision
    hubnet-send user-id "step-size" step-size
  ]
  reset-ticks
end 

to go
  listen-clients
  every 0.1
  [
    tick
  ]
end 

;;
;;  HubNet Procedure
;;

to listen-clients
  while [hubnet-message-waiting?]
  [
    hubnet-fetch-message
    ifelse hubnet-enter-message?
    [ create-new-student ]
    [
      ifelse hubnet-exit-message?
      [ remove-student ]
      [
        ask students with [user-id = hubnet-message-source] 
        [
          execute-command hubnet-message-tag 
          update-vision
        ]
      ]
    ]
  ]
end 

to create-new-student
  create-students 1
  [
    set user-id hubnet-message-source
    set label user-id
    set step-size 1
    update-vision
  ;  pen-down
    send-info-to-clients
  ]  
end 

to remove-student
  ask students with [user-id = hubnet-message-source]
  [die]
end 

to execute-command [command]
  if command = "step-size"
  [
    set step-size hubnet-message
    stop
  ]
    if command = "up"
  [ execute-move 0 stop ]
  if command = "down"
  [ execute-move 180 stop ]
  if command = "right"
  [ execute-move 90 stop ]
  if command = "left"
  [ execute-move 270 stop ]
end 

to send-info-to-clients
  hubnet-send user-id "location" (word "(" pxcor "," pycor ")")
end 

to execute-move [new-heading]
  set heading new-heading
  fd step-size
  send-info-to-clients
end 

to color-patches
  ask n-of 10 patches [set pcolor white]
end 

to update-vision
  set visible-region patches in-radius 5
  set dark-region patches with [not member? self [visible-region] of myself]
end 

to mask
  ask turtles [
    hubnet-clear-override user-id visible-region "pcolor" 
    hubnet-send-override user-id dark-region "pcolor" [black]
  ]
end 

There is only one version of this model, created almost 11 years ago by Dajun Yue.

Attached files

File Type Description Last updated
Dark room.png preview Preview for 'Dark room' almost 11 years ago, by Dajun Yue Download

This model does not have any ancestors.

This model does not have any descendants.