Large diffs are not rendered by default.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

@@ -12,7 +12,7 @@ def main():
matrix = read_matrix(filepath)
# matrix = read_matrix("input2.txt")
make_image(matrix, era=0)
for era in range(1, 5):
for era in range(1, 11):
make_rain(matrix, const.AMOUNT_OF_RAIN)
make_water_drainage(matrix, era)
print_matrix(matrix)
@@ -22,22 +22,23 @@ def main():

if __name__ == "__main__":
import cProfile, pstats, StringIO
print "Output: " + const.DIRECTORY_NAME

pr = cProfile.Profile()
pr.enable()

# ... do something ...
logpath = os.path.join(const.DIRECTORY_NAME, "logfile.log")
sys.stdout = Logger(logpath)
print "Output: " + const.DIRECTORY_NAME

main()
print "Output: " + const.DIRECTORY_NAME

pr.disable()
s = StringIO.StringIO()
sortby = 'time'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats()
print s.getvalue()
print "Output: " + const.DIRECTORY_NAME

# vovk.v.d@gmail.com
@@ -48,30 +48,35 @@ def print_matrix_diff(matrix1, matrix2):


def init_matrix_to_file(filepath, size):
def make_ellipsoid(matrix, center_x, center_y, a, b):
def make_ellipsoid(matrix, center_x, center_y, a, b, min_height):
a, b = float(a), float(b)
rows, cols = matrix.shape
for i in range(rows):
x = abs(i - center_x)
for j in range(cols):
y = abs(j - center_y)
if (x / a) ** 2 + (y / b) ** 2 <= 1:
# matrix[i, j] += (x + y) * 5
matrix[i, j] *= (x / a) ** 2 + (y / b) ** 2
# matrix[i, j] *= min(((x / a) ** 2 + (y / b) ** 2) + min_height,
# const.DEFAULT_TERRAIN_LEVEL)
coefficient = (x / a) ** 2 + (y / b) ** 2
matrix[i, j] = min(coefficient * matrix[i, j] + min_height,
const.DEFAULT_TERRAIN_LEVEL)
return matrix

matrix = np.matrix(np.ones((size, size), int) * const.DEFAULT_TERRAIN_LEVEL)
matrix = make_ellipsoid(matrix=matrix,
center_x=0,
center_y=0,
a=5,
b=7)
center_x=20,
center_y=36,
a=25,
b=40,
min_height=20)

matrix = make_ellipsoid(matrix=matrix,
center_x=size,
center_y=size,
a=8,
b=6)
center_x=50,
center_y=36,
a=25,
b=30,
min_height=5)

# save height matrix to file
with open(filepath, "w") as f:
@@ -7,14 +7,13 @@ def make_rain(matrix, water_amount):


def make_water_drainage(matrix, era):
smt_changed = True
iterations_count = 0
smt_changed = True # track whether water drainage occured for at least one cell in the @matrix
iterations_count = 0 # number of iterations, used only for logging
while smt_changed:
smt_changed = False
iterations_count += 1
print "Calculating {era} era, iteration: {iteration}...".format(
era=era, iteration=iterations_count)
for i, row in enumerate(matrix):
for j, cell in enumerate(row):
print "Calculating {} era, iteration: {}...".format(era, iterations_count)
for row in matrix:
for cell in row:
water_drained = cell.drain_water(matrix)
smt_changed = smt_changed or water_drained
smt_changed = smt_changed or water_drained # track whether drainage occured