chess.py

Created by 1epauletteshark

Created on September 13, 2025

1.13 KB

The classic game of chess


from kandinsky import fill_rect as rect

W,H = 320,222
SQUARES = 8
SSIZE = int(H/SQUARES-1)
print(SSIZE)


XOFFSET = int((W-SQUARES*SSIZE)/2)
YOFFSET = int((H-SQUARES*SSIZE)/2)
BORDER = 2
rect(0,0,W,H,"black")


def render(x,y,peice,player):
  x=int(x)
  y=int(y)
  SPRITES = {}
  draw=SPRITES[peice]
  for i in range(0,len(draw[0]),4):
    pixel=draw[0][i:i+4]
    pixel_x=x-draw[1]+int(pixel[:2])
    pixel_y=y-draw[2]+int(pixel[2:4])
    set_pixel(pixel_x,pixel_y,"red" if player = 1 else "blue")

def draw_board():
  rect(XOFFSET-BORDER,YOFFSET-BORDER,W-2*(XOFFSET-BORDER),H-2*(YOFFSET - BORDER),"white")
  for y in range (SQUARES):
    for x in range (SQUARES):
      if (x+y) % 2 == 0:
        rect(XOFFSET+x*SSIZE,YOFFSET+y*SSIZE,SSIZE,SSIZE,"grey")


def draw_pieces(pieces):
  for piece in pieces:
    rect(XOFFSET + piece.x * SSIZE,YOFFSET + piece.y * SSIZE,15,15,"black")


class Piece():
  def __init__(self,piece,player,x,y,):
    self.piece = piece
    self.player = player
    self.x = x
    self.y = y
    
pieces = [Piece("pawn",1,i,1) for i in range(8)] + [Piece("pawn",2,i,6) for i in range(8)]
draw_board()
draw_pieces(pieces)

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.