Created
April 6, 2022 02:56
-
-
Save chrisplim/c2fb2b1db00122bd73f003d1c07915f1 to your computer and use it in GitHub Desktop.
the_fall_episode_1
This file contains hidden or 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
| import sys | |
| import math | |
| class Game: | |
| def __init__(self, width, height): | |
| self.room_type_grid = [[0]*width for _ in range(height)] | |
| self.prev_x = None | |
| self.prev_y = None | |
| def get_next_position(self, x, y): | |
| """ | |
| Based on the position, its room type, and a previous position we have stored, we can | |
| return the next position for Indy. | |
| """ | |
| current_room_type = self.room_type_grid[y][x] | |
| next_position = None | |
| if current_room_type in ['4', '10'] and self.prev_y is not None and self.prev_y < y: | |
| next_position = (x-1, y) | |
| elif current_room_type in ['5', '11'] and self.prev_y is not None and self.prev_y < y: | |
| next_position = (x+1, y) | |
| elif current_room_type in ['1', '3', '4', '5', '7', '8', '9', '12', '13']: | |
| next_position = (x, y+1) | |
| elif current_room_type in ['2', '6'] and self.prev_x is not None and self.prev_x > x: | |
| next_position = (x-1, y) | |
| elif current_room_type in ['2', '6'] and self.prev_x is not None and self.prev_x < x: | |
| next_position = (x+1, y) | |
| self.prev_x = x | |
| self.prev_y = y | |
| return next_position | |
| # Auto-generated code below aims at helping you parse | |
| # the standard input according to the problem statement. | |
| # w: number of columns. | |
| # h: number of rows. | |
| w, h = [int(i) for i in input().split()] | |
| game = Game(w, h) | |
| for i in range(h): | |
| line = input() # represents a line in the grid and contains W integers. Each integer represents one room of a given type. | |
| room_types_row = line.split(" ") | |
| for j in range(w): | |
| # Set the room type in our room_type_grid | |
| game.room_type_grid[i][j] = room_types_row[j] | |
| ex = int(input()) # the coordinate along the X axis of the exit (not useful for this first mission, but must be read). | |
| # game loop | |
| while True: | |
| inputs = input().split() | |
| xi = int(inputs[0]) | |
| yi = int(inputs[1]) | |
| pos = inputs[2] | |
| # Write an action using print | |
| # To debug: print("Debug messages...", file=sys.stderr, flush=True) | |
| next_position = game.get_next_position(xi, yi) | |
| if next_position: | |
| new_x, new_y = next_position | |
| print(f"{new_x} {new_y}") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment