Skip to content
Snippets Groups Projects
Commit 14830ba1 authored by Jakob Kirsch's avatar Jakob Kirsch
Browse files

auto generated by makefile

parent 09ac2384
No related branches found
No related tags found
No related merge requests found
run: game.py .PHONY run:
python3 game.py python3 game.py
edit: .PHONY edit:
jupp game.py jupp game.py
push: .PHONY push:
git add . git add .
git commit -m "auto generated by makefile" git commit -m "auto generated by makefile"
git push git push
example:
python3 game.py testconf.json
\ No newline at end of file
...@@ -7,4 +7,6 @@ ...@@ -7,4 +7,6 @@
"DELAY" : 0, "DELAY" : 0,
"DEATH" : " ", "DEATH" : " ",
"LIFE" : "█" "LIFE" : "█"
} "PRINT" : 1,
\ No newline at end of file "CLEAR": 1
}
import random, time, os, sys, json import random, time, sys, json, os
if len(sys.argv) < 2: if len(sys.argv) < 2:
height = int(input("Height: ")) height = int(input("Height: "))
width = int(input("Width: ")) width = int(input("Width: "))
...@@ -11,6 +11,7 @@ if len(sys.argv) < 2: ...@@ -11,6 +11,7 @@ if len(sys.argv) < 2:
DEATH = " " DEATH = " "
DELAY = float(input("Delay: ")) DELAY = float(input("Delay: "))
PRINT = True PRINT = True
CLEAR = True
else: else:
with open(sys.argv[1], "r") as f: with open(sys.argv[1], "r") as f:
conf = json.load(f) conf = json.load(f)
...@@ -19,7 +20,11 @@ else: ...@@ -19,7 +20,11 @@ else:
MAP = [[DEATH for x in range(0, width)] for y in range(0, height)] MAP = [[DEATH for x in range(0, width)] for y in range(0, height)]
exec("def pattern(x, y):" + '\n\t'.join(code)) exec("def pattern(x, y):" + '\n\t'.join(code))
def draw(map): def draw(map):
os.system("clear") if CLEAR:
if os.name == "nt":
print("\n"*10000)
else:
os.system("clear")
print("/" + "-" * len(map[0]) + "\\") print("/" + "-" * len(map[0]) + "\\")
for row in map: for row in map:
print("|", end = '') print("|", end = '')
...@@ -28,25 +33,26 @@ def draw(map): ...@@ -28,25 +33,26 @@ def draw(map):
print("|") print("|")
print("\\" + "-" * len(map[0]) + "/") print("\\" + "-" * len(map[0]) + "/")
time.sleep(DELAY) time.sleep(DELAY)
def check(map, x, y): def check(map_orig, x, y):
target = map[y][x] global MAP
target = map_orig[y][x]
target_near = [] target_near = []
try: try:
try: target_near.append(map[y + 1][x + 1]) try: target_near.append(map_orig[y + 1][x + 1])
except: pass except: pass
try: target_near.append(map[y + 1][x]) try: target_near.append(map_orig[y + 1][x])
except: pass except: pass
try: target_near.append(map[y + 1][x - 1]) try: target_near.append(map_orig[y + 1][x - 1])
except: pass except: pass
try: target_near.append(map[y][x + 1]) try: target_near.append(map_orig[y][x + 1])
except: pass except: pass
try: target_near.append(map[y][x - 1]) try: target_near.append(map_orig[y][x - 1])
except: pass except: pass
try: target_near.append(map[y - 1][x + 1]) try: target_near.append(map_orig[y - 1][x + 1])
except: pass except: pass
try: target_near.append(map[y - 1][x]) try: target_near.append(map_orig[y - 1][x])
except: pass except: pass
try: target_near.append(map[y - 1][x - 1]) try: target_near.append(map_orig[y - 1][x - 1])
except: pass except: pass
except: pass except: pass
life = 0 life = 0
...@@ -54,9 +60,9 @@ def check(map, x, y): ...@@ -54,9 +60,9 @@ def check(map, x, y):
if target_item == LIFE: if target_item == LIFE:
life += 1 life += 1
if life > 3 or life < 2: if life > 3 or life < 2:
map[y][x] = DEATH MAP[y][x] = DEATH
elif life == 3: elif life == 3:
map[y][x] = LIFE MAP[y][x] = LIFE
else: else:
pass pass
def seed(map): def seed(map):
...@@ -77,10 +83,13 @@ while True: ...@@ -77,10 +83,13 @@ while True:
if PRINT: if PRINT:
draw(MAP) draw(MAP)
LMAP = [item.copy() for item in MAP.copy()] LMAP = [item.copy() for item in MAP.copy()]
GMAP = [item.copy() for item in MAP.copy()]
for y in range(0, len(MAP)): for y in range(0, len(MAP)):
for x in range(0, len(MAP[0])): for x in range(0, len(MAP[0])):
check(MAP, x, y) check(GMAP, x, y)
if check_frozen(MAP, LMAP): if check_frozen(MAP, LMAP):
break break
if not PRINT: if not PRINT:
draw(MAP) draw(MAP)
\ No newline at end of file #return [x, y] in [[1, 0], [2, 1], [0, 2], [1, 2], [2, 2]]
#return [x, y] in [[1, 1], [2, 1], [3, 1]]
{
"height" : 16,
"width" : 16,
"code" : [
"return random.randint(0, 1)"
],
"DELAY" : 0,
"DEATH" : " ",
"LIFE" : "█",
"PRINT" : 0
}
\ No newline at end of file
@
#
&
0
\ No newline at end of file
26
60
0
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment