X-Git-Url: https://git.auder.net/img/rock_paper_scissors_lizard_spock.gif?a=blobdiff_plain;ds=inline;f=utils%2FsetupPieces.js;h=60110cf0a3e92700d55b246cde0626da2868a005;hb=c4d2eb5bdf1b23d8c4a9d09322f84a9e0da9d60c;hp=2c8cceee81f5edd4ea8e6fc9c0d2ec7df24861f3;hpb=10c9010b3b04915e132b6b3820f2f19c9ea6dcf0;p=xogo.git diff --git a/utils/setupPieces.js b/utils/setupPieces.js index 2c8ccee..60110cf 100644 --- a/utils/setupPieces.js +++ b/utils/setupPieces.js @@ -38,18 +38,20 @@ export const FenUtil = { }); } if (o.between) { - // Locate p1. If appearing first, exchange with first p2. - // If appearing last, exchange with last p2. - const p1 = res.indexOf(o.between["p1"]); - const firstP2 = res.indexOf(o.between["p2"]), - lastP2 = res.lastIndexOf(o.between["p2"]); - if (p1 < firstP2 || p1 > lastP2) { - res[p1] = o.between["p2"]; - if (p1 < firstP2) - res[firstP2] = o.between["p1"]; - else //p1 > lastP2 - res[lastP2] = o.between["p1"]; - } + o.between.forEach(b => { + // Locate p1. If appearing first, exchange with first p2. + // If appearing last, exchange with last p2. + const p1 = res.indexOf(b["p1"]); + const firstP2 = res.indexOf(b["p2"]), + lastP2 = res.lastIndexOf(b["p2"]); + if (p1 < firstP2 || p1 > lastP2) { + res[p1] = b["p2"]; + if (p1 < firstP2) + res[firstP2] = b["p1"]; + else //p1 > lastP2 + res[lastP2] = b["p1"]; + } + }); } } return {fen: res, flags: flags};