Created
November 24, 2022 01:06
-
-
Save bayasdev/9a385c57704847bb7bf35e3a4ac11b9a to your computer and use it in GitHub Desktop.
Codingame Solution JavaScript: Shadows of the Knight - Episode 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Auto-generated code below aims at helping you parse | |
* the standard input according to the problem statement. | |
**/ | |
var inputs = readline().split(' '); | |
const W = parseInt(inputs[0]); // width of the building. | |
const H = parseInt(inputs[1]); // height of the building. | |
const N = parseInt(readline()); // maximum number of turns before game over. | |
var inputs = readline().split(' '); | |
let X0 = parseInt(inputs[0]); | |
let Y0 = parseInt(inputs[1]); | |
let X1 = 0; | |
let Y1 = 0; | |
let X2 = W - 1; | |
let Y2 = H - 1; | |
// game loop | |
while (true) { | |
const bombDir = readline(); // the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL) | |
// Write an action using console.log() | |
// To debug: console.error('Debug messages...');else | |
if(bombDir.includes('U')){ | |
Y2 = Y0 - 1; | |
} else if(bombDir.includes('D')){ | |
Y1 = Y0 + 1; | |
} | |
if(bombDir.includes('L')){ | |
X2 = X0 - 1; | |
} else if(bombDir.includes('R')){ | |
X1 = X0 + 1; | |
} | |
X0 = X1 + (X2 - X1) / 2; | |
Y0 = Y1 + (Y2 - Y1) / 2; | |
// the location of the next window Batman should jump to. | |
console.log(`${Math.round(X0)} ${Math.round(Y0)}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment