Langton's ant: Difference between revisions
Content deleted Content added
Line 1,750:
const west = 2
const south = 3
const leftTurns = [ west, north, south, east ]
const rightTurns = [ east, south, north, west ]
func move(ant) {
ant
ant
}
func Array.step(ant) {
var ptCur = (x
var leftTurn = this[ptCur
ant.direction =
if leftTurn {
leftTurns[ant
} else {
rightTurns[ant
}
this[ptCur
move(ant)
ptCur = (x
ant
ptCur
ptCur
ptCur
ptCur
ant
}
func newAnt(width, height) {
(
position
origin
outOfBounds
isBlack
direction
width
height
)
}
func run() {
const w = 100
Line 1,796:
const blacks = Array.empty(w, () => Array.empty(h, false))
const ant = newAnt(w, h)
while !ant
blacks.step(ant)
}
var iRow = 0;
while iRow < w {
var iCol = 0;
Line 1,818:
}
}
run()</lang>
|