-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathshadows-knight1.kt
72 lines (60 loc) · 1.26 KB
/
shadows-knight1.kt
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.util.*
fun main(args : Array<String>) {
val input = Scanner(System.`in`)
val width = input.nextInt() // width of the building.
val height = input.nextInt() // height of the building.
val n = input.nextInt() // maximum number of turns before game over.
var x = input.nextInt()
var y = input.nextInt()
var minX = 0
var maxX = width -1
var minY = 0
var maxY = height - 1
// game loop
while (true) {
val bombDir = input.next() // the direction of the bombs from batman's current location
when (bombDir) {
"U" -> {
maxY = y - 1
minX = x
maxX = x
}
"UR" -> {
minX = x + 1
maxY = y - 1
}
"R" -> {
minX = x + 1
minY = y
maxY = y
}
"DR" -> {
minX = x + 1
minY = y + 1
}
"D" -> {
minY = y + 1
minX = x
maxX = x
}
"DL" -> {
maxX = x - 1
minY = y + 1
}
"L" -> {
maxX = x - 1
minY = y
maxY = y
}
// UL
else -> {
maxX = x - 1
maxY = y - 1
}
}
x = (minX + maxX) / 2
y = (minY + maxY) / 2
// the location of the next window Batman should jump to.
println("$x $y")
}
}