【发布时间】:2021-10-10 18:05:19
【问题描述】:
我正在尝试使用 chessboard.js library 创建一个使用 if 语句检查棋盘是否处于特定位置(我使用的是 start)的函数
我尝试使用此代码将板的位置属性与我想要使用对象和 FEN 字符串的位置进行比较,但两者都不起作用。
if (board.position == {a1: "wR", a2: "wP", a7: "bP", , a8: "bR", b1: "wN", b2: "wP", b7: "bP", b8: "bN", c1: "wB", c2: "wP", c7: "bP", c8: "bB", d1: "wQ", d2: "wP", d7: "bP", d8: "bQ", e1: "wK", e2: "wP", e7: "bP", e8: "bK", f1: "wB", f2: "wP", f7: "bP", f8: "bB", g1: "wN", g2: "wP", g7: "bP", g8: "bN", h1: "wR", h2: "wP", h7: "bP", h8: "bR") {
alert('The board is in the start position');
} else {
alert('The board is not in the start position');
if (board.position == 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR') {
alert('The board is in the start position');
} else {
alert('The board is not in the start position');
我什至尝试将它与“开始”进行比较
if (board.position == 'start') {
alert('The board is in the start position');
} else {
alert('The board is not in the start position');
【问题讨论】:
-
您是否尝试记录
board.position以查看其实际包含的内容?
标签: javascript jquery chessboard.js