Anonymous user
Langton's ant: Difference between revisions
→{{header|Rust}}: Updated to the Rust 1.3.0
(→{{header|Rust}}: Updated to the Rust 1.3.0) |
|||
Line 4,916:
=={{header|Rust}}==
<lang Rust>struct Ant {
x: usize,
struct Ant {▼
▲ dir: Direction
}
#[derive(Clone,Copy)]
enum Direction {▼
fn move(&mut self, vec: &mut Vec<Vec<u8>>) {▼
}▼
use Direction::*;
let pointer = vec.get_mut(self.y).get_mut(self.x);▼
//change direction▼
match *pointer {▼
0 => self.dir = self.dir.right(),▼
_ => fail!("Unexpected colour in grid")▼
//flip colour▼
//if it's 1 it's black▼
//if it's 0 it's white▼
*pointer ^= 1; ▼
//move direction▼
match self.dir {▼
North => self.y -= 1,▼
South => self.y += 1,▼
East => self.x += 1,▼
}
▲}
West => self.x -= 1,
}
}
▲enum Direction {
▲ North,
▲ East,
▲ South,
▲ West
}
impl Direction {
}
}
}
}
fn main(){
}
.map(|&x| if x == 0 { " " } else { "#" })
}
}</lang>▼
▲</lang>
=={{header|Scala}}==
|