xchess
Version:
Chess Engine
137 lines (100 loc) • 1.64 kB
JavaScript
export {
MoveEvent,
PromotionEvent,
InsertEvent,
DeleteEvent,
TransferEvent,
RestoreEvent,
}
import {Queen, Rook, Bishop, Knight} from './piece.js'
class MoveEvent extends Event {
#move;
constructor(type, move){
super(type);
this.#move = move;
}
get move(){
return this.#move;
}
}
class PromotionEvent extends MoveEvent {
queen(){
this.target.promote(new Queen(this.target.color));
}
rook(){
this.target.promote(new Rook(this.target.color));
}
bishop(){
this.target.promote(new Bishop(this.target.color));
}
knight(){
this.target.promote(new Knight(this.target.color));
}
q(){
this.queen();
}
r(){
this.rook();
}
b(){
this.bishop();
}
n(){
this.knight();
}
}
class BoardEvent extends Event {
#piece;
constructor(type, piece){
super(type);
this.#piece = piece;
}
get piece(){
return this.#piece;
}
}
class InsertEvent extends BoardEvent {
#square;
constructor(piece, square){
super('insert', piece);
this.#square = square;
}
get square(){
return this.#square;
}
}
class DeleteEvent extends BoardEvent {
#square;
constructor(piece, square){
super('delete', piece);
this.#square = square;
}
get square(){
return this.#square;
}
}
class TransferEvent extends BoardEvent {
#from;
#to;
constructor(piece, from, to){
super('transfer', piece);
this.#from = from;
this.#to = to;
}
get from(){
return this.#from;
}
get to(){
return this.#to;
}
}
class RestoreEvent extends Event {
#count;
constructor(count){
super('restore');
this.#count = Math.trunc(count);
}
get count(){
return this.#count;
}
}