forked from DTC-Formation/dart-basics-rakparfait90
-
Notifications
You must be signed in to change notification settings - Fork 0
/
power_of_Thor.dart
41 lines (36 loc) · 1.01 KB
/
power_of_Thor.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import 'dart:io';
// import 'dart:math';
String readLineSync() {
String? s = stdin.readLineSync();
return s == null ? '' : s;
}
void main() {
List inputs;
inputs = stdin.readLineSync()?.split(' ') ?? List.filled(4, '');
int lightX = int.parse(inputs[0]); // the X position of the light of power
int lightY = int.parse(inputs[1]); // the Y position of the light of power
int initialTX = int.parse(inputs[2]); // Thor's starting X position
int initialTY = int.parse(inputs[3]); // Thor's starting Y position
int thorX = initialTX;
int thorY = initialTY;
// game loop
while (true) {
// int remainingTurns = int.parse(readLineSync());
var directionX = "", directionY = "";
if (thorX > lightX) {
directionX = "W";
thorX--;
} else if (thorX < lightX) {
directionX = "E";
thorX++;
}
if (thorY > lightY) {
directionY = "N";
thorY--;
} else if (thorY < lightY) {
directionY = "S";
thorY++;
}
print(directionY + directionX);
}
}