Created
June 5, 2021 14:35
-
-
Save jO-Osko/4a57256119409698b790cdb814d0d277 to your computer and use it in GitHub Desktop.
Mreža
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 random | |
def seed(): | |
random.seed(2021) | |
def prazna_mreza(w, h): | |
return [ | |
[0 for j in range(w)] for _ in range(h) | |
] | |
def cell(a): | |
if a == 0: | |
return "." | |
if a == 1: | |
return "#" | |
if a == 2: | |
return "X" | |
if a == 3: | |
return "0" | |
def print_mreza(m): | |
rr = "\n".join( | |
"".join([cell(x) for x in l]) for l in m | |
) | |
return rr | |
def random_mreza(m, p1, p2, p3): | |
seed() | |
for j in range(len(m)): | |
v = m[j] | |
for i in range(len(v)): | |
r = random.random() | |
n = 3 | |
if r < p1: | |
n = 0 | |
elif r < p2: | |
n = 1 | |
elif r < p3: | |
n = 2 | |
v[i] = n | |
return m | |
p1 = 0.7 | |
p2 = 0.8 | |
p3 = 0.9 | |
mreza = prazna_mreza(200, 150) | |
#print(print_mreza(mreza)) | |
random_mreza(mreza, p1, p2, p3) | |
# print(print_mreza(mreza)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment