Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
if (direction == 0)
{
if (east == 0)
result = 'east';
else if (west == 0)
result = 'west';
else if (north == 0)
result = 'north';
else if (south== 0)
result = 'south';
}
if (direction == 'north')
{
if (west == 0)
result = 'west';
else if (north == 0)
result = 'north';
else if (east == 0)
result = 'east';
else if (south == 0)
result = 'south';
}
if (direction == 'east')
{
if (north == 0)
result = 'north';
else if (east == 0)
result = 'east';
else if (south == 0)
result = 'south';
else if (west== 0)
result = 'west';
}
if (direction == 'south')
{
if (east == 0)
result = 'east';
else if (south == 0)
result = 'south';
else if (west == 0)
result = 'west';
else if (north== 0)
result = 'north';
}
if (direction == 'west')
{
if (south == 0)
result = 'south';
else if (west== 0)
result = 'west';
else if (north == 0)
result = 'north';
else if (east== 0)
result = 'east';
}
if (west == 3)
result = 'west';
else if (south== 3)
result = 'south';
else if (north== 3)
result = 'north';
else if (east== 3)
result = 'east';
var args = {
"north": north,
"east": east,
"south": south,
"west": west
}
var movement = new Array (
"north",
"east",
"south",
"west"
);
for(a in movement) {
if(direction == movement[a]) {
// Вот здесь можно значительно красивее, да. Но для наглядности оставил как есть.
var tmpA = movement.slice(0, a-1);
var tmpB = movement.slice(a-1, movement.length);
movement = tmpB.concat(tmpA);
break;
}
}
for(a in movement) {
if(args[movement[a]] != 1) {
result = movement[a];
break;
}
}

var moves = ['west', 'north', 'east', 'south', 'west', 'north', 'east'];
var start = 1;
if (direction)
{
for (var i=1; i<5; i++)
{
if (direction == moves[i])
{
start = i-1;
break;
}
}
}
for (var i = start; i < start+4; i++)
{
if (eval(moves[i]) == 0 || eval(moves[i]) == 3)
{
result = moves[i];
break;
}
}
var moves = ['west', 'north', 'east', 'south', 'west', 'north', 'east'];
var pos=(direction)? moves.indexOf(direction, 1)-1: 1
while(eval(result=moves[pos++]) == 1);
var cardinal_directions = ['north','east','south','west','jaw'];
var env = [ north, east, south, west, 0];
var i;
for (i = 0; i < 4; ++i) {
if (env[i] == 3)
break;
}
if (i == 4) {
for (i = 0; i < 5; ++i) {
if (cardinal_directions[i] == direction)
break;
}
i = i % 5;
var right = (i + 1) % 4;
if (env[right] == 0) {
if (!goo) {
i = 4;
} else {
i = right;
}
}
while (i < 4 && env[i] == 1) {
i = (i + 3) % 4;
}
}
result = cardinal_directions[i];
Как я ищу программиста