1 import ChessRules
from "/base_rules.js";
2 import GiveawayRules
from "/variants/Giveaway/class.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 genRandInitFen(seed
) {
26 const options
= Object
.assign({mode: "suicide"}, this.options
);
27 const gr
= new GiveawayRules({options: options
, genFenOnly: true});
28 return gr
.genRandInitFen(seed
);
32 return this.board
[x
][y
] == "" || this.getPiece(x
, y
) == V
.GOAL
;
35 // Subturn 1: play a move for the opponent on the designated square.
36 // Subturn 2: play a move for me (which just indicate a square).
37 getPotentialMovesFrom([x
, y
]) {
38 const color
= this.turn
;
39 const oppCol
= C
.GetOppCol(color
);
40 if (this.subTurn
== 2) {
41 // Just play a normal move (which in fact only indicate a square)
44 super.getPotentialMovesFrom([x
, y
])
46 // Filter promotions: keep only one, since no choice for now.
47 if (m
.appear
[0].p
!= m
.vanish
[0].p
) {
48 const hash
= C
.CoordsToSquare(m
.start
) + C
.CoordsToSquare(m
.end
);
49 if (!movesHash
[hash
]) {
50 movesHash
[hash
] = true;
58 if (m
.vanish
.length
== 1)
59 m
.appear
[0].p
= V
.GOAL
;
61 m
.appear
[0].p
= V
.TARGET_CODE
[m
.vanish
[1].p
];
67 // At subTurn == 1, play a targeted move for the opponent.
68 // Search for target (we could also have it in a stack...)
69 let target
= {x: -1, y: -1};
70 outerLoop: for (let i
= 0; i
< this.size
.x
; i
++) {
71 for (let j
= 0; j
< this.size
.y
; j
++) {
72 if (this.board
[i
][j
] != "") {
73 const piece
= this.getPiece(i
, j
);
76 Object
.keys(V
.TARGET_DECODE
).includes(piece
)
84 const moves
= super.getPotentialMovesFrom([x
, y
], oppCol
);
85 return moves
.filter(m
=> m
.end
.x
== target
.x
&& m
.end
.y
== target
.y
);
89 const color
= this.getColor(x
, y
);
91 (this.subTurn
== 1 && ![this.turn
, this.playerColor
].includes(color
)) ||
92 (this.subTurn
== 2 && super.canIplay(x
, y
))
96 // Code for empty square target
101 static get TARGET_DECODE() {
112 static get TARGET_CODE() {
123 pieces(color
, x
, y
) {
125 's': {"class": "target-pawn", moves: []},
126 'u': {"class": "target-rook", moves: []},
127 'o': {"class": "target-knight", moves: []},
128 'c': {"class": "target-bishop", moves: []},
129 't': {"class": "target-queen", moves: []},
130 'l': {"class": "target-king", moves: []}
132 return Object
.assign({ 'g': {"class": "target", moves: []} },
133 targets
, super.pieces(color
, x
, y
));
137 // Since there are no checks this seems true (same as for Magnetic...)
146 return ['k', 'l'].includes(symbol
);
150 // This function is only called at subTurn 1
151 const color
= C
.GetOppCol(this.turn
);
152 const kingPos
= this.searchKingPos(color
);
154 return (color
== 'w' ? "0-1" : "1-0");
159 const color
= this.turn
;
160 if (this.subTurn
== 2 || this.searchKingPos(color
)[0] < 0) {
161 this.turn
= C
.GetOppCol(color
);
164 this.subTurn
= 3 - this.subTurn
;