Skip to content

Commit

Permalink
Update main.js: Fix memory leak & add gamer result display
Browse files Browse the repository at this point in the history
  • Loading branch information
yjf2002ghty authored Jun 22, 2024
1 parent 90ab16a commit ee4df79
Showing 1 changed file with 49 additions and 42 deletions.
91 changes: 49 additions & 42 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,7 @@ function getNotation(notation, variant, startfen, is960, ucimovestr) {
let tmpboard = new ffish.Board(variant, startfen, is960);
let moveslist = ucimoves.split(/[ ]+/).reverse();
let result = "";
let tmpboardresult = "";
if (moveslist.length == 1 && moveslist[0] == "") {
} else {
while (moveslist.length > 0) {
Expand All @@ -974,52 +975,63 @@ function getNotation(notation, variant, startfen, is960, ucimovestr) {
}
}
}
tmpboardresult = tmpboard.result();
if (notation == "DEFAULT") {
tmpboard.setFen(startfen);
return tmpboard.variationSan(ucimoves, ffish.Notation.DEFAULT);
result =
tmpboard.variationSan(ucimoves, ffish.Notation.DEFAULT) +
(tmpboardresult !== "*" ? " " + tmpboardresult : "");
} else if (notation == "SAN") {
tmpboard.setFen(startfen);
return tmpboard.variationSan(ucimoves, ffish.Notation.SAN);
result =
tmpboard.variationSan(ucimoves, ffish.Notation.SAN) +
(tmpboardresult !== "*" ? " " + tmpboardresult : "");
} else if (notation == "LAN") {
tmpboard.setFen(startfen);
return tmpboard.variationSan(ucimoves, ffish.Notation.LAN);
result =
tmpboard.variationSan(ucimoves, ffish.Notation.LAN) +
(tmpboardresult !== "*" ? " " + tmpboardresult : "");
} else if (notation == "SHOGI_HOSKING") {
tmpboard.setFen(startfen);
return tmpboard.variationSan(
ucimoves,
ffish.Notation.SHOGI_HOSKING,
);
result =
tmpboard.variationSan(ucimoves, ffish.Notation.SHOGI_HOSKING) +
(tmpboardresult !== "*" ? " " + tmpboardresult : "");
} else if (notation == "SHOGI_HODGES") {
tmpboard.setFen(startfen);
return tmpboard.variationSan(
ucimoves,
ffish.Notation.SHOGI_HODGES,
);
result =
tmpboard.variationSan(ucimoves, ffish.Notation.SHOGI_HODGES) +
(tmpboardresult !== "*" ? " " + tmpboardresult : "");
} else if (notation == "SHOGI_HODGES_NUMBER") {
tmpboard.setFen(startfen);
return tmpboard.variationSan(
ucimoves,
ffish.Notation.SHOGI_HODGES_NUMBER,
);
result =
tmpboard.variationSan(
ucimoves,
ffish.Notation.SHOGI_HODGES_NUMBER,
) + (tmpboardresult !== "*" ? " " + tmpboardresult : "");
} else if (notation == "JANGGI") {
tmpboard.setFen(startfen);
return tmpboard.variationSan(ucimoves, ffish.Notation.JANGGI);
result =
tmpboard.variationSan(ucimoves, ffish.Notation.JANGGI) +
(tmpboardresult !== "*" ? " " + tmpboardresult : "");
} else if (notation == "XIANGQI_WXF") {
tmpboard.setFen(startfen);
return tmpboard.variationSan(
ucimoves,
ffish.Notation.XIANGQI_WXF,
);
result =
tmpboard.variationSan(ucimoves, ffish.Notation.XIANGQI_WXF) +
(tmpboardresult !== "*" ? " " + tmpboardresult : "");
} else if (notation == "THAI_SAN") {
tmpboard.setFen(startfen);
return tmpboard.variationSan(ucimoves, ffish.Notation.THAI_SAN);
result =
tmpboard.variationSan(ucimoves, ffish.Notation.THAI_SAN) +
(tmpboardresult !== "*" ? " " + tmpboardresult : "");
} else if (notation == "THAI_LAN") {
tmpboard.setFen(startfen);
return tmpboard.variationSan(ucimoves, ffish.Notation.THAI_LAN);
result =
tmpboard.variationSan(ucimoves, ffish.Notation.THAI_LAN) +
(tmpboardresult !== "*" ? " " + tmpboardresult : "");
} else if (notation == "FEN") {
return tmpboard.fen();
result = tmpboard.fen();
} else if (notation == "PGN") {
const gameresult = tmpboard.result();
const gameresult = tmpboardresult;
tmpboard.setFen(startfen);
const today = new Date();
const year = today.getFullYear();
Expand Down Expand Up @@ -1052,7 +1064,6 @@ function getNotation(notation, variant, startfen, is960, ucimovestr) {
result += `[Round "1"]\n[White "${whitename}"]\n[Black "${blackname}"]\n`;
result += `[FEN "${startfen}"]\n[Result "${gameresult}"]\n[Variant "${tmpboard.variant()}"]\n\n`;
result += tmpboard.variationSan(ucimoves, ffish.Notation.SAN);
return result;
} else if (notation == "EPD") {
const today = new Date();
const year = today.getFullYear();
Expand Down Expand Up @@ -1109,13 +1120,12 @@ function getNotation(notation, variant, startfen, is960, ucimovestr) {
result += ` variant "${tmpboard.variant()}";`;
result += ` site "${window.location.host}";`;
result += ` date "${year.toString() + "." + month.toString() + "." + day.toString()}";`;
result += ` result "${tmpboard.result()}";`;
result += ` result "${tmpboardresult}";`;
result += ` first_player "${whitename}";`;
result += ` second_player "${blackname}";`;
return result;
} else if (notation == "FEN+UCIMOVE") {
tmpboard.setFen(startfen);
return tmpboard.fen() + "|" + ucimoves;
result = tmpboard.fen() + "|" + ucimoves;
} else if (notation == "FEN+USIMOVE") {
tmpboard.setFen(startfen);
let dimensions = getDimensions();
Expand All @@ -1125,12 +1135,11 @@ function getNotation(notation, variant, startfen, is960, ucimovestr) {
dimensions.height,
);
if (convertedmoves != null) {
return tmpboard.fen() + "|" + convertedmoves;
result = tmpboard.fen() + "|" + convertedmoves;
} else {
return (
result =
tmpboard.fen() +
"|(There are moves that cannot be displayed in USI moves, such as pawn promotion or seirawan gating)"
);
"|(There are moves that cannot be displayed in USI moves, such as pawn promotion or seirawan gating)";
}
} else if (notation == "FEN+UCCIMOVE") {
tmpboard.setFen(startfen);
Expand All @@ -1141,12 +1150,11 @@ function getNotation(notation, variant, startfen, is960, ucimovestr) {
dimensions.height,
);
if (convertedmoves != null) {
return tmpboard.fen() + "|" + convertedmoves;
result = tmpboard.fen() + "|" + convertedmoves;
} else {
return (
result =
tmpboard.fen() +
"|(There are moves that cannot be displayed in UCCI moves, such as pawn promotion or seirawan gating)"
);
"|(There are moves that cannot be displayed in UCCI moves, such as pawn promotion or seirawan gating)";
}
} else if (notation == "SFEN+USIMOVE") {
tmpboard.setFen(startfen);
Expand All @@ -1157,23 +1165,22 @@ function getNotation(notation, variant, startfen, is960, ucimovestr) {
dimensions.height,
);
if (convertedmoves != null) {
return (
result =
fge.ConvertFENtoSFEN(tmpboard.fen()) +
"|" +
fge.convertUCImovestoUSImoves(
ucimoves,
dimensions.width,
dimensions.height,
)
);
);
} else {
return (
result =
fge.ConvertFENtoSFEN(tmpboard.fen()) +
"|(There are moves that cannot be displayed in USI moves, such as pawn promotion or seirawan gating)"
);
"|(There are moves that cannot be displayed in USI moves, such as pawn promotion or seirawan gating)";
}
}
tmpboard.delete();
return result;
} else {
return "Illegal FEN";
}
Expand Down

0 comments on commit ee4df79

Please sign in to comment.