RosettaCodeData/Task/Langtons-ant/Liberty-BASIC/langtons-ant-1.basic
2023-07-01 13:44:08 -04:00

55 lines
986 B
Text

dim arena(100,100)
black=0
white=not(black)
for i = 1 to 100
for j = 1 to 100
arena(i,j)=white
next
next
'north=1 east=2 south=3 west=4
nomainwin
graphicbox #1.g, 0, 0, 100, 100
open "Langton's Ant" for window as #1
#1 "trapclose Quit"
#1.g "down"
antX=50:antY=50
nsew=1 'ant initially points north
while (antX>0) and (antX<100) and (antY>0) and (antY<100)
if arena(antX,antY) then
nsew=nsew-1
if nsew<1 then nsew=4
else
nsew=nsew+1
if nsew>4 then nsew=1
end if
select case nsew
case 1: antY=antY-1
case 2: antX=antX+1
case 3: antY=antY+1
case 4: antX=antX-1
end select
arena(antX,antY)=not(arena(antX,antY))
#1.g "color ";GetColor$(antX,antY)
#1.g "set ";antX;" ";antY
wend
#1.g "flush"
wait
function GetColor$(x,y)
if arena(x,y) then
GetColor$="white"
else
GetColor$="black"
end if
end function
sub Quit handle$
close #handle$
end
end sub