xchess
Version:
Chess Engine
109 lines (79 loc) • 1.28 kB
JavaScript
export {GameColor}
import {white, black} from './color.js'
import {INVALID_COLOR} from './errors.js'
class GameColor {
static from(color){
if(white.eq(color)) return White;
if(black.eq(color)) return Black;
throw INVALID_COLOR(color);
}
static get white(){
return White;
}
static get black(){
return Black;
}
get color(){
return null;
}
invert(){
return null;
}
// Castling
wk(state){
return null;
}
wq(state){
return null;
}
bk(state){
return null;
}
bq(state){
return null;
}
}
class WhiteGameColor extends GameColor {
get color(){
return white;
}
invert(){
return Black;
}
// Castling
wk({castling}){
return castling.kingside;
}
wq({castling}){
return castling.queenside;
}
bk({prevCastling}){
return prevCastling.kingside;
}
bq({prevCastling}){
return prevCastling.queenside;
}
}
class BlackGameColor extends GameColor {
get color(){
return black;
}
invert(){
return White;
}
// Castling
wk({prevCastling}){
return prevCastling.kingside;
}
wq({prevCastling}){
return prevCastling.queenside;
}
bk({castling}){
return castling.kingside;
}
bq({castling}){
return castling.queenside;
}
}
const White = new WhiteGameColor();
const Black = new BlackGameColor();