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 genRandInitBaseFen() {
26 const options
= Object
.assign({mode: "suicide"}, this.options
);
27 const gr
= new GiveawayRules({options: options
, genFenOnly: true});
28 return gr
.genRandInitBaseFen();
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
];
62 m
.appear
[0].c
= m
.vanish
[1].c
;
69 // At subTurn == 1, play a targeted move for the opponent.
71 let target
= {x: -1, y: -1};
72 outerLoop: for (let i
= 0; i
< this.size
.x
; i
++) {
73 for (let j
= 0; j
< this.size
.y
; j
++) {
74 if (this.board
[i
][j
] != "") {
75 const piece
= this.getPiece(i
, j
);
78 Object
.keys(V
.TARGET_DECODE
).includes(piece
)
86 const moves
= super.getPotentialMovesFrom([x
, y
], oppCol
);
87 return moves
.filter(m
=> m
.end
.x
== target
.x
&& m
.end
.y
== target
.y
);
91 const color
= this.getColor(x
, y
);
93 (this.subTurn
== 1 && ![this.turn
, this.playerColor
].includes(color
)) ||
94 (this.subTurn
== 2 && super.canIplay(x
, y
))
98 // Code for empty square target
103 static get TARGET_DECODE() {
114 static get TARGET_CODE() {
125 pieces(color
, x
, y
) {
127 's': {"class": "target-pawn"},
128 'u': {"class": "target-rook"},
129 'o': {"class": "target-knight"},
130 'c': {"class": "target-bishop"},
131 't': {"class": "target-queen"},
132 'l': {"class": "target-king"}
134 return Object
.assign({ 'g': {"class": "target"} },
135 targets
, super.pieces(color
, x
, y
));
139 // Since there are no checks this seems true (same as for Magnetic...)
149 p
= this.getPiece(x
, y
);
150 return ['k', 'l'].includes(p
);
154 // This function is only called at subTurn 1
155 const color
= C
.GetOppCol(this.turn
);
156 if (this.searchKingPos(color
).length
== 0)
157 return (color
== 'w' ? "0-1" : "1-0");
162 const color
= this.turn
;
163 if (this.subTurn
== 2 || this.searchKingPos(color
).length
== 0) {
164 this.turn
= C
.GetOppCol(color
);
167 this.subTurn
= 3 - this.subTurn
;