' ' Langton's ant ' ' World is a global boolean array, 100x100 in size width%=100 height%=100 DIM world!(width%,height%) ARRAYFILL world!(),FALSE ' Time in world time%=0 ' Ant is represented by a global three-element array ' holding: x, y, direction [0=north,1=west,2=south,3=east] DIM ant%(3) ' @setup_ant @run_ant @display_world ' ' Displays the world to file "langton.out": . for false, # for true ' PROCEDURE display_world LOCAL i%,j% OPEN "o",#1,"langton.out" PRINT #1,"Time in world: ";time%;" ticks" FOR i%=0 TO width%-1 FOR j%=0 TO height%-1 IF world!(i%,j%) PRINT #1,"#"; ELSE PRINT #1,"."; ENDIF NEXT j% PRINT #1,"" NEXT i% CLOSE #1 RETURN ' ' Set up the ant to start at (50,50) facing north ' PROCEDURE setup_ant ant%(0)=50 ant%(1)=50 ant%(2)=0 RETURN ' ' check if ant position is within world's bounds ' FUNCTION ant_in_world RETURN ant%(0)>=0 AND ant%(0)=0 AND ant%(1)