AI Assignment 1
No preview image
Model was written in NetLogo 5.0.5
•
Viewed 472 times
•
Downloaded 34 times
•
Run 0 times
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 [turn-path-cost step-path-cost] turtles-own [direction] ;; 1 follows right-hand wall, ;; -1 follows left-hand wall breed [dogs dog] breed [houses house] breed [clinics clinic] ; Hamton Court Maze Demo ; ; Draws a schematic map of the Hampton Court Maze ; setup maze at (0,0) to setup-row [row colour segments] foreach segments [ if pycor = row * maze-height and (pxcor >= maze-width * (item 0 ?)) and (pxcor <= maze-width * (item 1 ?)) [set pcolor colour] ] end to setup-col [col colour segments] foreach segments [ if pxcor = col * maze-width and (pycor >= maze-height * (item 0 ?)) and (pycor <= maze-height * (item 1 ?)) [set pcolor colour] ] end to create-dog create-turtles 1 [ ; move the turtle slowly to the entrance setxy (maze-width / 2) (- maze-height * 7) set size 1 ;; bigger turtles are easier to see set pen-size 2 ;; thicker lines are easier to see set color green ;;set shape "dog" pen-down set turn-path-cost 0 set step-path-cost 0 set heading 0 ; head north repeat maze-height + 1 [forward 1 wait 0.2 set turn-path-cost turn-path-cost + 1] ifelse random 2 = 0 [ set heading 90 set direction 1 set step-path-cost step-path-cost + 1] ;; follow right hand wall [ set heading 270 set direction -1 set step-path-cost step-path-cost + 1] ;; follow left hand wall forward 2 set turn-path-cost turn-path-cost + 2 clear-output output-write turn-path-cost ] end to setup-hampton-maze ca;; clear everything ask patches [ if (pxcor >= min-pxcor and pxcor <= max-pxcor and pycor >= min-pycor and pycor <= max-pycor) [set pcolor white] ;; make background full of white patches setup-row 5 grey[[-9 10]] setup-row 4 grey[[-8 -5] [-3 -1] [0 3] [5 9]] setup-row 3 grey[[-7 -4] [-2 2] [4 8]] setup-row 2 grey[[-6 -1] [1 4] [5 7]] setup-row 1 grey[[-3 3] [8 9]] setup-row 0 grey[[-8 -7] [9 10]] setup-row -1 grey[[-9 -8]] setup-row -2 grey[[-8 -7] [-3 0] [1 3]] setup-row -3 grey[[-4 -1] [2 4] [6 8]] setup-row -4 grey[[-7 -1] [1 9]] setup-row -5 grey[[-8 10]] setup-row -6 grey[[-9 0] [1 10]] setup-col 10 grey[[-6 5]] setup-col 9 grey[[-4 -1] [1 4]] setup-col 8 grey[[-3 1] [2 3]] setup-col 7 grey[[-2 2]] setup-col 6 grey[[-4 1]] setup-col 5 grey[[-3 2]] setup-col 4 grey[[-3 2] [3 5]] setup-col 3 grey[[-2 1] [2 4]] setup-col 1 grey[[-4 -2]] setup-col 0 grey[[-5 -2] [1 3]] setup-col -1 grey[[-4 -3] [4 5]] setup-col -3 grey[[-2 1] [2 4]] setup-col -4 grey[[-3 2] [3 5]] setup-col -5 grey[[-4 1]] setup-col -6 grey[[-3 2]] setup-col -7 grey[[-4 -3] [-2 0] [1 3]] setup-col -8 grey[[-5 -2] [0 4]] setup-col -9 grey[[-6 5]] ] create-turtles 1 [ ; move the turtle slowly to the entrance setxy (maze-width / 2) (- maze-height * 7) set size 2 ;; bigger turtles are easier to see set pen-size 2 ;; thicker lines are easier to see set color green set shape "dog" pen-down set turn-path-cost 0 set step-path-cost 0 set heading 0 ; head north repeat maze-height + 1 [forward 1 wait 0.2 set turn-path-cost turn-path-cost + 1] ifelse random 2 = 0 [ set heading 90 set direction 1 set step-path-cost step-path-cost + 1] ;; follow right hand wall [ set heading 270 set direction -1 set step-path-cost step-path-cost + 1] ;; follow left hand wall forward 2 set turn-path-cost turn-path-cost + 2 clear-output output-write turn-path-cost ] end to create-house create-turtles 2 [ set color red set shape "house" set size 5 setxy 6 50 ] end to create-clinic create-clinics 1 [ set color blue set shape "clinic" set size 8 setxy -1 -1 ] end to go ask turtles [ walk ] end to walk ;; turtle procedure if count neighbors4 with [pcolor = grey] = 4 [ user-message "Trapped!" stop ] if ycor > ( - 2 * maze-height) and ycor <= maze-height and xcor >= 0 and xcor <= maze-width [ user-message "Made it to the centre of the maze!" stop ] ;; turn right if necessary if not wall? (90 * direction) 1 and wall? (135 * direction) (sqrt 2) [ rt 90 * direction set step-path-cost step-path-cost + 1] ;; wall straight ahead: turn left if necessary (sometimes more than once) while [wall? 0 1] [ lt 90 * direction set step-path-cost step-path-cost + 1] ;; move forward fd 1 set turn-path-cost turn-path-cost + 1 clear-output output-print (word "turn direction path cost :" turn-path-cost " ") output-print (word "step path cost :" step-path-cost " ") end to-report wall? [angle dist] ;; note that angle may be positive or negative. if angle is ;; positive, the turtle looks right. if angle is negative, ;; the turtle looks left. report grey = [pcolor] of patch-right-and-ahead angle dist end
There is only one version of this model, created over 10 years ago by Jind Lee.
Attached files
No files
This model does not have any ancestors.
This model does not have any descendants.