插入棋谱模块测试
Posted: 2019-09-28 1:53
Let's talk about Renju/Gomoku! Share your experience!
https://bbs.renjucaffe.com/
Code: Select all
[board]h8i9j9k8k7j6i6h7[/board]
Code: Select all
[board]h8h9h6i10i6i9g9g8j11i7i8/k71h102k8Ag6B[/board]
Code: Select all
function convertsinglepos(pos) {
if(pos.length < 2 || pos.length > 3) {
return null;
}
var n1 , n2;
n1 = pos[0].charCodeAt() - 'a'.charCodeAt() + 1;
n2 = parseInt(pos.substring(1));
//TODO 这里可以添加对n1 ,n2 取值范围的检查
return n2.toString(16) + n1.toString(16);
}
Code: Select all
function convertpos(pos) {
var ret = '';
var tmp_str = '';//临时变量,这个也可以改为坐标记录
for (i = 0; i < pos.length; i ++) {
//这里检查每个字符的合法性,然后去做转换
if(pos[i] >= 'a' && pos[i] <= 'o') //是字母
{
if(tmp_str)
{
ret += convertsinglepos(tmp_str);
}
tmp_str = pos[i];
}
else //是数字
{
tmp_str += pos[i];
}
}
ret += convertsinglepos(tmp_str);
return ret;
}