extensions [ table ] ;============================================================ ; MAZE DATA ;============================================================ patches-own [ patch.maze.type ;; what type of patch: open / wall / shadow ] ;============================================================ ; GLOBALS ;============================================================ globals [ maze.wall-color ;; color of wall patches maze.shadow-color ;; color of patches next to walls (blocked patches) maze.wide-walls? ;; using wide walls ie: blocked patches next to walls maze.fragments# ;; number of maze fragments maze.has-sides? ;; is the maze bounded by walls? maze.args ;; the argument table ] to maze.setup-globals set maze.wall-color grey ;; maze walls set maze.shadow-color 12 ;; the patches next to wall patches if also blocked off set maze.wide-walls? false ;; the patches next to wall patches are also blocked off set maze.has-sides? true ;; turns on side walls by default end ;============================================================ ; SETTING UP ;============================================================ ; ; arguments... ; "random-seed" ; "use-wide-walls?" ; "shadow-color" ; "wall-color" ; "number-of-fragments" to maze.setup-maze [$arglist] ;;___initialisation_____________________________ maze.setup-globals ask patches [ set patch.maze.type "open" ] ;; set up maze variables set maze.args table:from-list $arglist if (table:has-key? maze.args "random-seed") [ random-seed (table:get maze.args "random-seed") ] maze.setvar "maze.wide-walls?" "use-wide-walls?" maze.setvar "maze.wall-color" "wall-color" maze.setvar "maze.shadow-color" "shadow-color" maze.setvar "maze.fragments#" "number-of-fragments" maze.setvar "maze.has-sides?" "maze.has-sides?" ;;____draw side walls___________________________ if (maze.has-sides?) [ ask patches with [pxcor = min-pxcor] [(set pcolor maze.wall-color) (set patch.maze.type "wall")] ask patches with [pycor = min-pycor] [(set pcolor maze.wall-color) (set patch.maze.type "wall")] ask patches with [pxcor = max-pxcor] [(set pcolor maze.wall-color) (set patch.maze.type "wall")] ask patches with [pycor = max-pycor] [(set pcolor maze.wall-color) (set patch.maze.type "wall")] ] ;;___draw maze fragments________________________ let $step ifelse-value (maze.wide-walls?) [4] [2] ;; size of each fragment let $width (max-pxcor - min-pxcor) ;; width of the world let $height (max-pycor - min-pycor) ;; height of the world let $x-segments ($width / $step) ;; no. horizontal segments assuming step size let $y-segments ($height / $step) ;; no. horizontal segments assuming step size (let $pdx 0) (let $pdy 0) ;; patch dx,dy controlling segment orientation repeat maze.fragments# [ let $x min-pxcor + (random $x-segments) * $step ;; x,y position of new segment let $y min-pycor + (random $y-segments) * $step ifelse ((random 2) = 0) ;; horisontal or vertical [ (set $pdx 1) (set $pdy 0) ] [ (set $pdx 0) (set $pdy 1) ] repeat ($step + 1) [ ask patch $x $y [(set pcolor maze.wall-color) (set patch.maze.type "wall")] set $x ($x + $pdx) set $y ($y + $pdy) ] ] ;;___label blocked patches_______________________________ if (maze.wide-walls?) [ ask patches with [patch.maze.type = "open"] [ if any? neighbors with [patch.maze.type = "wall"] [ set patch.maze.type "shadow" set pcolor maze.shadow-color ] ] ] end ;============================================================ ; UTILS ;============================================================ to maze.setvar [$var $key] ;; a convenience procedure... ;; dynamically assign a global if (table:has-key? maze.args $key) [ run (word "set " $var " table:get maze.args \""$key"\"") ] end to assert [$cond $str] ;; this is the best compromise approach I can find ;; to throwing an error. Any suggestions welcome. if (not $cond) [ print $str run "ERROR:_check_output_for_details" ] end to maze.redraw-patches ;; redraw patches ;; leaves responsibility to clear patches to caller ask patches [ ifelse (patch.maze.type = "wall") [ set pcolor maze.wall-color ] [ if (patch.maze.type = "shadow") [ set pcolor maze.shadow-color ] ] ] end ; ;Copyright 2013. Simon Lynch. All rights reserved. ; ;Permission to use, modify or redistribute this model is hereby granted, provided that both of the following requirements are followed: ; ; 1 this copyright notice is included. ; 2 this model will not be used for profit without permission from Simon Lynch. ; Contact Simon Lynch for appropriate licenses for commercial use. ; ;To reference this work in publications, please use the model name, Simon Lynch (2013), www.agent-domain.org ; ;For more information contact borismolecule@gmail.com ;