chess-ai-kong
Version:
Chess AI based on Alpha-Beta pruning algorithm.
98 lines (88 loc) • 3.15 kB
JavaScript
;
/**
* Get the basic strategy tables for White player (Black should be the opposite index):
* - Pawns go forward and prefer center
* - Rooks stick to the edge
* - Bishops and Knights avoid the corners and edges
* - Queen prefers the edge and avoid the center
* - King hide
*/
function getStrategyPositionTable() {
/**
* TODO: need to be tuned.
*/
return {
'P': [
0, 0, 0, 0, 0, 0, 0, 0,
5, 10, 10,-25,-25, 10, 10, 5,
5, -5,-10, 0, 0,-10, -5, 5,
0, 0, 0, 25, 25, 0, 0, 0,
5, 5, 10, 27, 27, 10, 5, 5,
10, 10, 20, 30, 30, 20, 10, 10,
30, 30, 30, 40, 40, 30, 30, 30,
50, 50, 50, 50, 50, 50, 50, 50
],
'N': [
-50,-40,-30,-30,-30,-30,-40,-50,
-40,-20, 0, 5, 5, 0,-20,-40,
-30, 5, 10, 15, 15, 10, 5,-30,
-30, 0, 15, 20, 20, 15, 0,-30,
-30, 5, 15, 20, 20, 15, 5,-30,
-30, 0, 10, 15, 15, 10, 0,-30,
-40,-20, 0, 0, 0, 0,-20,-40,
-50,-40,-20,-30,-30,-20,-40,-50
],
'B': [
-20,-10,-40,-10,-10,-40,-10,-20
-10, 5, 0, 0, 0, 0, 5,-10,
-10, 10, 10, 10, 10, 10, 10,-10,
-10, 0, 10, 10, 10, 10, 0,-10,
-10, 5, 5, 10, 10, 5, 5,-10,
-10, 0, 5, 10, 10, 5, 0,-10,
-10, 0, 0, 0, 0, 0, 0,-10,
-20,-10,-10,-10,-10,-10,-10,-20
],
'R': [
20, 10, 10, 10, 10, 10, 10, 20,
20, 0, 0, 0, 0, 0, 0, 20,
20, 0, -5,-10,-10, -5, 0, 20,
10, 0,-10,-15,-15,-10, 0, 10,
10, 0,-10,-15,-15,-10, 0, 10,
10, 0, -5,-10,-10, -5, 0, 10,
20, 0, 0, 0, 0, 0, 0, 20,
20, 20, 10, 10, 10, 10, 20, 20
],
'Q': [
30, 20, 20, 50, 50, 20, 20, 30,
20, 20, 10, 5, 5, 10, 20, 20,
20, 10, -5,-10,-10, -5, 10, 20,
30, 0,-15,-20,-20,-15, 0, 30,
30, 0,-15,-20,-20,-15, 0, 30,
20, 0,-10,-50,-50,-20, 0, 20,
20, 20, 0, 0, 0, 0, 20, 20,
30, 20, 20, 40, 40, 20, 20, 30
],
'K': [
20, 30, 10, 0, 0, 10, 30, 20,
20, 20, 0, 0, 0, 0, 20, 20,
-10, -20, -20, -20, -20, -20, -20, -10,
-20, -30, -30, -40, -40, -30, -30, -20,
-30, -40, -40, -50, -50, -40, -40, -30,
-30, -40, -40, -50, -50, -40, -40, -30,
-30, -40, -40, -50, -50, -40, -40, -30,
-30, -40, -40, -50, -50, -40, -40, -30
]
};
}
function getStrategyPiecesTable() {
return {
'P': 100
,'R': 500
,'B': 325
,'N': 300
,'Q': 900
,'K': 32767
}
}
module.exports.getStrategyPositionTable = getStrategyPositionTable;
module.exports.getStrategyPiecesTable = getStrategyPiecesTable;