to search-for-food ;;check if you are on a food spot if food > 0 [ ;;if you're on food and the don't have food ;; pick up the food and turn 180 degrees if not hasFood? [sethasFood? true setshape termite-wood-shape rt 180 setfood food - 1 if food = 0 [ ask-patch-at xcor ycor [setpc black] ] ] ] ;;check if you are on the nest if isNest? [ ;;if you on nest and have food, drop it ;; and turn 180 degrees if hasFood? [sethasFood? false setshape termite-shape rt 180] ] ;;find the "best" path (most chemical) find-best-path ;;drop chemical on this spot drop-chem ;;move randomly wiggle ;;go forward fd 1 end to find-best-path ;;get three chemical levels and compare ;; turn in the direction of the highest setahead next-chemlevel lt 45 setleft next-chemlevel rt 90 setright next-chemlevel lt 45 if (right > ahead) and (right > left) [rt 45 stop] if (left > ahead) and (left > right) [lt 45] end to drop-chem ;;if you have food, drop more chemical than if you don't ifelse hasFood? [setchemlevel chemlevel + .1] [setchemlevel chemlevel + .2] if not (isNest? or food > 0) [scale-pc green chemlevel .1 10] end to wiggle ;;turn right and left randomly rt random 10 lt random 10 end to next-chemlevel ;;return the chemlevel variable at the spot ;; we would be at if we moved fd 1 output chemlevel-at dx dy end