Example #1
0
def check_dragon(image: Image, x: int, y: int):
    for i in range(len(DRAGON)):
        for j in range(len(DRAGON[i])):
            if not image.in_bounds(x + i, y + j):
                return False
            if DRAGON[i][j] == "#" and image.get(x+i, y+j) != "#":
                return False
    return True
Example #2
0
 def post(self):
   logging.info("hi")
   upload_files = self.get_uploads('file')  # 'file' is file upload field in the form
   blob_info = upload_files[0]
   userID = users.get_current_user().user_id()
   
   image = Image(parent = ndb.Key('image', userID), blobKey=blob_info.key(), urlString = get_serving_url(blob_info.key(), size=None, crop=False, secure_url=None))
   image.put()
   self.redirect('/my-dashboard')
Example #3
0
def fill_dragons(image: Image, indices):
    image = image.copy()
    for x, y in indices:
        for i in range(len(DRAGON)):
            for j in range(len(DRAGON[i])):
                if not image.in_bounds(x + i, y + j):
                    print(f"error: x={x}, y={y}, i: {i}, j: {j}")
                    raise Exception("Unexpected out of bounds while filling")
                if DRAGON[i][j] == "#":
                    if image.get(x + i, y + j) not in ("#", "O"):
                        print(f"error: x={x}, y={y}, i: {i}, j: {j}")
                        raise Exception("Unexpected mismatch while filling")
                    image.put(x+i, y+j, "O")
    return image
Example #4
0
  def get(self):
    template_values = {}
    
    current_user = users.get_current_user()
    if current_user == None:					# returns to homepage if no user logged in
      template_values['loginURL'] = users.create_login_url(dest_url='my-dashboard')
      template = jinja_environment.get_template('home.html')
      self.response.out.write(template.render(template_values))
    else:
      name = users.get_current_user()
      logout = users.create_logout_url('/')
      userID = users.get_current_user().user_id()

      notes = Note.query(ancestor=ndb.Key('note', userID)).fetch()
      images = Image.query(ancestor=ndb.Key('image', userID)).fetch()
      
      # allURLs = []
      # for image in images:
      #     url = get_serving_url(image.blobKey, size=None, crop=False, secure_url=None)
      #     allURLs.append(url)
            
      template_values = {
       'notes': notes,
       'name' : name, 
       'current_user': current_user,
       'logout' : logout,
       'images' : images
      }
      
      template = jinja_environment.get_template('my-dashboard.html')
      self.response.out.write(template.render(template_values))
Example #5
0
def find_dragon(image: Image):
    indices = locate_dragons(image)
    for i in range(4):
        if len(indices) != 0:
            print(f"Breaking because indices = {indices}")
            break
        print(f"Rotating {i+1} times")
        image.rotate()
        indices = locate_dragons(image)

    if len(indices) == 0:
        print(f"Flipping the image")
        image.flip()
        indices = locate_dragons(image)
        for i in range(4):
            if len(indices) != 0:
                print(f"Breaking because indices = {indices}")
                break
            print(f"Rotating again {i + 1} times")
            image.rotate()
            indices = locate_dragons(image)

    filled_image = fill_dragons(image, indices)
    print(image.pretty())

    return calculate_roughness(filled_image)
Example #6
0
def main():
    tile_db = parse("input.txt")
    grid = assemble_grid(tile_db)
    print(grid.pretty())

    for tile in tile_db.tiles():
        tile.shed()

    image = Image.from_grid(grid)
    print(image.pretty())
    print("DRAGON_COUNT:", find_dragon(image))