<commit_before>class Board {
    constructor(width, height, gameWidth, gameHeight, inputs, outputs, pieces){
        this.layout = new Array(gameWidth);
        for(var i = 0; i < gameWidth; i++){
            this.layout[i] = new Array(gameHeight);
        }
        this.width = width;
        this.height = height;
        this.inputs = inputs;
        this.outputs = outputs;
        this.pieces = pieces;
    }

    set width(width){
        this._width = width;
        this.updateBoardDim();
    }

    get width(){
        return this._width;
    }

    set height(height){
        this._height = height;
        this.updateBoardDim();
    }

    get height(){
        return this._height;
    }

    updateBoardDim(){
        // Find a scale unit on the board
        // This is the number of pixels a square takes up
        var unitWidth = (this.width - 20) / this.gameWidth;
        var unitHeight = (this.height - 30) / (this.gameHeight + 1);
        if (unitWidth < unitHeight) {
            this._unit = unitWidth;
        } else {
            this._unit = unitHeight;
        }
    }

    get unit(){
        return this._unit;
    }

    get boardWidth(){
        return this.unit * this.gameWidth;
    }

    get boardHeight(){
        return this.unit * this.gameHeight;
    }

    get boardX(){
        return (this.width - this.boardWidth) / 2;
    }

    get boardY(){
        return ((this.height - this.boardHeight - this.unit) / 2) - 5;
    }

    get gameWidth(){
        return this.layout.length;
    }

    get gameHeight(){
        return this.layout[0].length;
    }

    draw(canvas){
        canvas.fillStyle = "#000000";
        canvas.fillRect(this.boardX ,this.boardY, this.boardWidth, this.boardHeight);
        var color = false;
        for(var x = 0; x < this.gameWidth; x++){
            if (this.gameWidth % 2 != 0) color = !color;
            for(var y = 0; y < this.gameHeight; y++){
                color = !color;
                canvas.fillStyle = color ? "#555555" : "#333333";
                canvas.fillRect(this.unit * x + this.boardX, this.unit * y + this.boardY, this.unit, this.unit);
                var piece = pieceAsset(this.layout[x][y], false);
                if (piece != null) {
                    canvas.drawImage(piece, this.unit * x + this.boardX, this.unit * y + this.boardY, this.unit, this.unit);
                }
            }
        }
        for(var x = 0; x < this.gameWidth; x++){
            color = !color;
            canvas.fillStyle = color ? "#555555" : "#333333";
            canvas.fillRect(this.unit * x + this.boardX, this.boardHeight + this.boardY + 10, this.unit, this.unit);
            if(x < this.pieces.length){
                canvas.drawImage(pieceAsset(this.pieces[x], false), this.unit * x + this.boardX, this.boardHeight + this.boardY + 10, this.unit, this.unit);
            }
        }
    }

    getPiece(x, y) {
        var tmp = (y - this.boardY - this.boardHeight - 10);
        if (tmp > 0 && tmp < this.unit) {
            tmp = Math.trunc((x - this.boardX) / this.unit);
            if (0 <= tmp && tmp < this.pieces.length){
                return this.pieces.splice(tmp, 1);
            }
        } else {
            var cx = Math.trunc((x - this.boardX) / this.unit);
            var cy = Math.trunc((y - this.boardY) / this.unit);
            if (0 <= cy && 0 <= cx && cy < this.gameHeight && cx < this.gameWidth && this.layout[cx][cy] != 0) {
                tmp = this.layout[cx][cy];
                this.layout[cx][cy] = null;
                return tmp;
            }
        }
        return null;
    }

    setPiece(x, y, p) {
        if (p != null) {
            var cx = Math.trunc((x - this.boardX) / this.unit);
            var cy = Math.trunc((y - this.boardY) / this.unit);
            if (0 <= cy && 0 <= cx && cy < this.gameHeight && cx < this.gameWidth && this.layout[cx][cy] == null) {
                this.layout[cx][cy] = p;
            } else {
                this.pieces.push(p);
            }
        }
    }
}

var board;
var canvas;
var mouseDown;
var mouseX, mouseY;
var pieceAssets;
var wireAssets;
var currentPiece;

