pieces_echecs.py

Created by caucaucybu

Created on March 07, 2023

5.11 KB

Script complétant le script echecs.py.


from kandinsky import fill_rect as draw,draw_string as txt,get_pixel as get
grey=(165,166,165)
blanc=(255,255,255)
noir=(0,0,0)
plt=((222,97,24),(255,207,82))
def xn(xa):return 60+xa*25
def yn(ya):return 20+ya*25
def roin(x,y,c=noir):
  x=int(xn(x));y=int(yn(y))
  draw(x+21,y+3,3,19,c)
  draw(x+6,y+7,3,11,c)
  draw(x+2,y+11,19,3,c)
  for i in range(4):
    draw(x+11+3*i,y+2+i,3,3,c)
    draw(x+11+3*i,y+20-i,3,3,c)
  draw(x+12,y+5,2,15,c)
  draw(x+14,y+8,1,9,c)
  for i in (2,17):draw(x+11,y+i,2,6,c)
def roib(x,y,c=blanc):
  x=int(xn(x));y=int(yn(y))
  draw(x+1,y+3,3,19,c)
  draw(x+16,y+7,3,11,c)
  draw(x+4,y+11,19,3,c)
  for i in range(4):
    draw(x+11-3*i,y+2+i,3,3,c)
    draw(x+11-3*i,y+20-i,3,3,c)
  draw(x+11,y+5,2,15,c)
  draw(x+10,y+8,1,9,c)
  for i in (2,17):draw(x+12,y+i,2,6,c)
def reinen(x,y,c=noir):
  x=int(xn(x));y=int(yn(y))
  draw(x+21,y+3,3,19,c)
  for i in range(5):
    draw(x+8+3*i,y+1+i,3,3,c)
    draw(x+8+3*i,y+21-i,3,3,c)
  draw(x+7,y+11,14,3,c)
  draw(x+9,y+2,2,21,c)
  draw(x+11,y+8,1,9,c)
  for i in (2,17):draw(x+8,y+i,2,6,c)
def reineb(x,y,c=blanc):
  x=int(xn(x));y=int(yn(y))
  draw(x+1,y+3,3,19,c)
  for i in range(5):
    draw(x+14-3*i,y+1+i,3,3,c)
    draw(x+14-3*i,y+21-i,3,3,c)
  draw(x+4,y+11,14,3,c)
  draw(x+14,y+2,2,21,c)
  draw(x+13,y+8,1,9,c)
  for i in (2,17):draw(x+15,y+i,2,6,c)
def tourn(x,y,c=noir):
  x=int(xn(x));y=int(yn(y))
  draw(x+21,y+5,3,15,c)
  draw(x+10,y+8,11,9,c)
  draw(x+7,y+6,3,13,c)
  for i in (6,11,16):draw(x+4,y+i,3,3,c)
def tourb(x,y,c=blanc):
  x=int(xn(x));y=int(yn(y))
  draw(x+1,y+5,3,15,c)
  draw(x+4,y+8,11,9,c)
  draw(x+15,y+6,3,13,c)
  for i in (6,11,16):draw(x+18,y+i,3,3,c)
def cavaliern(x,y,c=noir):
  x=int(xn(x));y=int(yn(y))
  draw(x+21,y+6,3,14,c)
  draw(x+20,y+8,3,10,c)
  draw(x+16,y+9,4,8,c)
  draw(x+5,y+10,16,6,c)
  draw(x+9,y+16,5,4,c)
  draw(x+8,y+16,1,2,c)
def cavalierb(x,y,c=blanc):
  x=int(xn(x));y=int(yn(y))
  draw(x+1,y+6,3,14,c)
  draw(x+2,y+8,3,10,c)
  draw(x+5,y+9,4,8,c)
  draw(x+4,y+10,16,6,c)
  draw(x+11,y+6,5,4,c)
  draw(x+16,y+8,1,2,c)
def pionn(x,y,c=noir):
  x=int(xn(x));y=int(yn(y))
  draw(x+21,y+6,3,13,c)
  for i in range(3):
    draw(x+20-i*4,y+8+i,4,9-i*2,c)
    draw(x+13-i,y+10-i,1,5+i*2,c)
    draw(x+8-i,y+8+i,1,9-i*2,c)
  draw(x+9,y+8,2,9,c)
def pionb(x,y,c=blanc):
  x=int(xn(x));y=int(yn(y))
  draw(x+1,y+6,3,13,c)
  for i in range(3):
    draw(x+1+i*4,y+8+i,4,9-i*2,c)
    draw(x+11+i,y+10-i,1,5+i*2,c)
    draw(x+16+i,y+8+i,1,9-i*2,c)
  draw(x+14,y+8,2,9,c)
