首页 > 解决方案 > JS棋盘阅读器Y坐标问题

问题描述

我正在尝试从棋盘的 X 和 Y 值(如 a1、h3 ... 等)标准化国际象棋坐标但是 Y 坐标存在问题,它被反对。所以,我试着做,TempYStorage[8-i]但价值观根本没有改变。这对我来说似乎很奇怪。棋盘,试图从https://prnt.sc/uhjyk5读取 我的测试结果 - https://pastebin.com/1tQFTnR3

JS 函数,标准化 X 和 Y 坐标:

function NormalizeCoordinates()
{
    let Storage = SetupPieces(); // Getting the Pieces from the board (Storage[0] -> X Storage[1] -> Y Storage[2] -> Piece Name)

    let xAxis = ["a","b","c","d","e","f","g","h"];
    let yAxis = [1,2,3,4,5,6,7,8];

    var TempXStorage = []; // Arrays for the normalised values to be stored in
    var TempYStorage = [];

    var TempReadyCoord = [];
    for(var i=0;i<Storage[0].length;i++)
    {
        //console.log("x:" + Storage[0][i] + " y:" + Storage[1][i]); // Test console logging, to see, if x and y values are present
        switch(Storage[0][i])
        {
            case 1:
                TempXStorage[i] = xAxis[0];
                break;
            case 2:
                TempXStorage[i] = xAxis[1];
                break;
            case 3:
                TempXStorage[i] = xAxis[2];
                break;
            case 4:
                TempXStorage[i] = xAxis[3];
                break;
            case 5:
                TempXStorage[i] = xAxis[4];
                break;
            case 6:
                TempXStorage[i] = xAxis[5];
                break;
            case 7:
                TempXStorage[i] = xAxis[6];
                break;
            case 8:
                TempXStorage[i] = xAxis[7];
                break;
        }

        switch(Storage[1][i])
        {
            case 1:
                TempYStorage[i] = yAxis[0];
                break;
            case 2:
                TempYStorage[i] = yAxis[1];
                break;
            case 3:
                TempYStorage[i] = yAxis[2];
                break;
            case 4:
                TempYStorage[i] = yAxis[3];
                break;
            case 5:
                TempYStorage[i] = yAxis[4];
                break;
            case 6:
                TempYStorage[i] = yAxis[5];
                break;
            case 7:
                TempYStorage[i] = yAxis[6];
                break;
            case 8:
                TempYStorage[i] = yAxis[7];
                break;
        }
        TempReadyCoord[i] = TempXStorage[i] + TempYStorage[i]; // Part, where I performed changes in 
tests
        console.log("Position:" + TempXStorage[i] + TempYStorage[i] + " Piece Name:" + Storage[2][i]);
    }

}

标签: javascriptchess

解决方案


推荐阅读