<commit_before>import pygame
import sys
import copy
import random

pygame.init()

# Configuration
width = 500
height = 500
screen = pygame.display.set_mode((width, height))
cellSize = 15;
cellsX = round(width/cellSize);
cellsY = round(height/cellSize);
snake = None
food = None
gameloop = True

# set default drawing colors
color = (0,0,0)
bgColor = (255,255,255)


class SNAKE:
    def __init__(self):
        self.elements = []
        self.direction = 'right'
        self.length = 5

    def create(self):
        self.elements = []
        i = self.length
        while i != 0:
            self.elements.append({'x': i, 'y':0})
            i -= 1

    def render(self):
        for element in snake.elements:
            draw(element)

    def move(self):
        global gameloop
        elementToMove = copy.deepcopy(self.elements)
        elementToMove = elementToMove[0]
        if self.direction == 'right':
            elementToMove['x'] = elementToMove['x'] + 1
        elif self.direction == 'left':
            elementToMove['x'] = elementToMove['x'] - 1
        elif self.direction == 'down':
            elementToMove['y'] = elementToMove['y'] + 1
        elif self.direction == 'up':
            elementToMove['y'] = elementToMove['y'] - 1

        if (elementToMove['x'] == -1 or
            elementToMove['x'] == cellsX or
            elementToMove['y'] == -1 or
            elementToMove['y'] == cellsY):
			# restart game
			gameloop = False

        self.elements.pop()
        self.elements.insert(0, elementToMove)

class FOOD:
    def __init__(self):
        self.position = None

    def create(self):
        self.position = {
            'x': random.randrange(0, (width - cellSize)/cellSize, 1),
            'y': random.randrange(0, (height - cellSize)/cellSize, 1)
        }

    def render(self):
        draw(self.position)

def initGame():
    global snake, food
    snake = SNAKE()
    snake.direction = 'right'
    snake.create()
    food = FOOD()
    food.create()
    score = 0


def draw(element):
    pygame.draw.rect(
        screen,
        color,
        (
            element['x'] * cellSize,
            element['y'] * cellSize,
            cellSize,
            cellSize
        ),
        0
    )

def render():
    snake.move()
    snake.render()
    food.render()

initGame()

# main game loop
while (True):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit(); sys.exit();

    # fill screen with default background color
    screen.fill(bgColor);

    #draw single rectangle
    if gameloop:
        render()
        pygame.display.update()<commit_msg>[PY] - :european_post_office: keyboard controll<commit_after>import pygame
import sys
import copy
import random

pygame.init()

# Configuration
width = 500
height = 500
screen = pygame.display.set_mode((width, height))
cellSize = 15;
cellsX = round(width/cellSize);
cellsY = round(height/cellSize);
snake = None
food = None
gameloop = True

# set default drawing colors
color = (0,0,0)
bgColor = (255,255,255)


class SNAKE:
    def __init__(self):
        self.elements = []
        self.direction = 'right'
        self.length = 5

    def create(self):
        self.elements = []
        i = self.length
        while i != 0:
            self.elements.append({'x': i, 'y':0})
            i -= 1

    def render(self):
        for element in snake.elements:
            draw(element)

    def move(self):
        global gameloop
        elementToMove = copy.deepcopy(self.elements)
        elementToMove = elementToMove[0]
        if self.direction == 'right':
            elementToMove['x'] = elementToMove['x'] + 1
        elif self.direction == 'left':
            elementToMove['x'] = elementToMove['x'] - 1
        elif self.direction == 'down':
            elementToMove['y'] = elementToMove['y'] + 1
        elif self.direction == 'up':
            elementToMove['y'] = elementToMove['y'] - 1

        if (elementToMove['x'] == -1 or
            elementToMove['x'] == cellsX or
            elementToMove['y'] == -1 or
            elementToMove['y'] == cellsY):
			# restart game
			gameloop = False

        self.elements.pop()
        self.elements.insert(0, elementToMove)

class FOOD:
    def __init__(self):
        self.position = None

    def create(self):
        self.position = {
            'x': random.randrange(0, (width - cellSize)/cellSize, 1),
            'y': random.randrange(0, (height - cellSize)/cellSize, 1)
        }

    def render(self):
        draw(self.position)

def initGame():
    global snake, food
    snake = SNAKE()
    snake.direction = 'right'
    snake.create()
    food = FOOD()
    food.create()
    score = 0


def draw(element):
    pygame.draw.rect(
        screen,
        color,
        (
            element['x'] * cellSize,
            element['y'] * cellSize,
            cellSize,
            cellSize
        ),
        0
    )

def render():
    snake.move()
    snake.render()
    food.render()

initGame()

# main game loop
while (True):
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit(); sys.exit();
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                snake.direction = 'left'
            if event.key == pygame.K_RIGHT:
                snake.direction = 'right'
            if event.key == pygame.K_DOWN:
                snake.direction = 'down'
            if event.key == pygame.K_UP:
                snake.direction = 'up'
    # fill screen with default background color
    screen.fill(bgColor);

    #draw single rectangle
    if gameloop:
        render()
        pygame.display.update()
{'fraction_non_alphanumeric': 0.12903225806451613, 'fraction_numerical': 0.01332398316970547, 'mean_word_length': 1.9791122715404699, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3898045', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1742, 'n_words': 425}