1 import { ChessRules
} from "@/base_rules";
2 import { Wormhole2Rules
} from "@/variants/Wormhole2";
4 export class Wormhole1Rules
extends Wormhole2Rules
{
6 static get PawnSpecs() {
10 { promotions: [V
.LION
, V
.CHAMPION
, V
.WIZARD
, V
.KNIGHT
] }
20 static get CHAMPION() {
25 return [V
.PAWN
, V
.CHAMPION
, V
.KNIGHT
, V
.WIZARD
, V
.LION
, V
.KING
];
29 if (b
[0] == 'x') return "Wormhole/hole";
30 if ([V
.LION
, V
.CHAMPION
, V
.WIZARD
].includes(b
[1]))
31 return "Wormhole/" + b
;
38 [ [-2, 0], [-1, -1] ],
40 [ [0, -2], [-1, -1] ],
71 n: Wormhole2Rules
.steps
[V
.KNIGHT
],
72 k: Wormhole2Rules
.steps
[V
.KING
]
76 static GenRandInitFen(options
) {
77 if (options
.randomness
== 0)
78 return "cnwmkwnc/pppppppp/8/8/8/8/PPPPPPPP/CNWMKWNC w 0";
80 // Mapping new --> standard:
89 const baseFen
= ChessRules
.GenRandInitFen(options
);
91 baseFen
.substr(0, 8).split('').map(p
=> piecesMap
[p
]).join('') +
92 baseFen
.substr(8, 27) +
93 baseFen
.substr(35, 8).toLowerCase().split('')
94 .map(p
=> piecesMap
[p
]).join('').toUpperCase() +
99 getPotentialMovesFrom(sq
) {
100 switch (this.getPiece(sq
[0], sq
[1])) {
101 case V
.PAWN: return super.getPotentialPawnMoves(sq
);
102 case V
.CHAMPION: return this.getPotentialChampionMoves(sq
);
103 case V
.KNIGHT: return super.getPotentialKnightMoves(sq
);
104 case V
.WIZARD: return this.getPotentialWizardMoves(sq
);
105 case V
.LION: return this.getPotentialLionMoves(sq
);
106 case V
.KING: return super.getPotentialKingMoves(sq
);
111 getJumpMoves([x
, y
], steps
, onlyTake
) {
113 for (let step
of steps
) {
114 const sq
= this.getSquareAfter([x
,y
], step
);
117 (!onlyTake
&& this.board
[sq
[0]][sq
[1]] == V
.EMPTY
) ||
118 (this.board
[sq
[0]][sq
[1]] != V
.EMPTY
&& this.canTake([x
, y
], sq
))
121 moves
.push(this.getBasicMove([x
, y
], sq
));
127 getPotentialChampionMoves(sq
) {
128 const steps
= V
.steps
['d'].concat(V
.steps
['a']).concat(V
.steps
['z']);
129 return this.getJumpMoves(sq
, steps
);
132 getPotentialWizardMoves(sq
) {
133 const steps
= V
.steps
['w'].concat(V
.steps
['f']);
134 return this.getJumpMoves(sq
, steps
);
137 getPotentialLionMoves(sq
) {
138 let steps
= V
.steps
['d'].concat(V
.steps
['a']);
139 const moves1
= this.getJumpMoves(sq
, steps
);
140 steps
= V
.steps
['f'].concat(V
.steps
['z']);
141 const moves2
= this.getJumpMoves(sq
, steps
, "onlyTake");
142 return moves1
.concat(moves2
);
145 isAttacked(sq
, color
) {
147 super.isAttackedByPawn(sq
, color
) ||
148 this.isAttackedByChampion(sq
, color
) ||
149 super.isAttackedByKnight(sq
, color
) ||
150 this.isAttackedByWizard(sq
, color
) ||
151 this.isAttackedByLion(sq
, color
) ||
152 super.isAttackedByKing(sq
, color
)
156 isAttackedByWizard(sq
, color
) {
158 this.isAttackedByJump(sq
, color
, V
.WIZARD
, V
.steps
['f']) ||
159 // NOTE: wizard attack is not symmetric in this variant:
160 // steps order need to be reversed.
161 this.isAttackedByJump(
165 V
.steps
['w'].map(s
=> s
.reverse())
170 isAttackedByChampion(sq
, color
) {
171 const steps
= V
.steps
['d'].concat(V
.steps
['a']).concat(V
.steps
['z']);
172 return this.isAttackedByJump(sq
, color
, V
.CHAMPION
, steps
);
175 isAttackedByLion(sq
, color
) {
176 const steps
= V
.steps
['d'].concat(V
.steps
['a'])
177 .concat(V
.steps
['f']).concat(V
.steps
['z']);
178 return this.isAttackedByJump(sq
, color
, V
.LION
, steps
);
181 static get VALUES() {