def foun(x,y,c=noir):
  x=int(xn(x));y=int(yn(y))
  draw(x+21,y+6,3,13,c)
  for i in range(3):
    draw(x+20-i*4,y+8+i,4,9-i*2,c)
    draw(x+14-i*2,y+10-i,2,5+i*2,c)
    draw(x+9-i*2,y+8+i,2,9-i*2,c)
  draw(x+3,y+11,2,3,c)
def foub(x,y,c=blanc):
  x=int(xn(x));y=int(yn(y))
  draw(x+1,y+6,3,13,c)
  for i in range(3):
    draw(x+1+i*4,y+8+i,4,9-i*2,c)
    draw(x+9+i*2,y+10-i,2,5+i*2,c)
    draw(x+14+i*2,y+8+i,2,9-i*2,c)
  draw(x+20,y+11,2,3,c)
def plateau():
  pl=0
  draw(59,1,202,16,plt[0])
  txt("Echecs by Caucaucybu",60,0,noir,plt[0])
  draw(59,19,202,202,noir)
  draw(60,20,200,200,blanc)
  draw(262,1,57,220,noir)
  draw(0,1,58,220,noir)
  draw(1,2,56,218,blanc)
  for i in range(60,255,25):
    if pl:pl=0
    else:pl=1
    for j in range(20,220,25):
      if pl:draw(i,j,25,25,plt[0]);pl=0
      else:draw(i,j,25,25,plt[1]);pl=1
def depiece(x,y,c=0):
  x=xn(x);y=yn(y)
  if not c:c=get(x,y)
  draw(x,y,25,25,c)
def chercher(x,y,rst=0):
  x=int(xn(x));y=int(yn(y));p=get(x+12,y+12);blanc=get(3,3);noir=get(315,3)
  if p in plt:return 0
  if rst:
    if p==blanc:pa=noir
    elif p==noir:pa=blanc
  else:pa=(p[0],p[1],p[2])
  if pa==noir:
    if get(x+4,y+6)==p:return "t",0
    if get(x+2,y+11)==p:return "k",0
    if get(x+8,y+2)==p:return "r",0
    if get(x+16,y+16)==p:return "c",0
    if get(x+3,y+11)==p:return "f",0
    return "p",0
  if pa==blanc:
    if get(x+20,y+6)==p:return "t",-1
    if get(x+22,y+11)==p:return "k",-1
    if get(x+15,y+2)==p:return "r",-1
    if get(x+8,y+16)==p:return "c",-1
    if get(x+20,y+11)==p:return "f",-1
    return "p",-1
def repiece0(x,y,tpe,c=noir):
  if tpe=="t":tourn(x,y,c)
  if tpe=="c":cavaliern(x,y,c)
  if tpe=="p":pionn(x,y,c)
  if tpe=="k":roin(x,y,c)
  if tpe=="r":reinen(x,y,c)
  if tpe=="f":foun(x,y,c)
def repiece1(x,y,tpe,c=blanc):
  if tpe=="t":tourb(x,y,c)
  if tpe=="c":cavalierb(x,y,c)
  if tpe=="p":pionb(x,y,c)
  if tpe=="k":roib(x,y,c)
  if tpe=="r":reineb(x,y,c)
  if tpe=="f":foub(x,y,c)
def chpiece(tour,i,it,j=-1,jt=1):
  tst=0
  while 1: 
    if tst and tst[1]==tour:break
    j+=jt
    if j==8:j=0;i-=it
    if j==-1:j=7;i+=it
    if i==-1:i=7
    if i==8:i=0
    tst=chercher(i,j)
  gris(i,j)
  if it==-1:repiece0(i,j,tst[0])
  if it==1:repiece1(i,j,tst[0])
  return i,j,tst[0]
def repieceg(tour,lst,tpi):
  x=lst[0];y=lst[1]
  if not tour:
    if len(lst)==3:repiece1(x,y,lst[2])
    repiece0(x,y,tpi,grey)
  else:
    if len(lst)==3:repiece0(x,y,lst[2])
    repiece1(x,y,tpi,grey)
def w(a,b,c):depiece(a,b);repiece0(a,b,c)
def r(a,b,c):depiece(a,b);repiece1(a,b,c)
def inplt(val):return -1<val<8
def gris(x,y):
  x=xn(x);y=yn(y);p=0
  for k in range(x,x+25):
    for l in range(y,y+25):
      if p:draw(k,l,1,1,(0,0,0));p=0
      else:p=1