chess3.py

Created by schraf

Created on January 28, 2021

1.3 KB

Déplacements possibles pour une pièce blanche sur un échiquier vide. Par exemple :
>> jeu(T,"e4")

>> jeu(D,"g8")

>> jeu(C,"a6")


from kandinsky import *

# Deplacements
nn,ss,ee,oo,ne,no,se,so = [0,1],[0,-1],[1,0],[-1,0],[1,1],[1,-1],[-1,1],[-1,-1]

P = [[0,120,252,252,120,120,252,510,510,0],[nn],1]
T = [[0,438,438,510,252,252,252,510,510,0],[nn,ss,ee,oo],8]
C = [[0,56,124,124,240,248,252,510,510,0],[[1,2],[-1,2],[1,-2],[-1,-2],[2,1],[2,-1],[-2,1],[-2,-1]],1]
F = [[48,56,156,220,478,510,252,510,510,0],[ne,no,se,so],8]
R = [[48,120,48,252,510,252,252,510,510,0],[nn,ss,ee,oo,ne,no,se,so],1]
D = [[72,120,306,438,180,252,252,510,510,0],[nn,ss,ee,oo,ne,no,se,so],8]



def dessin(x,y,p,coul):
  for c in range(10):
    for l in range(10):
      if p[l]>>c & 1:
        car(x+2*c,y+2*l,2,coul)

def car(x,y,t,c):
  for i in range(t*t): 
    set_pixel(x+i%t,y+i//t,c)
    # effet quadrillage
    # set_pixel(x+i%t,y+i//t,c*(i>t and i%t!=0))
    
def jeu(piece, pos):
  g,h=30,30
  for c in range(8):
    for l in range(8):
      coul = (110,110,220) if (c+l)%2==0 else (0,0,0)
      car(g+20*c,h+20*l,20,coul)
    draw_string(str(c+1),g-20,h+1+7*20-20*c)
    draw_string(chr(97+c),g+5+20*c,h-20)
  x,y = ord(pos[0])-97, int(pos[1])-1
  dessin(g+20*x,h+140-20*y,piece[0],(248,255,248))
  for d in piece[1]:
    for j in range(1,piece[2]+1):
      if 0<=x+j*d[0]<8 and 0<=y+j*d[1]<8:
        car(g+20*(x+j*d[0]),h+140-20*(y+j*d[1]),20,(50,240,40))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.