<commit_before>﻿var replayContext;
const tileDepth = 0.78;
const tileWidth = 0.97;
const tileHeight = 1.28;
const gap = 0.2;

function initReplay() {
    replayContext = new RenderContext("replayCanvas");
    replayContext.setCameraPosition(0, -21, 31);
    replayCreateLights();

    replayContext.createTiles(() => arrange());
}

function arrange() {
    const input = document.querySelector("#gameDataJson");
    const json = input.value;
    const data = JSON.parse(json);
    const wall = data.slice(0, 136);
    const dice = data.slice(136, 138);

    const oyaId = 0;
    const tilesDrawn = 13 * 3;
    const rinshanTilesDrawn = 0;

    createWall(wall, dice, oyaId, tilesDrawn, rinshanTilesDrawn);
    //createPond();
    createHands(wall, oyaId);
}

function createHands(wall, oyaId) {
    const a = -(14 * tileWidth + gap) / 2;
    const b = -(11 * tileWidth);
    const y = b - 0.5 * tileHeight;
    for (let i = 0; i < 4; i++) {
        let x = a + 0.5 * tileWidth - tileWidth;
        const handTiles = getDealtTileIds(wall, i, oyaId);
        const tilesInHand = 13;
        for (let k = 0; k < handTiles.length; k++) {
            const tileId = handTiles[k];
            addTile(i, tileId, x, y, 0, i === 0 ? -0.40 : 3, 0);
            if (k === tilesInHand - 2 && tilesInHand % 3 === 2) {
                x += gap;
            }
            x += tileWidth;
        }

        //let meldX = -a + 4 * tileWidth;
        //const meldCount = Math.floor((14 - tilesInHand) / 3);
        //for (let j = 0; j < meldCount; ++j) {
        //    const meldTileIds = [wall[135 - wallId++], wall[135 - wallId++], wall[135 - wallId++], wall[135 - wallId++]];
        //    meldX = createMeld(i, meldX, meldTileIds);
        //}
    }
}

function getDealtTileIds(wall, playerId, oyaId) {
    var tileIds = [];
    const offset = (playerId - oyaId) * 4;
    for (let i = 0; i < 3; i++) {
        tileIds = tileIds.concat(wall.slice(136 - (offset + i * 16 + 4), 136 - (offset + i * 16)));
    }
    tileIds.push(wall[135 - (offset + 3 * 4 * 4)]);
    tileIds.sort((a, b) => a - b);
    return tileIds;
}

function createWall(wall, dice, oyaId, tilesDrawn, rinshanTilesDrawn) {
    const layoutOffset = -(17 * tileWidth + tileHeight + gap) / 2;
    const y = layoutOffset + 0.5 * tileHeight;
    const xStart = layoutOffset + 0.5 * tileWidth + tileHeight + gap;

    const diceSum = dice[0] + dice[1];
    const wallOffset = (20 - diceSum - oyaId) * 34 + diceSum * 2;

    var wallId = 0;

    for (let i = 0; i < 4; i++) {
        let x = xStart;
        for (let j = 0; j < 17; j++) {
            for (let k = 0; k < 2; k++) {
                const shiftedId = (wallId + wallOffset) % 136;
                if (shiftedId === 0) {
                    x += gap;
                }
                const tileId = wall[shiftedId];
                addTile(i, tileId, x, y, k * tileDepth, shiftedId === 5 ? 0 : 2, 0);<commit_msg>remove drawn tiles from wall<commit_after>﻿var replayContext;
const tileDepth = 0.78;
const tileWidth = 0.97;
const tileHeight = 1.28;
const gap = 0.2;

function initReplay() {
    replayContext = new RenderContext("replayCanvas");
    replayContext.setCameraPosition(0, -21, 31);
    replayCreateLights();

    replayContext.createTiles(() => arrange());
}

function arrange() {
    const input = document.querySelector("#gameDataJson");
    const json = input.value;
    const data = JSON.parse(json);
    const wall = data.slice(0, 136);
    const dice = data.slice(136, 138);

    const oyaId = 0;
    const tilesDrawn = 13 * 4;
    const rinshanTilesDrawn = 0;

    createWall(wall, dice, oyaId, tilesDrawn, rinshanTilesDrawn);
    //createPond();
    createHands(wall, oyaId);
}

function createHands(wall, oyaId) {
    const a = -(14 * tileWidth + gap) / 2;
    const b = -(11 * tileWidth);
    const y = b - 0.5 * tileHeight;
    for (let i = 0; i < 4; i++) {
        let x = a + 0.5 * tileWidth - tileWidth;
        const handTiles = getDealtTileIds(wall, i, oyaId);
        const tilesInHand = 13;
        for (let k = 0; k < handTiles.length; k++) {
            const tileId = handTiles[k];
            addTile(i, tileId, x, y, 0, i === 0 ? -0.40 : 3, 0);
            if (k === tilesInHand - 2 && tilesInHand % 3 === 2) {
                x += gap;
            }
            x += tileWidth;
        }

        //let meldX = -a + 4 * tileWidth;
        //const meldCount = Math.floor((14 - tilesInHand) / 3);
        //for (let j = 0; j < meldCount; ++j) {
        //    const meldTileIds = [wall[135 - wallId++], wall[135 - wallId++], wall[135 - wallId++], wall[135 - wallId++]];
        //    meldX = createMeld(i, meldX, meldTileIds);
        //}
    }
}

function getDealtTileIds(wall, playerId, oyaId) {
    var tileIds = [];
    const offset = (playerId - oyaId) * 4;
    for (let i = 0; i < 3; i++) {
        tileIds = tileIds.concat(wall.slice(136 - (offset + i * 16 + 4), 136 - (offset + i * 16)));
    }
    tileIds.push(wall[135 - (offset + 3 * 4 * 4)]);
    tileIds.sort((a, b) => a - b);
    return tileIds;
}

function createWall(wall, dice, oyaId, tilesDrawn, rinshanTilesDrawn) {
    const layoutOffset = -(17 * tileWidth + tileHeight + gap) / 2;
    const y = layoutOffset + 0.5 * tileHeight;
    const xStart = layoutOffset + 0.5 * tileWidth + tileHeight + gap;

    const diceSum = dice[0] + dice[1];
    const wallOffset = (20 - diceSum - oyaId) * 34 + diceSum * 2;

    var wallId = 0;

    for (let i = 0; i < 4; i++) {
        let x = xStart;
        for (let j = 0; j < 17; j++) {
            for (let k = 0; k < 2; k++) {
                const shiftedId = (wallId + wallOffset) % 136;
                if (shiftedId === 0) {
                    x += gap;
                }
                const rinshanId = shiftedId % 2 === 0 ? shiftedId + 1 : shiftedId - 1;
                if (rinshanId >= rinshanTilesDrawn && shiftedId < 136 - tilesDrawn) {
                    const tileId = wall[shiftedId];
                    addTile(i, tileId, x, y, k * tileDepth, shiftedId === 5 ? 0 : 2, 0);
                }
{'fraction_non_alphanumeric': 0.15148514851485148, 'fraction_numerical': 0.04141914191419142, 'mean_word_length': 2.050327126321087, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 8, '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': '1083708', 'n_tokens_mistral': 2322, 'n_tokens_neox': 2087, 'n_words': 598}