Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "ostruct"
- STDOUT.sync = true # DO NOT REMOVE
- # Auto-generated code below aims at helping you parse
- # the standard input according to the problem statement.
- LEFT_BORDER = 0
- TOP_BORDER = 0
- BOTTOM_BORDER = 19
- RIGHT_BORDER = 29
- @obstacles = {}
- directions = ["LEFT", "UP", "RIGHT", "DOWN"]
- DIRECTIONS_OFFSETS = {
- "LEFT" => [-1, 0],
- "UP" => [0, -1],
- "RIGHT" => [1, 0],
- "DOWN" => [0, 1]
- }
- (LEFT_BORDER..RIGHT_BORDER).each do |x|
- @obstacles[[x, TOP_BORDER - 1]] = true
- @obstacles[[x, BOTTOM_BORDER + 1]] = true
- end
- (TOP_BORDER..BOTTOM_BORDER).each do |y|
- @obstacles[[LEFT_BORDER - 1, y]] = true
- @obstacles[[RIGHT_BORDER + 1, y]] = true
- end
- def blocked?(hero, direction)
- offset = DIRECTIONS_OFFSETS[direction]
- next_coordinate = [hero.x + offset[0], hero.y + offset[1]]
- @obstacles[next_coordinate]
- end
- current_direction = "LEFT"
- def debug(message)
- STDERR.puts(message.inspect)
- end
- # game loop
- loop do
- # n: total number of players (2 to 4).
- # p: your player number (0 to 3).
- n, p = gets.split(" ").collect {|x| x.to_i}
- players = []
- n.times do |index|
- # x0: starting X coordinate of lightcycle (or -1)
- # y0: starting Y coordinate of lightcycle (or -1)
- # x1: starting X coordinate of lightcycle (can be the same as X0 if you play before this player)
- # y1: starting Y coordinate of lightcycle (can be the same as Y0 if you play before this player)
- x0, y0, x1, y1 = gets.split(" ").collect {|x| x.to_i}
- players << OpenStruct.new(:x => x1, :y => y1)
- @obstacles[[x0, y0]] = true
- @obstacles[[x1, y1]] = true
- end
- hero = players[p]
- debug(hero)
- debug(@obstacles.keys.last(3))
- if blocked?(hero, current_direction)
- current_direction = directions.find{|direction|
- !blocked?(hero, direction)
- }
- end
- # Write an action using puts
- # To debug: STDERR.puts "Debug messages..."
- puts(current_direction)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement