Skip to content

Instantly share code, notes, and snippets.

@deadkff01
Created October 16, 2016 06:56
Show Gist options
  • Select an option

  • Save deadkff01/f552dbf6a9b11ed70802fa50d7b931a7 to your computer and use it in GitHub Desktop.

Select an option

Save deadkff01/f552dbf6a9b11ed70802fa50d7b931a7 to your computer and use it in GitHub Desktop.
The Last Crusade - Episode 1 Solution
var grid = [];
var inputs = readline().split(' ');
var W = parseInt(inputs[0]); // number of columns.
var H = parseInt(inputs[1]); // number of rows.
for (var i = 0; i < H; i++) {
var LINE = readline(); // represents a line in the grid and contains W integers. Each integer represents one room of a given type.
grid[i] = LINE.split(' ');
}
var EX = parseInt(readline()); // the coordinate along the X axis of the exit (not useful for this first mission, but must be read).
// game loop
while (true) {
var inputs = readline().split(' ');
var XI = parseInt(inputs[0]);
var YI = parseInt(inputs[1]);
var POS = inputs[2];
switch(parseInt(grid[YI][XI])) {
case 1:
case 3:
case 7:
case 8:
case 9:
case 12:
case 13:
YI++;
break;
case 2:
case 6:
XI = (POS == 'LEFT') ? XI+1 : XI-1;
break;
case 4:
if(POS == 'TOP')
XI--;
else
YI++
break;
case 5:
if(POS == 'TOP')
XI++;
else
YI++;
break;
case 10:
XI--;
break;
case 11:
XI++;
break;
default:
print('Error');
}
// One line containing the X Y coordinates of the room in which you believe Indy will be on the next turn.
print(XI+' '+YI);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment