Skip to content
TheChatArchiveThe Chat Archive
Metallama-2-70b-chat· MetaHugging Face Arena Human Preference 55K

write snake game in python

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Qwenqwen-14b-chat’s answer.
  1. User

    write snake game in python

  2. Meta Assistant

    Sure! Here's a simple implementation of the classic Snake game in Python using the Pygame library:

    import pygame
    
    # Initialize pygame
    pygame.init()
    
    # Set the screen dimensions
    screen_width = 640
    screen_height = 480
    screen = pygame.display.set_mode((screen_width, screen_height))
    
    # Set the title of the window
    pygame.display.set_caption('Snake Game')
    
    # Define some colors
    BLACK = (0, 0, 0)
    WHITE = (255, 255, 255)
    GREEN = (0, 255, 0)
    
    # Define the snake's starting position
    snake_x = 320
    snake_y = 240
    
    # Define the snake's length
    snake_length = 10
    
    # Define the food's position
    food_x = 400
    food_y = 300
    
    # Define the speed of the snake
    snake_speed = 10
    
    # Define the score
    score = 0
    
    # Main game loop
    while True:
        # Handle events
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
    
        # Move the snake
        keys = pygame.key.get_pressed()
        if keys[pygame.K_LEFT]:
            snake_x -= snake_speed
        if keys[pygame.K_RIGHT]:
            snake_x += snake_speed
        if keys[pygame.K_UP]:
            snake_y -= snake_speed
        if keys[pygame.K_DOWN]:
            snake_y += snake_speed
    
        # Check for collision with walls and food
        if snake_x < 0 or snake_x >= screen_width - 1 or snake_y < 0 or snake_y >= screen_height - 1:
            print('Game Over!')
            pygame.quit()
            sys.exit()
        elif
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.