1 import { ChessRules
, PiPo
, Move
} from "@/base_rules";
3 export const VariantRules
= class AntimatterRules
extends ChessRules
{
4 getBasicMove([sx
, sy
], [ex
, ey
]) {
5 const startColor
= this.getColor(sx
, sy
);
6 const startPiece
= this.getPiece(sx
, sy
);
26 if (this.board
[ex
][ey
] != V
.EMPTY
) {
27 const endColor
= this.getColor(ex
, ey
);
28 const endPiece
= this.getPiece(ex
, ey
);
49 getPotentialPawnMoves([x
, y
]) {
50 const color
= this.turn
;
52 const [sizeX
, sizeY
] = [V
.size
.x
, V
.size
.y
];
53 const shiftX
= color
== "w" ? -1 : 1;
54 const startRank
= color
== "w" ? sizeX
- 2 : 1;
55 const firstRank
= color
== "w" ? sizeX
- 1 : 0;
57 if (x
+ shiftX
>= 0 && x
+ shiftX
< sizeX
) {
59 if (this.board
[x
+ shiftX
][y
] == V
.EMPTY
) {
61 this.getBasicMove([x
, y
], [x
+ shiftX
, y
], {
67 [startRank
,firstRank
].includes(x
) &&
68 this.board
[x
+ 2 * shiftX
][y
] == V
.EMPTY
71 moves
.push(this.getBasicMove([x
, y
], [x
+ 2 * shiftX
, y
]));
75 for (let shiftY
of [-1, 1]) {
79 this.board
[x
+ shiftX
][y
+ shiftY
] != V
.EMPTY
&&
80 this.canTake([x
, y
], [x
+ shiftX
, y
+ shiftY
])
83 this.getBasicMove([x
, y
], [x
+ shiftX
, y
+ shiftY
], {
93 const Lep
= this.epSquares
.length
;
94 const epSquare
= this.epSquares
[Lep
- 1]; //always at least one element
97 epSquare
.x
== x
+ shiftX
&&
98 Math
.abs(epSquare
.y
- y
) == 1
100 let enpassantMove
= this.getBasicMove([x
, y
], [epSquare
.x
, epSquare
.y
]);
101 const oppCol
= V
.GetOppCol(color
);
102 enpassantMove
.vanish
.push({
108 enpassantMove
.appear
.push({
114 moves
.push(enpassantMove
);
120 getPotentialKingMoves() {
124 updateVariables(move) {
125 super.updateVariables(move);
126 if (move.vanish
.length
== 2) {
127 // Was opponent king swapped?
128 if (move.vanish
[1].p
== V
.KING
)
129 this.kingPos
[this.turn
] = [move.appear
[1].x
, move.appear
[1].y
];
133 unupdateVariables(move) {
134 super.unupdateVariables(move);
135 if (move.appear
.length
== 2) {
136 // Was opponent king swapped?
137 if (move.appear
[1].p
== V
.KING
)
138 this.kingPos
[move.vanish
[1].c
] = [move.vanish
[1].x
,move.vanish
[1].y
];
155 const color
= this.turn
;
156 const kp
= this.kingPos
[color
];
157 if (color
== "w" && kp
[0] == 0)
159 if (color
== "b" && kp
[0] == V
.size
.x
- 1)
161 // King is not on the opposite edge: game not over
166 // Very simple criterion for now: kings position
167 return this.kingPos
["w"][0] + this.kingPos
["b"][0];