def to_grid_pos(x, y, maze_size):
  """Converts DMLab world coordinates to maze coordinates.

  Inspired from LuaMazeGeneration::FromWorldPos, with the big difference that
  FromWorldPos uses (LUA) 1-based indexing.

  Args:
    x: X coordinate in DMLab world.
    y: Y coordinate in DMLab world.
    maze_size: Size of the DMLab maze in number of cell.

  Returns:
    Pair of floats: (row, col). We return floats because some uses of that
    function need the exact position in maze coordinates. Other uses are free
    to round the returned values.
  """
  grid_width = 100
  row = maze_size - y / grid_width - 0.5
  col = x / grid_width - 0.5
  return row, col