1 import ChessRules
from "/base_rules.js";
2 import {FenUtil
} from "/utils/setupPieces.js";
4 export default class AmbiguousRules
extends ChessRules
{
8 select: C
.Options
.select
,
17 setOtherVariables(fenParsed
) {
18 super.setOtherVariables(fenParsed
);
19 if (this.movesCount
== 0)
25 genRandInitBaseFen() {
26 const s
= FenUtil
.setupPieces(
27 ['r', 'n', 'b', 'q', 'k', 'b', 'n', 'r'], {diffCol: ['b']});
29 fen: s
.b
.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
30 s
.w
.join("").toUpperCase(),
36 return this.board
[x
][y
] == "" || this.getPiece(x
, y
) == V
.GOAL
;
39 // Subturn 1: play a move for the opponent on the designated square.
40 // Subturn 2: play a move for me (which just indicate a square).
41 getPotentialMovesFrom([x
, y
]) {
42 const color
= this.turn
;
43 const oppCol
= C
.GetOppCol(color
);
44 if (this.subTurn
== 2) {
45 // Just play a normal move (which in fact only indicate a square)
48 super.getPotentialMovesFrom([x
, y
])
50 // Filter promotions: keep only one, since no choice for now.
51 if (m
.appear
[0].p
!= m
.vanish
[0].p
) {
52 const hash
= C
.CoordsToSquare(m
.start
) + C
.CoordsToSquare(m
.end
);
53 if (!movesHash
[hash
]) {
54 movesHash
[hash
] = true;
62 if (m
.vanish
.length
== 1)
63 m
.appear
[0].p
= V
.GOAL
;
65 m
.appear
[0].p
= V
.TARGET_CODE
[m
.vanish
[1].p
];
66 m
.appear
[0].c
= m
.vanish
[1].c
;
73 // At subTurn == 1, play a targeted move for the opponent.
75 let target
= {x: -1, y: -1};
76 outerLoop: for (let i
= 0; i
< this.size
.x
; i
++) {
77 for (let j
= 0; j
< this.size
.y
; j
++) {
78 if (this.board
[i
][j
] != "") {
79 const piece
= this.getPiece(i
, j
);
82 Object
.keys(V
.TARGET_DECODE
).includes(piece
)
90 const moves
= super.getPotentialMovesFrom([x
, y
], oppCol
);
91 return moves
.filter(m
=> m
.end
.x
== target
.x
&& m
.end
.y
== target
.y
);
95 const color
= this.getColor(x
, y
);
97 (this.subTurn
== 1 && ![this.turn
, this.playerColor
].includes(color
)) ||
98 (this.subTurn
== 2 && super.canIplay(x
, y
))
102 // Code for empty square target
107 static get TARGET_DECODE() {
118 static get TARGET_CODE() {
129 pieces(color
, x
, y
) {
131 's': {"class": "target-pawn"},
132 'u': {"class": "target-rook"},
133 'o': {"class": "target-knight"},
134 'c': {"class": "target-bishop"},
135 't': {"class": "target-queen"},
136 'l': {"class": "target-king"}
138 return Object
.assign({ 'g': {"class": "target"} },
139 targets
, super.pieces(color
, x
, y
));
143 // Since there are no checks this seems true (same as for Magnetic...)
153 p
= this.getPiece(x
, y
);
154 return ['k', 'l'].includes(p
);
158 // This function is only called at subTurn 1
159 const color
= C
.GetOppCol(this.turn
);
160 if (this.searchKingPos(color
).length
== 0)
161 return (color
== 'w' ? "0-1" : "1-0");
166 const color
= this.turn
;
167 if (this.subTurn
== 2 || this.searchKingPos(color
).length
== 0) {
168 this.turn
= C
.GetOppCol(color
);
171 this.subTurn
= 3 - this.subTurn
;