black-horse
Version:
Chess engine built in Javascript using the alpha-beta algorithm
139 lines (122 loc) • 3.11 kB
JavaScript
const pawnTable = [
[],
[],
[],
[],
[],
[],
[],
[],
];
const knightTable = [
[],
[],
[],
[],
[],
[],
[],
[],
];
const bishopTable = [
[],
[],
[],
[],
[],
[],
[],
[],
];
const rookTable = [
[],
[],
[],
[],
[],
[],
[],
[],
];
const queenTable = [
[],
[],
[],
[],
[],
[],
[],
[],
];
const kingTable = [
[],
[-30, -30, -30, -30, -30, -30, -30, -30],
[-50, -50, -50, -50, -50, -50, -50, -50],
[-70, -70, -70, -70, -70, -70, -70, -70],
[-70, -70, -70, -70, -70, -70, -70, -70],
[-70, -70, -70, -70, -70, -70, -70, -70],
[-70, -70, -70, -70, -70, -70, -70, -70],
[-70, -70, -70, -70, -70, -70, -70, -70],
];
const kingEndGameTable = [
[-50, -10, 0, 0, 0, 0, -10, -50],
[-10, 0, 10, 10, 10, 10, 0, -10],
[],
[],
[],
[],
[-10, 0, 10, 10, 10, 10, 0, -10],
[-50, -10, 0, 0, 0, 0, -10, -50],
];
const bishopPairBonus = 30;
const endGameValue = 51400;
const doubledPawnPenalty = 10;
const isolatedPawnPenalty = 10;
const castlingPenalty = 99;
const castlingEndGamePenalty = 0;
const castlingBonus = 0;
module.exports = class EvaluationModel {
constructor() {}
pawnScore(row, column) {
return pawnTable[row][column];
}
knightScore(row, column) {
return knightTable[row][column];
}
bishopScore(row, column) {
return bishopTable[row][column];
}
rookScore(row, column) {
return rookTable[row][column];
}
queenScore(row, column) {
return queenTable[row][column];
}
kingScore(row, column) {
return kingTable[row][column];
}
kingEndGameScore(row, column) {
return kingEndGameTable[row][column];
}
bishopPairBonus() {
return bishopPairBonus;
}
doubledPawnPenalty() {
return doubledPawnPenalty;
}
isolatedPawnPenalty() {
return isolatedPawnPenalty;
}
castlingPenalty() {
return castlingPenalty;
}
castlingEndGamePenalty() {
return castlingEndGamePenalty;
}
castlingBonus() {
return castlingBonus;
}
endGameValue() {
return endGameValue;
}
};