Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Алгоритм Тезея для черепашки: http://www.kurilo.su/programmers/
var dirs = {'north':0,'east':1,'south':2,'west':3};
var names = ['north','east','south','west'];
var obs = {'north':north,'south':south,'west':west,'east':east};
result='east';
if (!direction) direction = 'east';
var left = function() {
return names[(dirs[direction] + 3) % 4];
};
var right = function() {
return names[(dirs[direction] + 1) % 4];
};
var back = function() {
return names[(dirs[direction] + 2) % 4];
};
var forward = function() { return direction };
if (obs[left()] == 1 && obs[forward()] != 1) { // путь свободен
result = forward();
} else {
if (obs[left()] != 1) { // потеряли стену
result = left();
} else { // впереди препятствие
if (obs[right()] != 1) { // справа есть куда ехать
result = right();
} else {
result = back();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.