├── LICENSE.md └── initial /LICENSE.md: -------------------------------------------------------------------------------- 1 | // free // 2 | -------------------------------------------------------------------------------- /initial: -------------------------------------------------------------------------------- 1 | import pygame 2 | import os 3 | 4 | # Initialize pygame 5 | pygame.init() 6 | 7 | # Constants 8 | SCREEN_WIDTH, SCREEN_HEIGHT = 800, 800 9 | SQUARE_SIZE = SCREEN_WIDTH // 8 10 | PIECE_SIZE = SQUARE_SIZE - 10 11 | WHITE, BLACK = (255, 255, 255), (0, 0, 0) 12 | FPS = 60 13 | 14 | # Load images 15 | def load_images(): 16 | pieces = {} 17 | for piece in ['bB', 'bK', 'bN', 'bP', 'bQ', 'bR', 'wB', 'wK', 'wN', 'wP', 'wQ', 'wR']: 18 | pieces[piece] = pygame.transform.scale(pygame.image.load(os.path.join("images", f"{piece}.png")), (PIECE_SIZE, PIECE_SIZE)) 19 | return pieces 20 | 21 | # Draw board 22 | def draw_board(screen): 23 | for row in range(8): 24 | for col in range(8): 25 | color = WHITE if (row + col) % 2 == 0 else BLACK 26 | pygame.draw.rect(screen, color, (col * SQUARE_SIZE, row * SQUARE_SIZE, SQUARE_SIZE, SQUARE_SIZE)) 27 | 28 | # Draw pieces 29 | def draw_pieces(screen, board, pieces): 30 | for row in range(8): 31 | for col in range(8): 32 | piece = board[row][col] 33 | if piece != "--": 34 | screen.blit(pieces[piece], (col * SQUARE_SIZE + 5, row * SQUARE_SIZE + 5)) 35 | 36 | # Initial board setup 37 | def initial_board(): 38 | return [ 39 | ["bR", "bN", "bB", "bQ", "bK", "bB", "bN", "bR"], 40 | ["bP", "bP", "bP", "bP", "bP", "bP", "bP", "bP"], 41 | ["--", "--", "--", "--", "--", "--", "--", "--"], 42 | ["--", "--", "--", "--", "--", "--", "--", "--"], 43 | ["--", "--", "--", "--", "--", "--", "--", "--"], 44 | ["--", "--", "--", "--", "--", "--", "--", "--"], 45 | ["wP", "wP", "wP", "wP", "wP", "wP", "wP", "wP"], 46 | ["wR", "wN", "wB", "wQ", "wK", "wB", "wN", "wR"] 47 | ] 48 | 49 | # Main game loop 50 | def main(): 51 | screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) 52 | pygame.display.set_caption("Chess") 53 | clock = pygame.time.Clock() 54 | pieces = load_images() 55 | board = initial_board() 56 | 57 | running = True 58 | while running: 59 | for event in pygame.event.get(): 60 | if event.type == pygame.QUIT: 61 | running = False 62 | 63 | draw_board(screen) 64 | draw_pieces(screen, board, pieces) 65 | pygame.display.flip() 66 | clock.tick(FPS) 67 | 68 | pygame.quit() 69 | 70 | if __name__ == "__main__": 71 | main() 72 | --------------------------------------------------------------------------------