Simple PathFinder

No preview image

1 collaborator

Moi Yassine Chaouche (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.1 • Viewed 298 times • Downloaded 24 times • Run 0 times
Download the 'Simple PathFinder' 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

globals [vision-distance debug_patch destination]
breed [firefighters]
breed [pees]
patches-own [peanuts fire-intensity]

to find-fire
  let patch-in-fire nobody  
  if any? patches in-radius vision-distance with [pcolor = red]
  [set patch-in-fire one-of patches in-radius vision-distance with [pcolor = red]]
end 

to set-patch-on-fire
  let _patch selected-patch
  if _patch != nobody [
    ask _patch [
      set pcolor (hsb 4 255 250)
      set fire-intensity 25
    ]    
  ]
end 

to-report selected-patch
  if mouse-down? [report patch mouse-xcor mouse-ycor]
  report nobody
end 

to make-road
  colorize-patch white
end 

to colorize-patch [_color]
  let _patch nobody
  if mouse-down?  
  [ 
    set _patch patch mouse-xcor mouse-ycor
    if [pcolor] of _patch = black [ask _patch [set pcolor _color]]
  ]  
end 

to create-ff
  create-firefighters 1 [init-ff]
end 

to init-ff
  set shape "van top"
  set size 1
  set color red
  set heading 0
  goto-road
end 

to goto-road
  let road-patch one-of patches with [pcolor = white]
  setxy [pxcor] of road-patch [pycor] of road-patch
end 

to-report is-road? [_patch]
  report [pcolor] of _patch = white
end 

to turn
  ifelse random 100 > 95 [left 90] [right 90]
end 

to drive
  let  _patch min-one-of (neighbors4 with [pcolor = white]) [peanuts]
  drop-peanut
  move-to _patch
end 

to drive-time
  every 0.4 [ask firefighters [drive]]
end 

to drop-peanut
  ask patch-here [
    set peanuts (peanuts + 1)
    ifelse peanuts = 1
    [sprout-pees 1 [set shape "circle" set color 5 set size 0.5]]
    [ask pees-here [set color (hsb (peanuts * 10) 255 255)]]
  ]
end 

to clear
  ask patches [set peanuts 0]
  clear-turtles
  if destination != nobody
  [
    ask destination [set pcolor white]
    set destination nobody
  ]
end 

to go
  every 0.4 [
    if destination-set?
    [
      ask firefighters [advance-to-destination destination]
    ]
  ]
end 

to set-off
  if fire-intensity > 0
  [
    set fire-intensity (fire-intensity - 1)
    set pcolor hsb 4 255 (fire-intensity * 10)
  ]
end 

to-report destination-set?
  report destination != nobody
end 

to select-destination
  let target selected-patch
  if target != nobody and [pcolor] of target = white [ 
    set destination target 
    ask destination [set pcolor yellow]
    ]
end 

to advance-to-destination [_destination]
  if _destination != nobody
  [
    ifelse patch-here != _destination
    [
      ifelse member? _destination neighbors4 [face _destination fd 1]
      [
        let next_patch min-one-of (neighbors4 with [pcolor = white] with-min [peanuts]) [distance _destination]
        drop-peanut
        face next_patch
        fd 1
      ]
    ]
    [
      remove-destination
      remove-path
    ]
  ]
end 

to remove-destination
  ask destination [
    set pcolor white
    set peanuts 0
  ]
  set destination nobody
end 

to remove-path
  ask patches with [peanuts > 0] 
  [
    set pcolor white
    ask pees-here [die]
    set peanuts 0
  ]
end 


  
  

There is only one version of this model, created about 9 years ago by Yassine Chaouche.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.