Langton's ant: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 4,267: | Line 4,267: | ||
socket.sleep(naptime) |
socket.sleep(naptime) |
||
until false |
until false |
||
</lang> |
|||
=={{header|M2000 Interpreter}}== |
|||
<lang M2000 Interpreter> |
|||
Module Ant { |
|||
Form 120,102 |
|||
N=100 |
|||
Enum CellColor {black=0,white=#FFFFFF} |
|||
Enum Direction{North=90, West=180, South=270, East=0} |
|||
Function Rotate(cd as Direction, clockwise=true) { |
|||
cd=(cd+if(clockwise->270,90)) mod 360 |
|||
=cd ' return a Direction Enum type |
|||
} |
|||
dim rect(1 to N, 1 to N)=white |
|||
cx=N div 2 |
|||
cy=N div 2 |
|||
cd=North |
|||
rect(cx,cy)=black |
|||
endmove=False |
|||
while not endmove |
|||
movecell() |
|||
end while |
|||
Disp() |
|||
sub movecell() |
|||
select case rect(cx,cy) |
|||
case black |
|||
cd=Rotate(cd, false) : rect(cx, cy)=white |
|||
case white |
|||
cd=Rotate(cd) : rect(cx, cy)=black |
|||
end select |
|||
select case cd |
|||
case North |
|||
cy-- |
|||
case West |
|||
cx-- |
|||
case South |
|||
cy++ |
|||
case East |
|||
cx++ |
|||
end select |
|||
endmove= cx<1 or cx>N or cy<1 or cy>N |
|||
end sub |
|||
sub disp() |
|||
Local Doc$, i, j |
|||
Document Doc$ |
|||
for i=1 to N:for j=1 to N |
|||
Doc$=if$(rect(i,j)=White->"_","#") |
|||
next |
|||
Doc$={ |
|||
} |
|||
next |
|||
cls |
|||
Print #-2,Doc$ |
|||
clipboard Doc$ |
|||
end sub |
|||
} |
|||
Ant |
|||
</lang> |
</lang> |
||
{{out}} |
|||
<pre style="height:30ex;overflow:scroll"> |
|||
____________________________________________________________________________________________________ |
|||
______________________________________##__############__##__________________________________________ |
|||
_____________________________________##__#__________####__#_________________________________________ |
|||
____________________________________#_##____________##___###________________________________________ |
|||
____________________________________#____#__#_________#__#_#________________________________________ |
|||
__________________________________#_______###_________#_#_##__##____________________________________ |
|||
__________________________________###__##_##_____#_____#___#__#_###_________________________________ |
|||
______________________________##__##_#__#_#___##_####_##__###__#_#__________________________________ |
|||
_____________________________###___###_____#_#_###__##_#__##_###_#__________________________________ |
|||
____________________________#_#_#_###___#__####__#_#_#####___#_____#________________________________ |
|||
____________________________#___#_###_#_######_##_##__####_#___##_###_______________________________ |
|||
_____________________________##_###_#####___#_##_##_##_#_#_##_#_###_#_______________________________ |
|||
___________________________##_#____####__#_#___#___###_##_#___#_#___________________________________ |
|||
__________________________##_____#_##_____##__#___##_##_________#__#________________________________ |
|||
_________________________#_##__##_###___#_____##__#__###_##_#_#___###_______________________________ |
|||
_________________________#___####_##__#____#__###___##_##___##__###__#______________________________ |
|||
__________________________#_____#__###_##_#__##_####_#_#__#_#___#___###_____________________________ |
|||
________________________##__#__#_##_###______#__###_#__#____##_#__###__#____________________________ |
|||
_______________________#___##_####__####_#####__##__##_#_##_#_____#___###___________________________ |
|||
______________________#___#____#_#_#___##______##_#_#_###_#__#_#_#__###__#__________________________ |
|||
______________________#______#___####_####_______##___#_##__###_##__#___###_________________________ |
|||
_______________________#____#____#__####__#_###########__##___#__#_#__###__#________________________ |
|||
_______________________##__#____##__#__#########__##__####_#______##__#___###_______________________ |
|||
______________________#_####__##_#__#___###_###_##_##___##_#__##___#_#__###__#______________________ |
|||
______________________#___##___###_###____#_#_##_#_##_######_#__#___##__#___###_____________________ |
|||
_______________________#___##____#_##__#_#_____#####_#_#####_____#___#_#__###__#____________________ |
|||
_______________________#__#__#_##__#__#___#_#__##_#####_##_#_____#____##__#___###___________________ |
|||
_______________________##___##########___##_#####__#_####___#____#_____#_#__###__#__________________ |
|||
___________________________##_####_##___#__####___#__#___##___##_#______##__#___###_________________ |
|||
_________________________#_#__#__#__#_#____#___#_##___##__#_#####________#_#__###__#________________ |
|||
_________________________##__##__#__##_#_#_##_##____#_#_#_##__##__________##__#___###_______________ |
|||
_________________________#_####__##_#_#_########_#____#__#_________________#_#__###__#______________ |
|||
_________________________#_##__#__#___##_##_______#___#__#__________________##__#___###_____________ |
|||
_________________________####_##___##__##__#______#__#__#____________________#_#__###__#____________ |
|||
________________________###_#___#____##__##_______#___##______________________##__#___###___________ |
|||
________________________####_###_####____####__##_#____________________________#_#__###__#__________ |
|||
_______________________#__#_#_##_#__##____####__##______________________________##__#___###_________ |
|||
______________________#####_##_###_##____##____##________________________________#_#__###__#________ |
|||
______________________####__#_##_#________________________________________________##__#___###_______ |
|||
______________________##_##_##_____________________________________________________#_#__###__#______ |
|||
____________________________##______________________________________________________##__#___###_____ |
|||
____________________#_####__##_#_____________________________________________________#_#__###__#____ |
|||
____________________###__###_#__#_____________________________________________________##__#___###___ |
|||
_____________________#__#__#_##_#______________________________________________________#_#__###__#__ |
|||
______________________##______##________________________________________________________##__#___###_ |
|||
_____________________________##__________________________________________________________#_#__###__# |
|||
__________________________________________________________________________________________##__#_###_ |
|||
___________________________________________________________________________________________#_#_#_#_# |
|||
____________________________________________________________________________________________##_####_ |
|||
_____________________________________________________________________________________________#_##_#_ |
|||
______________________________________________________________________________________________####__ |
|||
_______________________________________________________________________________________________##___ |
|||
____________________________________________________________________________________________________ |
|||
</pre > |
|||
=={{header|MATLAB}} / {{header|Octave}}== |
=={{header|MATLAB}} / {{header|Octave}}== |
||
<lang MATLAB>function u = langton_ant(n) |
<lang MATLAB>function u = langton_ant(n) |