from platform import platform import sys from tkinter import mainloop import turtle as t import random import pickle import time ## Global Variablen clear = "\n" * 100 print(clear) def logo(): print(" ___ _ ") print(" / __\___ _ ____ ____ _ _ _( )__ ") print(" / / / _ \| '_ \ \ /\ / / _` | | | |/ __| ") print("/ /__| (_) | | | \ V V / (_| | |_| |\__ \ ") print("\____/\___/|_| |_|\_/\_/ \__,_|\__, ||___/ ") print(" |___/ ") print(" ___ __ __ _ __ ") print(" / _ \__ _ _ __ ___ ___ ___ / _| / /(_)/ _| ___ ") print(" / /_\/ _` | '_ ` _ \ / _ \ / _ \| |_ / / | | |_ / _ \ ") print("/ /_\\\\ (_| | | | | | | __/ | (_) | _| / /__| | _| __/") print("\____/\__,_|_| |_| |_|\___| \___/|_| \____/_|_| \___|") print(" ") logo() if len(sys.argv)<3: print("Bitte sende beim Start der Anwendung 2 Argumente mit.\n Grid size als erstes Argument.\n Länge der Würfel in px als zweites Argument.") exit() grid=sys.argv[1] length_of_quader=sys.argv[2] size=int(length_of_quader)*int(grid) start_calc=(int(length_of_quader)*int(grid))/2 new_startposi=-abs(start_calc),(start_calc) new_startposit=-abs(start_calc),(start_calc) g_grid=int(grid)/2 flist=[] update_list=[] print(" Grid: "+grid +"\n Quadrat Länge: "+ length_of_quader + "\n Size: "+ str(size)+ "\n Start Calc: "+ str(start_calc)) ## test print(" Start Position: "+str(new_startposi)+"\n") def help(): print("Press C for 1 random block Press Y to save the game") print("Press S for 1 Generation interval Press X to load the savestate") print("Press D for 20 Generation interval Press V to reload the board") print("Press F for 50 Generation interval Press Q to to quit the game and close the window") def loadgame(): with open('savefile.dat', 'rb') as f: gamestate, lengthsave, gridsave = pickle.load(f) x=0 y=0 global ts, new_startposi for x in ts: for y in x: y.clear() grid=gridsave ts = [] # Baustein t2d= [] # 2d matrix nr= [] i=0 j=0 while j 3: kill(ts[asd][dsa]) if asdf == 3: belebe(ts[asd][dsa]) update_list=[] update_list=[] t.update() def death_or_alive(x,y): if ts[x][y].fillcolor() == "black": return True else: ts[x][y].fillcolor() == "white" return False def quadrat(this): i=0 #this.fillcolor("white") r = random.randint(1,5) if r==0: this.fillcolor("black") else: this.fillcolor("white") this.begin_fill() while i < 4: this.fd(int(length_of_quader)) this.rt(90) i=i+1 this.end_fill() this.hideturtle() def quadrat2(this,lengthsave):# Used 4 loadsavegame i=0 #this.fillcolor("white") this.fillcolor("white") this.begin_fill() while i < 4: this.fd(lengthsave) this.rt(90) i=i+1 this.end_fill() this.hideturtle() def colored(this): if this.fillcolor() == "white": i=0 this.fillcolor("black") this.begin_fill() while i < 4: this.fd(int(length_of_quader)) this.rt(90) i=i+1 this.end_fill() this.hideturtle() t.update() elif this.fillcolor() == "black": i=0 this.fillcolor("white") this.begin_fill() while i < 4: this.fd(int(length_of_quader)) this.rt(90) i=i+1 this.end_fill() this.hideturtle() t.update() def randoblack(): global ts x = random.randint(0,int(grid)) y = random.randint(0,int(grid)) if x>0: x-=1 if y>0: y-=1 resu=ts[x][y] colored(resu) def startpos(this): global startposit, new_startposi this.up() # this.goto(startposit) this.goto(new_startposi) this.down() # startposit=startposit[0]+int(length_of_quader),startposit[1] new_startposi=new_startposi[0]+int(length_of_quader),new_startposi[1] def get_feld(x,y): minus=size/2 feld1=x+minus feld2=y+minus resu=round(feld1,int(length_of_quader)) resu2=round(feld2,int(length_of_quader)) resu=feld1/int(length_of_quader) resu2=feld2/int(length_of_quader) resu=round(resu,int(length_of_quader)),round(resu2,int(length_of_quader)) return int(resu[0]),int(resu[1]) def mouse_clicked(x,y): global ts if -abs(start_calc)> x or x > (start_calc): print("auserhalb des Brettes") elif -abs(start_calc)> y or y > (start_calc): print("auserhalb des Brettes") else: feld_cord=get_feld(x,y) n1=feld_cord[0] n2=feld_cord[1] theOne=ts[n2][n1] colored(theOne) def generation20(): start_time = time.time() i=0 while i<21: i+=1 game_interval() print("durchlauf: "+str(i)) clear = "\n" * 100 print(clear) logo() help() print("Die 20 Generationen brauchten,", time.time() - start_time, "Sekunden zum durchlaufen") def generation50(): start_time = time.time() i=0 while i<51: i+=1 game_interval() print("durchlauf: "+str(i)) clear = "\n" * 100 print(clear) logo() help() print("Die 50 Generationen brauchten,", time.time() - start_time, "Sekunden zum durchlaufen") def main(): global grid, startposit, startpos, length_of_quader,new_startposi,start_calc,ts,new_startposit grid=int(grid) ts = [] # Baustein t2d= [] # 2d matrix nr= [] i=0 j=0 while j