Skip to content

Commit

Permalink
Update main.js: Reduce redundant wall gating notation
Browse files Browse the repository at this point in the history
  • Loading branch information
yjf2002ghty authored Jun 4, 2024
1 parent 2825983 commit e7bc6fd
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2919,24 +2919,30 @@ function afterChessgroundMove(orig, dest, metadata) {

if (possiblegatings.length > 1) {
//if there are more than one option
let i = 0;
let gatesquares = [];
for (i = 0; i < possiblegatings.length; i++) {
gatesquares.push(possiblegatings[i].match(/[a-z]+[0-9]+/g)[1]);
}
while (true) {
choice = prompt(
`There are multiple chioces that you can gate a wall square. They are\n${possiblegatings}\n, where = means do not gate, letters with numbers mean destination square (e.g. e4e5 means your piece has moved to e4 and you gate a wall square to e5). Now please enter your choice: `,
`There are multiple chioces that you can gate a wall square. They are\n${gatesquares}\n, where = means do not gate, letters with numbers mean destination square (e.g. e5 means you gate a wall square to e5). Now please enter your choice: `,
"",
);
if (choice == null) {
afterMove(false);
return;
}
if (possiblegatings.includes(choice)) {
if (gatesquares.includes(choice)) {
break;
} else {
alert(
`Bad input: ${choice} . You should enter one option among ${possiblegatings}.`,
`Bad input: ${choice} . You should enter one option among ${gatesquares}.`,
);
continue;
}
}
choice = possiblegatings[gatesquares.indexOf(choice)];
} else if (possiblegatings.length == 1) {
//if there is only one option
choice = possiblegatings[0];
Expand Down

0 comments on commit e7bc6fd

Please sign in to comment.