150 likes | 337 Views
Algorithms and Flow Charts. Algorithms. A procedure or formula for solving a problem. Drawing a square in Netlogo. Representation of Algorithms. Desirable Features Language independent Unambiguous Easy to understand A standard---understood and known by many Solution Flow charts.
E N D
Algorithms A procedure or formula for solving a problem. Drawing a square in Netlogo
Representation of Algorithms Desirable Features Language independent Unambiguous Easy to understand A standard---understood and known by many Solution Flow charts
Drawing a square As a flow chart:
Using variables More general?
Repetition in Netlogo On the previous slide while loop repeat ;; repeats forever pd loop [ fd 0.5 rt 1 ] ;; the turtle draws a circle pd repeat 36 [ fd 1 rt 10 ]
Decision if statement if else statement [ ifelse (xcor > 0) [ set color blue ] [ set color red ] ] [ if (xcor > 0) [ set color blue ] ]
Symbol Summary These seven symbols are used the most:
The Bug Game • Implemented in Netlogo; here is the file • Objective: pick up all the food and return home in the fewest moves
The Bug Game Write the procedure go using the following instructions (each instruction is actually a procedure call): turn-right turn-left move-forward dist (dist must be specified) pickup-food see-food (sets variables) see-start (sets variables) at-food (sets variables) at-start (sets variables)