90 lines
3.3 KiB
Python
90 lines
3.3 KiB
Python
from math import log10,sqrt
|
|
from tkinter import *
|
|
|
|
master = Tk()
|
|
master.resizable(0, 0)
|
|
|
|
canvas = Canvas(master, width=320, height=240)
|
|
canvas.pack()
|
|
|
|
def color(r, g, b):
|
|
return '#%02x%02x%02x' % (r, g, b)
|
|
|
|
def fill_rect(x, y, w, h, color):
|
|
y += 18
|
|
canvas.create_rectangle(x, y, x + w, y + h, fill=color, outline='')
|
|
|
|
def draw_string(text, x, y, fg=color(0,0,0), bg=None):
|
|
y += 18
|
|
t = canvas.create_text(x, y, anchor=NW, text=text, fill=fg)
|
|
if bg is not None:
|
|
r = canvas.create_rectangle(canvas.bbox(t), fill=bg, outline='')
|
|
canvas.tag_lower(r, t)
|
|
|
|
def clear():
|
|
canvas.delete('all')
|
|
canvas.create_rectangle(0, 18, 320, 240, fill=color(255, 255, 255), outline='')
|
|
canvas.create_rectangle(0, 0, 320, 18, fill=color(255, 183, 52), outline='')
|
|
|
|
def init():
|
|
global atmu,n,j,s,ma,mb,mc,w,fp,fm
|
|
atmu,n,j,s,w,fp,fm=[],9,0,0,5,0,0
|
|
ma,mb,mc=[[0]*n for k in range(n)],[[0]*n for k in range(n)],[[0]*n for k in range(n)]
|
|
|
|
def dr():
|
|
global s,j,w
|
|
sw=320
|
|
d,h=min(sw//n,221//n),(color(0,0,0),color(255,255,255))
|
|
b=sw-1-n*d
|
|
clear()
|
|
for i in range(0,n*d+1,d):
|
|
fill_rect(b,i,n*d,1,h[0])
|
|
fill_rect(b+i,0,1,n*d,h[0])
|
|
for y in range(0,n):
|
|
for x in range(0,n):
|
|
t=255-(255*abs(ma[y][x])//w)
|
|
fill_rect(b+x*d+1,y*d+1,d-1,d-1,ma[y][x]<0 and color(t,t,255) or ma[y][x]>0 and color(255,t,t) or h[1])
|
|
draw_string(" ATLEMU ",1,1,color(255,255,0),color(127,127,127))
|
|
draw_string("Muen\ndo(-1,c,l)",0,19,color(0,0,255),h[1])
|
|
draw_string("Atlante\ndo(1,c,l)",0,53,color(255,0,0),h[1])
|
|
draw_string("Passer\ndo(0)",0,87,color(255,0,255),h[1])
|
|
draw_string("Recommencer\ninit()",0,121,color(0,0,0),h[1])
|
|
draw_string("An: "+str(j)+"\nScore:\n"+str(s)[:10],0,n*d-49)
|
|
|
|
def do(*ar):
|
|
global j,gp,gm,fp,fm,s
|
|
j,k,v,(sc,sl)=j+1,ar[0],(len(ar)%2) or ar[len(ar)-1],(len(ar)>=3) and (ar[1],ar[2]) or (0,0)
|
|
k,gp,gm=k and k//abs(k),fp,fm
|
|
for y in range(n):mb[y]=mc[y].copy()
|
|
for y in range(n):
|
|
for x in range(n):
|
|
o,ma[y][x]=ma[y][x],ma[y][x]+w*(ma[y][x]==0 and x==sc and y==sl)*((k>0)-(k<0))+(ma[y][x]<=0 and (x-sc or y-sl or k==0) and mb[y][x]//10==3)*((ma[y][x]==0)*w-ma[y][x]*(not(not(ma[y][x]))))-(ma[y][x]>=0 and (x-sc or y-sl or k==0) and mb[y][x]-10*(mb[y][x]//10)==3)*((ma[y][x]==0)*w+ma[y][x]*(not(not(ma[y][x]))))
|
|
if o and ma[y][x]==o:
|
|
ls=(-1,w>abs(ma[y][x]))
|
|
ma[y][x]=ma[y][x]+(ma[y][x]>0)*ls[mb[y][x]//10==3 or mb[y][x]//10==4]-(ma[y][x]<0)*ls[mb[y][x]-10*(mb[y][x]//10)==3 or mb[y][x]-10*(mb[y][x]//10)==2]
|
|
if ma[y][x]-o:
|
|
fp,fm=fp+(ma[y][x]>0 and not(o))-(o>0 and not(ma[y][x])),fm+(ma[y][x]<0 and not(o))-(o<0 and not(ma[y][x]))
|
|
if not(o) and ma[y][x] or o and not(ma[y][x]):
|
|
for dl in range(-1,2):
|
|
for dc in range(-1,2):
|
|
if dl or dc:mc[y+dl+(dl<0 and y==0)*n-(dl>0 and y==n-1)*n][x+dc+(dc<0 and x==0)*n-(dc>0 and x==n-1)*n]+=(ma[y][x]<0)-(o<0 and 0==ma[y][x])+10*((ma[y][x]>0)-(o>0 and 0==ma[y][x]))
|
|
if max(fp,gp)*max(fm,gm):s=s/(1+abs(k)*log10(sqrt(j)))+fp*fm*min(fp,gp)*min(fm,gm)/max(fp,gp)/max(fm,gm)
|
|
atmu.append((sc*k+k,sl*k+k))
|
|
if v:
|
|
dr()
|
|
print("Bon score ? Envoie la liste\n'atmu' a info@tiplanet.org")
|
|
return s
|
|
|
|
def st(l,v=True):
|
|
init()
|
|
for p in l:s=do((p[0]>0)-(p[0]<0),abs(p[0])-1,abs(p[1])-1,v)
|
|
dr()
|
|
return s
|
|
|
|
init()
|
|
|
|
dr()
|
|
|
|
if __name__== "__main__":
|
|
master.mainloop()
|