1 class ExtinctionRules
extends ChessRules
5 super.initVariables(fen
);
29 getPotentialPawnMoves([x
,y
])
31 let moves
= super.getPotentialPawnMoves([x
,y
]);
32 // Add potential promotions into king
33 const color
= this.turn
;
34 const shift
= (color
== "w" ? -1 : 1);
35 const lastRank
= (color
== "w" ? 0 : V
.size
.x
-1);
37 if (x
+shift
== lastRank
)
40 if (this.board
[x
+shift
][y
] == V
.EMPTY
)
41 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
], {c:color
,p:V
.KING
}));
43 if (y
>0 && this.board
[x
+shift
][y
-1] != V
.EMPTY
44 && this.canTake([x
,y
], [x
+shift
,y
-1]))
46 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
-1], {c:color
,p:V
.KING
}));
48 if (y
<V
.size
.y
-1 && this.board
[x
+shift
][y
+1] != V
.EMPTY
49 && this.canTake([x
,y
], [x
+shift
,y
+1]))
51 moves
.push(this.getBasicMove([x
,y
], [x
+shift
,y
+1], {c:color
,p:V
.KING
}));
58 // TODO: verify this assertion
61 return true; //always at least one possible move
66 return false; //there is no check
76 super.updateVariables(move);
77 // Treat the promotion case: (not the capture part)
78 if (move.appear
[0].p
!= move.vanish
[0].p
)
80 this.material
[move.appear
[0].c
][move.appear
[0].p
]++;
81 this.material
[move.appear
[0].c
][V
.PAWN
]--;
83 if (move.vanish
.length
==2 && move.appear
.length
==1) //capture
84 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]--;
87 unupdateVariables(move)
89 super.unupdateVariables(move);
90 if (move.appear
[0].p
!= move.vanish
[0].p
)
92 this.material
[move.appear
[0].c
][move.appear
[0].p
]--;
93 this.material
[move.appear
[0].c
][V
.PAWN
]++;
95 if (move.vanish
.length
==2 && move.appear
.length
==1)
96 this.material
[move.vanish
[1].c
][move.vanish
[1].p
]++;
101 if (this.checkRepetition())
104 if (this.atLeastOneMove()) // game not over?
106 const color
= this.turn
;
107 if (Object
.keys(this.material
[color
]).some(
108 p
=> { return this.material
[color
][p
] == 0; }))
110 return this.checkGameEnd();
115 return this.checkGameEnd(); //NOTE: currently unreachable...
120 return this.turn
== "w" ? "0-1" : "1-0";
125 const color
= this.turn
;
126 if (Object
.keys(this.material
[color
]).some(
127 p
=> { return this.material
[color
][p
] == 0; }))
129 // Very negative (resp. positive) if white (reps. black) pieces set is incomplete
130 return (color
=="w"?-1:1) * V
.INFINITY
;
132 return super.evalPosition();