{demonstrates random walk in 2 dimensions. Step 3} uses crt; const dot = '.'; type row_type = 1..15; grid = array[row_type, row_type] of char; procedure initialize( var board : grid ); var row, col : row_type; begin for row := 1 to 15 do for col := 1 to 15 do board[ row, col ] := dot end; procedure print( board : grid ); var row, col : row_type; begin clrscr; for row := 1 to 15 do begin for col := 1 to 15 do write( board[ row, col ] ); writeln end; end; procedure plot( increment : boolean; var z : row_type); begin if increment then z := z + 1 else z := z - 1; end; procedure generate( var board : grid; var c, r : row_type ); const T = true; F = false; var m : 0..3; begin m := random( 4 ); case m of 0 : plot( T, c); {c++} 1 : plot( F, c); {c--} 2 : plot( T, r); {r++} 3 : plot( F, r); {r--} end; if board[ r, c ] = '*' then board[ r, c ] := '^' else board[ r, c ] := '*' end; procedure start( var board : grid; var c, r : row_type ); begin c := 8; r := 8; board[ r, c ] := '*'; end; function continue : boolean; var ans : char; valid : boolean; begin repeat writeln('Do you want to continue? (Y/N)'); ans := upcase( readkey ); valid := ans in [ 'Y', 'N']; until valid; continue := ans = 'Y' end; var board : grid; c, r : row_type; begin initialize( board ); print( board ); randomize; start( board, c, r ); print( board ); while continue do begin generate( board, c, r ); print( board ) end end.