问题描述
我正在尝试根据棋盘的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]);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)