// This will return the image that is associated with a piece number then the given state if on or off
function pieceAsset(num, bool) { return pieceAssets[(2 * num) - (bool ? 2 : 1)]; }<commit_msg>Getting ready for wire drawing<commit_after>class Board {
    constructor(width, height, gameWidth, gameHeight, inputs, outputs, pieces){
        this.layout = new Array(gameWidth);
        for(var i = 0; i < gameWidth; i++){
            this.layout[i] = new Array(gameHeight);
        }
        this.width = width;
        this.height = height;
        this.inputs = inputs;
        this.outputs = outputs;
        this.pieces = pieces;
    }

    set width(width){
        this._width = width;
        this.updateBoardDim();
    }

    get width(){
        return this._width;
    }

    set height(height){
        this._height = height;
        this.updateBoardDim();
    }

    get height(){
        return this._height;
    }

    updateBoardDim(){
        // Find a scale unit on the board
        // This is the number of pixels a square takes up
        var unitWidth = (this.width - 20) / this.gameWidth;
        var unitHeight = (this.height - 30) / (this.gameHeight + 1);
        if (unitWidth < unitHeight) {
            this._unit = unitWidth;
        } else {
            this._unit = unitHeight;
        }
    }

    get unit(){
        return this._unit;
    }

    get boardWidth(){
        return this.unit * this.gameWidth;
    }

    get boardHeight(){
        return this.unit * this.gameHeight;
    }

    get boardX(){
        return (this.width - this.boardWidth) / 2;
    }

    get boardY(){
        return ((this.height - this.boardHeight - this.unit) / 2) - 5;
    }

    get gameWidth(){
        return this.layout.length;
    }

    get gameHeight(){
        return this.layout[0].length;
    }

    draw(canvas){
        canvas.fillStyle = "#000000";
        canvas.fillRect(this.boardX ,this.boardY, this.boardWidth, this.boardHeight);
        var color = false;
        for(var x = 0; x < this.gameWidth; x++){
            if (this.gameWidth % 2 != 0) color = !color;
            for(var y = 0; y < this.gameHeight; y++){
                color = !color;
                canvas.fillStyle = color ? "#555555" : "#333333";
                canvas.fillRect(this.unit * x + this.boardX, this.unit * y + this.boardY, this.unit, this.unit);
                var piece = pieceAsset(this.layout[x][y], false);
                if (piece != null) {
                    canvas.drawImage(piece, this.unit * x + this.boardX, this.unit * y + this.boardY, this.unit, this.unit);
                }
            }
        }
        for(var x = 0; x < this.gameWidth; x++){
            color = !color;
            canvas.fillStyle = color ? "#555555" : "#333333";
            canvas.fillRect(this.unit * x + this.boardX, this.boardHeight + this.boardY + 10, this.unit, this.unit);
            if(x < this.pieces.length){
                canvas.drawImage(pieceAsset(this.pieces[x], false), this.unit * x + this.boardX, this.boardHeight + this.boardY + 10, this.unit, this.unit);
            }
        }
    }

    getPiece(x, y) {
        var tmp = (y - this.boardY - this.boardHeight - 10);
        if (tmp > 0 && tmp < this.unit) {
            tmp = Math.trunc((x - this.boardX) / this.unit);
            if (0 <= tmp && tmp < this.pieces.length){
                return this.pieces.splice(tmp, 1);
            }
        } else {
            var cx = Math.trunc((x - this.boardX) / this.unit);
            var cy = Math.trunc((y - this.boardY) / this.unit);
            if (0 <= cy && 0 <= cx && cy < this.gameHeight && cx < this.gameWidth && this.layout[cx][cy] != 0) {
                tmp = this.layout[cx][cy];
                this.layout[cx][cy] = undefined;
                return tmp;
            }
        }
        return null;
    }

    setPiece(x, y, p) {
        if (p != null) {
            var cx = Math.trunc((x - this.boardX) / this.unit);
            var cy = Math.trunc((y - this.boardY) / this.unit);
            if (0 <= cy && 0 <= cx && cy < this.gameHeight && cx < this.gameWidth && [0, null, undefined].includes(this.layout[cx][cy])) {
                this.layout[cx][cy] = p;
            } else {
                this.pieces.push(p);
            }
        }
    }
}

var board;
var canvas;
var mouseDown;
var mouseX, mouseY;
var pieceAssets;
var wireAssets;
var currentPiece;

// This will return the image that is associated with a piece number then the given state if on or off
function pieceAsset(num, bool) { 
    if (num > 0) {
        return pieceAssets[(2 * num) - (bool ? 2 : 1)];
    } else if (num == 0) {
        return wireAssets[1];
    }
}
{'fraction_non_alphanumeric': 0.13828584350972412, 'fraction_numerical': 0.014473089099954772, 'mean_word_length': 1.6673703256936068, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 6, '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': '604609', 'n_tokens_mistral': 2860, 'n_tokens_neox': 2677, 'n_words': 698}