Anonymous user
Langton's ant: Difference between revisions
m
→{{header|REXX}}: added whitespace.
m (→{{header|REXX}}: added whitespace.) |
|||
Line 6,721:
parse arg dir char seed . /*obtain optional arguments from the CL*/
if datatype(seed, 'W') then call random ,,seed /*Integer? Then use it as a RANDOM SEED*/
if dir=='' | dir=="," then dir= random(1, 4)
if char=='' | char=="," then char= '#' /*binary colors: 0≡white, 1≡black. */
parse value scrSize() with sd sw . /*obtain the terminal's depth and width*/
sd= sd -6;
xHome= 1000000;
$.= 1
minX= x;
@.=
do #=1 until (maxX-minY>sw)|(maxY-minY>sd) /*is the path out─of─bounds for screen?*/
black= @.x.y;
if black then dir= dir - 1
else dir= dir + 1
dir= $.dir
select /*ant walks the direction it's facing. */
when dir==1 then y= y + 1 /*is ant walking north? Then go up. */
Line 6,741:
when dir==4 then x= x - 1 /* " " " west? " " left. */
end /*select*/ /*the DIRection is always normalized.*/
minX= min(minX, x);
minY= min(minY, y);
end /*steps*/ /* [↑] ant walks hither and thither. */
/*finished walking, it's
say center(" Langton's ant walked " # ' steps ', sw, "─")
@.xHome.yHome= '█'
@.x.y= '∙'
/* [↓] show Langton's ant's trail. */
do y=maxY to minY by -1; _= /*display a single row of cells. */
do x=minX to maxX; _=_ || @.x.y /*build a cell row for the display. */
end /*x*/ /* [↓] strip trailing blanks from line*/
_= strip( translate(_, char, 10), 'T')
if _\=='' then say _ /*display line (strip trailing blanks).*/
end /*y*/ /*stick a fork in it, we're all done. */</lang>
|