xchess
Version:
Chess Engine
56 lines (47 loc) • 1.15 kB
JavaScript
export {Transitional}
import {
ResignationState,
ForfeitState,
WinOnTimeState,
ThreefoldRepetitionState,
FiftyMovesState,
DrawByResignationState,
DrawOnTimeState,
DrawByAgreementState,
} from './end-state.js'
function Transitional(State){
return class TransitionalState extends State {
forfeit(color){
this.push(new ForfeitState(this, this, color));
return true;
}
resign(color){
if(this.isCheckmateChance(color))
this.push(new ResignationState(this, this, color));
else
this.push(new DrawByResignationState(this, this, color));
return true;
}
draw(color){
if(this.halfmoveClock >= 50){
this.push(new FiftyMovesState(this, this, color));
return true;
}
if(this.repetition >= 3){
this.push(new ThreefoldRepetitionState(this, this, color));
return true;
}
return this.drawOffer.draw(color);
}
toDraw(color){
this.push(new DrawByAgreementState(this, this, color));
}
flagFall(){
if(this.isCheckmateChance(this.color))
this.push(new WinOnTimeState(this, this, this.color));
else
this.push(new DrawOnTimeState(this, this));
return true;
}
}
}