Created
November 20, 2022 12:13
-
-
Save turbod/fbedb08b1d9348fc4d5d181b5b6dad22 to your computer and use it in GitHub Desktop.
This file contains 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
STDOUT.sync = true # DO NOT REMOVE | |
w, h = gets.split(" ").collect { |x| x.to_i } | |
n = gets.to_i # maximum number of turns before game over. | |
x0, y0 = gets.split(" ").collect { |x| x.to_i } | |
x1 = x0 | |
y1 = y0 | |
max_x = w - 1 | |
min_x = 0 | |
max_y = h - 1 | |
min_y = 0 | |
loop do | |
bomb_dir = gets.chomp | |
case bomb_dir | |
when "U" | |
max_y = y1 if y1 < max_y | |
y1 = ((min_y + max_y) / 2.to_f).floor | |
when "UR" | |
min_x = x1 if x1 > min_x | |
max_y = y1 if y1 < max_y | |
x1 = (min_x + max_x) / 2.to_f | |
y1 = ((min_y + max_y) / 2.to_f).floor | |
when "R" | |
min_x = x1 if x1 > min_x | |
x1 = (min_x + max_x) / 2.to_f | |
when "DR" | |
min_x = x1 if x1 > min_x | |
min_y = y1 if y1 > min_y | |
# max_x = x1 if x1 > min_x | |
x1 = (min_x + max_x) / 2.to_f | |
y1 = (min_y + max_y) / 2.to_f | |
when "D" | |
min_y = y1 if y1 > min_y | |
y1 = (min_y + max_y) / 2.to_f | |
when "DL" | |
max_x = x1 if x1 < max_x | |
min_y = y1 if y1 > min_y | |
x1 = (min_x + max_x) / 2.to_f | |
y1 = (min_y + max_y) / 2.to_f | |
when "L" | |
min_x = x1 if x1 > min_x | |
y1 = (min_y + max_y) / 2.to_f | |
when "UL" | |
max_x = x1.floor if x1 < max_x | |
max_y = y1.floor if y1 < max_y | |
x1 = ((min_x + max_x) / 2.to_f).floor | |
y1 = (min_y + max_y) / 2.to_f | |
end | |
x1 = x1.ceil | |
y1 = y1.ceil | |
# the location of the next window Batman should jump to. | |
puts "#{x1} #{y1}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment