javascript - 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]);
}
}
解决方案
推荐阅读
- hibernate - 使用 Redisson 作为 Hibernate Level 2 缓存时,本地缓存更新是否会从所有应用程序节点中逐出
- google-apps-script - 根据 Gmail 中的 [Reply-To] 值验证电子表格数据
- sql-server - SQL Server DDL 触发器未触发
- r - 如何仅用小写字符替换具有不同大小写的单词向量?
- c - 如何统一分配具有灵活数组成员的结构数组?
- excel - 如何仅显示用户表单隐藏包含用户表单的 Excel 实例
- json - 如何确保方括号 [ ] 包围节点的内容?
- telerik-grid - Telerik GridBoundColumn DataFormatString 被忽略
- javascript - 如何同时使用 HTML 和 Javascript 来更改变量值?
- python - 如何从数据框中的 n 行文本中选择几行