# Simple Walk NetLogo Model

### Produced for the book series "Exercises for Artificial Intelligence";

### Author: W. J. Teahan; Publisher: Ventus Publishing Aps, Denmark.

powered by NetLogo

view/download model file: Simple-Walk.nlogo

## WHAT IS IT?

This model illustrates solutions to Exercises 4.2.1 and 4.2.2 for the book "Exercises for Artificial Intelligence - Agents and Environments".

## HOW TO USE IT

Press the setup-maze button first, then press the setup-turtle button. The walk button will execute the solution for Exercise 4.2.1. The shortest-walk-1, shortest-walk-2 and shortest-walk-3 buttons will execute solutions for Exercise 4.2.2.

## CREDITS AND REFERENCES

To refer to this model in publications, please use:

Teahan, W. J. (2010). Simple-Walk NetLogo model.

Exercisaes for Artificial Intelligence. Ventus Publishing Aps.

## PROCEDURES

; Simple Walk model. ; . ; ; Copyright 2010 William John Teahan. All Rights Reserved. ; to setup-maze ca ;; clear everything ask patches [ set pcolor white ] ;; make background full of white patches ask patches [ if (pxcor = 30) and (pycor >= -30) and (pycor <= 30) [ set pcolor black ] if (pxcor = -30) and (pycor >= -30) and (pycor <= 30) [ set pcolor black ] if (pycor = 30) and (pxcor >= -30) and (pxcor <= 30) [ set pcolor black ] if (pycor = -30) and (pxcor >= -30) and (pxcor <= 30) [ set pcolor black ] ] end to setup-turtle create-turtles 1 [ set color red set size 5 setxy 0 -28 set heading 0 pen-down set pen-size 2 ] end to walk ask turtles [ left 90 forward 28 right 90 forward 56 right 90 forward 56 right 90 ] end to shortest-walk-1 ; A solution if only right-angled turns are allowed. ask turtles [ forward 56 right 90 forward 28 right 90 ] end to shortest-walk-2 ; A solution with the shortest number of steps? ask turtles [ setxy 30 30 ; right some-angle ; (work out the value of Òsome-angleÓ for yourself) ] end to shortest-walk-3 ; Another solution, slightly more steps. ask turtles [ facexy 30 30 forward sqrt (56 * 56 + 28 * 28) ; (using square of the hypotenuse) right (180 - 26.6) ; (using angle calculation for a right angle triangle) ] end ; ; Copyright 2010 by William John Teahan. All rights reserved. ; ; Permission to use, modify or redistribute this model is hereby granted, ; provided that both of the following requirements are followed: ; a) this copyright notice is included. ; b) this model will not be redistributed for profit without permission ; from William John Teahan. ; Contact William John Teahan for appropriate licenses for redistribution for ; profit. ; ; To refer to this model in publications, please use: ; ; Teahan, W. J. (2010). Simple Walk NetLogo model. ; Artificial Intelligence. Ventus Publishing Aps ;