a0cb7f2f602cdeca7af1dcae5d8daebff5503764
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'],
29 randomness: this.options
["randomness"],
34 fen: s
.b
.join("") + "/pppppppp/8/8/8/8/PPPPPPPP/" +
35 s
.w
.join("").toUpperCase(),
41 return this.board
[x
][y
] == "" || this.getPiece(x
, y
) == V
.GOAL
;
44 // Subturn 1: play a move for the opponent on the designated square.
45 // Subturn 2: play a move for me (which just indicate a square).
46 getPotentialMovesFrom([x
, y
]) {
47 const color
= this.turn
;
48 const oppCol
= C
.GetOppTurn(color
);
49 if (this.subTurn
== 2) {
50 // Just play a normal move (which in fact only indicate a square)
53 super.getPotentialMovesFrom([x
, y
])
55 // Filter promotions: keep only one, since no choice for now.
56 if (m
.appear
[0].p
!= m
.vanish
[0].p
) {
57 const hash
= C
.CoordsToSquare(m
.start
) + C
.CoordsToSquare(m
.end
);
58 if (!movesHash
[hash
]) {
59 movesHash
[hash
] = true;
67 if (m
.vanish
.length
== 1)
68 m
.appear
[0].p
= V
.GOAL
;
70 m
.appear
[0].p
= V
.TARGET_CODE
[m
.vanish
[1].p
];
71 m
.appear
[0].c
= m
.vanish
[1].c
;
78 // At subTurn == 1, play a targeted move for the opponent.
80 let target
= {x: -1, y: -1};
81 outerLoop: for (let i
= 0; i
< this.size
.x
; i
++) {
82 for (let j
= 0; j
< this.size
.y
; j
++) {
83 if (this.board
[i
][j
] != "") {
84 const piece
= this.getPiece(i
, j
);
87 Object
.keys(V
.TARGET_DECODE
).includes(piece
)
95 const moves
= super.getPotentialMovesFrom([x
, y
], oppCol
);
96 return moves
.filter(m
=> m
.end
.x
== target
.x
&& m
.end
.y
== target
.y
);
100 const color
= this.getColor(x
, y
);
102 (this.subTurn
== 1 && ![this.turn
, this.playerColor
].includes(color
)) ||
103 (this.subTurn
== 2 && super.canIplay(x
, y
))
107 // Code for empty square target
112 static get TARGET_DECODE() {
123 static get TARGET_CODE() {
134 pieces(color
, x
, y
) {
136 's': {"class": "target-pawn"},
137 'u': {"class": "target-rook"},
138 'o': {"class": "target-knight"},
139 'c': {"class": "target-bishop"},
140 't': {"class": "target-queen"},
141 'l': {"class": "target-king"}
143 return Object
.assign({ 'g': {"class": "target"} },
144 targets
, super.pieces(color
, x
, y
));
148 // Since there are no checks this seems true (same as for Magnetic...)
158 p
= this.getPiece(x
, y
);
159 return ['k', 'l'].includes(p
);
163 // This function is only called at subTurn 1
164 const color
= C
.GetOppTurn(this.turn
);
165 if (this.searchKingPos(color
).length
== 0)
166 return (color
== 'w' ? "0-1" : "1-0");
171 const color
= this.turn
;
172 if (this.subTurn
== 2 || this.searchKingPos(color
).length
== 0) {
173 this.turn
= C
.GetOppTurn(color
);
176 this.subTurn
= 3 - this.subTurn
;