1 class ExtinctionRules
extends ChessRules
5 super.initVariables(fen
);
6 const V
= VariantRules
;
30 getPotentialPawnMoves([x
,y
])
32 let moves
= super.getPotentialPawnMoves([x
,y
]);
33 // Add potential promotions into king
34 const color
= this.turn
;
35 const V
= VariantRules
;
36 const [sizeX
,sizeY
] = V
.size
;
37 const shift
= (color
== "w" ? -1 : 1);
38 const lastRank
= (color
== "w" ? 0 : sizeX
-1);
40 if (x
+shift
== lastRank
)
43 if (this.board
[x
+shift
][y
] == V
.EMPTY
)
44 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
], {c:color
,p:V
.KING
}));
46 if (y
>0 && this.canTake([x
,y
], [x
+shift
,y
-1])
47 && this.board
[x
+shift
][y
-1] != V
.EMPTY
)
49 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
-1], {c:color
,p:V
.KING
}));
51 if (y
<sizeY
-1 && this.canTake([x
,y
], [x
+shift
,y
+1])
52 && this.board
[x
+shift
][y
+1] != V
.EMPTY
)
54 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
+1], {c:color
,p:V
.KING
}));
61 // TODO: verify this assertion
64 return true; //always at least one possible move
69 return false; //there is no check
79 super.updateVariables(move);
80 // Treat the promotion case: (not the capture part)
81 if (move.appear
[0].p
!= move.vanish
[0].p
)
83 this.material
[move.appear
[0].c
][move.appear
[0].p
]++;
84 this.material
[move.appear
[0].c
][VariantRules
.PAWN
]--;
86 if (move.vanish
.length
==2 && move.appear
.length
==1) //capture
87 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]--;
90 unupdateVariables(move)
92 super.unupdateVariables(move);
93 if (move.appear
[0].p
!= move.vanish
[0].p
)
95 this.material
[move.appear
[0].c
][move.appear
[0].p
]--;
96 this.material
[move.appear
[0].c
][VariantRules
.PAWN
]++;
98 if (move.vanish
.length
==2 && move.appear
.length
==1)
99 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]++;
104 if (this.checkRepetition())
107 if (this.atLeastOneMove()) // game not over?
109 const color
= this.turn
;
110 if (Object
.keys(this.material
[color
]).some(
111 p
=> { return this.material
[color
][p
] == 0; }))
113 return this.checkGameEnd();
118 return this.checkGameEnd(); //NOTE: currently unreachable...
123 return this.turn
== "w" ? "0-1" : "1-0";
128 const color
= this.turn
;
129 if (Object
.keys(this.material
[color
]).some(
130 p
=> { return this.material
[color
][p
] == 0; }))
132 // Very negative (resp. positive) if white (reps. black) pieces set is incomplete
133 return (color
=="w"?-1:1) * VariantRules
.INFINITY
;
135 return super.evalPosition();