<commit_before>var WIDTH = 700, HEIGHT = 600, PI = Math.PI;
var upArrow = 38, downArrow = 40;
var canvas, context, keystate;
var player, ai, ball;

player = {
    x: null,
    y: null,
    width: 20,
    height: 100,

    update: function() {
        if (keystate[upArrow])
            this.y -= 7;
        if (keystate[downArrow])
            this.y += 7;
    },
    draw: function() {
        context.fillRect(this.x, this.y, this.width, this.height);
    }
}

ai = {
    x: null,
    y: null,
    width: 20,
    height: 100,

    update: function() {
        var dest_y = ball.y - (this.height + ball.side) * 0.5;
        this.y += (dest_y - this.y) * 0.1;
    },
    draw: function() {
        context.fillRect(this.x, this.y, this.width, this.height);
    }
}

ball = {
    x: null,
    y: null,
    side: 20,
    speed: 5,
    velocity: null,

    serve: function(side) {
        var r = Math.random();
        this.x = side === 1 ? player.x : ai.x - this.side;
        this.y = (HEIGHT - this.side) * r;

        var phi = 0.1 * PI * (1 - 2 * r);
        this.velocity = {
            x: side * this.speed * Math.cos(phi),
            y: this.speed * Math.sin(phi)
        }
    },
    update: function() {
        this.x += this.velocity.x;
        this.y += this.velocity.y;<commit_msg>Correct bug for paddles scrolling outside the canvas<commit_after>var WIDTH = 700, HEIGHT = 600, PI = Math.PI;
var upArrow = 38, downArrow = 40;
var canvas, context, keystate;
var player, ai, ball;

player = {
    x: null,
    y: null,
    width: 20,
    height: 100,

    update: function() {
        if (keystate[upArrow])
            this.y -= 7;
        if (keystate[downArrow])
            this.y += 7;

        this.y = Math.max(Math.min(this.y, HEIGHT - this.height), 0);
    },
    draw: function() {
        context.fillRect(this.x, this.y, this.width, this.height);
    }
}

ai = {
    x: null,
    y: null,
    width: 20,
    height: 100,

    update: function() {
        var dest_y = ball.y - (this.height + ball.side) * 0.5;
        this.y += (dest_y - this.y) * 0.1;

        this.y = Math.max(Math.min(this.y, HEIGHT - this.height), 0);
    },
    draw: function() {
        context.fillRect(this.x, this.y, this.width, this.height);
    }
}

ball = {
    x: null,
    y: null,
    side: 20,
    speed: 5,
    velocity: null,

    serve: function(side) {
        var r = Math.random();
        this.x = side === 1 ? player.x + player.width: ai.x - this.side;
        this.y = (HEIGHT - this.side) * r;

        var phi = 0.1 * PI * (1 - 2 * r);
        this.velocity = {
            x: side * this.speed * Math.cos(phi),
            y: this.speed * Math.sin(phi)
        }
    },
    update: function() {
        this.x += this.velocity.x;
        this.y += this.velocity.y;
{'fraction_non_alphanumeric': 0.16086175942549372, 'fraction_numerical': 0.025134649910233394, 'mean_word_length': 1.7421259842519685, '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': '148038', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1009, 'n_words': 255}