Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Evaluates position of board
var evaluateBoard = function(board, color) {
// Sets the value for each piece using standard piece value
var pieceValue = {
'p': 100,
'n': 350,
'b': 350,
'r': 525,
'q': 1000,
'k': 10000
};
// Loop through all pieces on the board and sum up total
var value = 0;
board.forEach(function(row) {
row.forEach(function(piece) {
if (piece) {
// Subtract piece value if it is opponent's piece
value += pieceValue[piece['type']]
* (piece['color'] === color ? 1 : -1);
}
});
});
return value;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment