Skip to content

Instantly share code, notes, and snippets.

@LeReverandNox
Created April 7, 2018 23:38
Show Gist options
  • Select an option

  • Save LeReverandNox/b9c32c13161f7d822aad125477cab8c5 to your computer and use it in GitHub Desktop.

Select an option

Save LeReverandNox/b9c32c13161f7d822aad125477cab8c5 to your computer and use it in GitHub Desktop.
import sys
import math
from collections import namedtuple
# Auto-generated code below aims at helping you parse
# the standard input according to the problem statement.
# w: width of the building.
# h: height of the building.
w, h = [int(i) for i in input().split()]
n = int(input()) # maximum number of turns before game over.
x0, y0 = [int(i) for i in input().split()]
max_from_top_edge = h
max_from_left_edge = w
min_from_top_edge = 0
min_from_left_edge = 0
Point = namedtuple('Point', ['y', 'x'])
moves = {
'U': Point(-1, 0),
'UR': Point(-1, 1),
'R': Point(0, 1),
'DR': Point(1, 1),
'D': Point(1, 0),
'DL': Point(1, -1),
'L': Point(0, -1),
'UL': Point(-1, -1)
}
def calculate_half_distance(start, direction):
global max_from_top_edge
global max_from_left_edge
global min_from_top_edge
global min_from_left_edge
rounding = True
flooring = False
print('max_from_top_edge = {}, min_from_top_edge {}'.format(max_from_top_edge, min_from_top_edge), file=sys.stderr)
print('max_from_left_edge = {}, min_from_left_edge {}'.format(max_from_left_edge, min_from_left_edge), file=sys.stderr)
if direction == 'D':
# OK
min_from_top_edge = start.y
distance = max_from_top_edge - start.y
# flooring = True
elif direction == 'U':
# OK
max_from_top_edge = start.y
distance = start.y - min_from_top_edge
elif direction == 'L':
# OK
max_from_left_edge = start.x
distance = start.x - min_from_left_edge
elif direction == 'R':
# OK
min_from_left_edge = start.x
distance = max_from_left_edge - start.x
# flooring = True
elif direction == 'DR':
# LOGICALY GOOD
min_from_top_edge = start.y
min_from_left_edge = start.x
dist_y = max_from_top_edge - start.y
dist_x = max_from_left_edge - start.x
distance = min(dist_y, dist_x)
# flooring = True
elif direction == 'UL':
# SEEMS GOOD
max_from_top_edge = start.y
max_from_left_edge = start.x
dist_y = start.y - min_from_top_edge
dist_x = start.x - min_from_left_edge
distance = min(dist_y, dist_x)
elif direction == 'DL':
# SEEMS OK TOO
min_from_top_edge = start.y
max_from_left_edge = start.x
dist_y = max_from_top_edge - start.y
dist_x = start.x - min_from_left_edge
distance = min(dist_y, dist_x)
elif direction == 'UR':
# SEEMS OK TOOOO
max_from_top_edge = start.y
min_from_left_edge = start.x
dist_y = start.y - min_from_top_edge
dist_x = max_from_left_edge - start.x
distance = min(dist_y, dist_x)
print('dist {}, dist/2 {}, dist/2 round {}, dist/2 floor {}'.format(distance, distance / 2, math.ceil(distance /2), math.floor(distance/2)), file=sys.stderr)
if rounding:
return int(math.ceil(distance / 2)) if math.ceil(distance / 2) >= 1 else 1
elif flooring:
return int(math.floor(distance / 2)) if distance / 2 >= 1 else 1
else:
return int(distance / 2) if distance / 2 >= 1 else 1
# game loop
while True:
bomb_dir = input() # the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL)
print('Batman est à {},{}'.format(y0, x0), file=sys.stderr)
print('Il a droit a {} sauts'.format(n), file=sys.stderr)
print('La strucure fait {} de haut, {} de large'.format(h, w), file=sys.stderr)
print('La bombe est dans cette direction : {}'.format(bomb_dir), file=sys.stderr)
batman_pos = Point(y0, x0)
coef = calculate_half_distance(batman_pos, bomb_dir)
next_pos = Point(batman_pos.y + moves[bomb_dir].y * coef, batman_pos.x + moves[bomb_dir].x * coef)
y0, x0 = next_pos.y, next_pos.x
print('On va se deplacer ici : {},{}'.format(next_pos.y, next_pos.x), file=sys.stderr)
# the location of the next window Batman should jump to.
print("{} {}".format(next_pos.x, next_pos.y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment