Compare commits
No commits in common. "c5e48658cacef03372c2b6a0d37adc45a5284627" and "6367f27bf856c30b215ed6a6b8db10088785bf7d" have entirely different histories.
c5e48658ca
...
6367f27bf8
2 changed files with 9 additions and 55 deletions
31
a.py
31
a.py
|
@ -1,31 +0,0 @@
|
||||||
def finde_nachbarn(matrix, element):
|
|
||||||
x, y = element
|
|
||||||
nachbarn = []
|
|
||||||
|
|
||||||
for i in range(-1, 2):
|
|
||||||
for j in range(-1, 2):
|
|
||||||
nachbar_x = x + i
|
|
||||||
nachbar_y = y + j
|
|
||||||
# Clipping für den Rand der Matrix anwenden
|
|
||||||
nachbar_x = max(0, min(nachbar_x, len(matrix) - 1))
|
|
||||||
nachbar_y = max(0, min(nachbar_y, len(matrix[0]) - 1))
|
|
||||||
if (i != 0 or j != 0): # Dies schließt das aktuelle Element aus
|
|
||||||
nachbarn.append([nachbar_x, nachbar_y])
|
|
||||||
|
|
||||||
return nachbarn
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Beispiel Verwendung:
|
|
||||||
matrix = [
|
|
||||||
[1, 2, 3, 4, 5],
|
|
||||||
[6, 7, 8, 9, 10],
|
|
||||||
[11, 12, 13, 14, 15],
|
|
||||||
[16, 17, 18, 19, 20],
|
|
||||||
[21, 22, 23, 24, 25]
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
element = [0, 0] # Die Position 2,2 als Liste angegeben
|
|
||||||
nachbarn = finde_nachbarn(matrix, element)
|
|
||||||
print(nachbarn)
|
|
33
main.py
33
main.py
|
@ -36,21 +36,6 @@ def draw_feld(feld, color_key, block_size):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def finde_nachbarn(matrix, x, y):
|
|
||||||
feldx, feldy = len(feld[0]), len(feld)
|
|
||||||
|
|
||||||
over = (y - 1) % feldy , x % feldx
|
|
||||||
overr = (y - 1) % feldy , (x + 1) % feldx
|
|
||||||
overl = (y - 1) % feldy , (x - 1) % feldx
|
|
||||||
|
|
||||||
r = y , (x + 1) % feldx
|
|
||||||
l = y , (x - 1) % feldx
|
|
||||||
|
|
||||||
bellow = (y + 1) % feldy , x % feldx
|
|
||||||
bellowr = (y + 1) % feldy , (x + 1) % feldx
|
|
||||||
bellowl = (y + 1) % feldy , (x - 1) % feldx
|
|
||||||
return [overl,over, overr, r, l, bellowl, bellow, bellowr]
|
|
||||||
|
|
||||||
def verarbeite_feld(feld):
|
def verarbeite_feld(feld):
|
||||||
feldx, feldy = len(feld[0]), len(feld) # bekomme feld größe
|
feldx, feldy = len(feld[0]), len(feld) # bekomme feld größe
|
||||||
feld2 = copy.deepcopy(feld) # mache neue kopie
|
feld2 = copy.deepcopy(feld) # mache neue kopie
|
||||||
|
@ -59,25 +44,25 @@ def verarbeite_feld(feld):
|
||||||
poschar = feld[y][x]
|
poschar = feld[y][x]
|
||||||
if poschar == "a": # fals aktuelles checkendes element = "a"
|
if poschar == "a": # fals aktuelles checkendes element = "a"
|
||||||
# bekomme alle benötigten nachtbaren
|
# bekomme alle benötigten nachtbaren
|
||||||
nachtbaren = finde_nachbarn(feld, x ,y)
|
bellow = feld[(y + 1) % feldy][x]
|
||||||
bellow = feld[nachtbaren[6][0]][nachtbaren[6][1]]
|
bellowr = feld2[(y + 1) % feldy][(x + 1) % feldx]
|
||||||
bellowr = feld[nachtbaren[7][0]][nachtbaren[7][1]]
|
bellowl = feld2[(y + 1) % feldy][(x - 1) % feldx]
|
||||||
bellowl = feld[nachtbaren[5][0]][nachtbaren[5][1]]
|
#r = feld2[(y ) % feldy][(x + 1) % feldx]
|
||||||
|
#l = feld2[(y ) % feldy][(x - 1) % feldx]
|
||||||
direction = random.choice([-1, 1]) # Zufällige Auswahl der Richtung
|
direction = random.choice([-1, 1]) # Zufällige Auswahl der Richtung
|
||||||
if bellow == " " and not bellow == "#": # checke unten
|
if bellow == " " and not bellow == "#": # checke unten
|
||||||
feld2[y][x] = feld[(y + 1) % feldy][x]
|
feld2[y][x] = feld[(y + 1) % feldy][x]
|
||||||
feld2[(y + 1) % feldy][x] = feld[y][x]
|
feld2[(y + 1) % feldy][x] = feld[y][x]
|
||||||
|
|
||||||
elif bellowr == " " and not bellowr == "#" and direction == 1: # checke unten rechts fals richtung nach rechts
|
elif bellowr == " " and not bellowr == "#" and not r == "#" and direction == 1: # checke unten rechts fals richtung nach rechts
|
||||||
feld2[y][x] = feld[(y + 1) % feldy][(x + direction) % feldx] # tausche in kopie aktuelle position mit "a"
|
feld2[y][x] = feld[(y + 1) % feldy][(x + direction) % feldx] # tausche in kopie aktuelle position mit "a"
|
||||||
feld2[(y + 1) % feldy][(x + direction) % feldx] = feld[y][x] # tausche in kopie neue position mit bevorigen element
|
feld2[(y + 1) % feldy][(x + 1) % feldx] = feld[y][x] # tausche in kopie neue position mit bevorigen element
|
||||||
|
|
||||||
elif bellowl == " " and not bellowl == "#" and direction == -1: # checke unten links fals richtung nach links
|
elif bellowl == " " and not bellowl == "#" and not l == "#" and direction == -1: # checke unten links fals richtung nach links
|
||||||
feld2[y][x] = feld[(y + 1) % feldy][(x + direction) % feldx]
|
feld2[y][x] = feld[(y + 1) % feldy][(x + direction) % feldx]
|
||||||
feld2[(y + 1) % feldy][(x + direction) % feldx] = feld[y][x]
|
feld2[(y + 1) % feldy][(x + -1) % feldx] = feld[y][x]
|
||||||
return feld2 # gib kopie zurück
|
return feld2 # gib kopie zurück
|
||||||
|
|
||||||
## Funktion zum Verarbeiten des Feldes
|
|
||||||
|
|
||||||
def make_feld(size, mode):
|
def make_feld(size, mode):
|
||||||
x = screensize[0] // size
|
x = screensize[0] // size
|
||||||
|
|
Loading…
Reference in a new issue