Skip to content

Instantly share code, notes, and snippets.

@byanofsky
Created July 4, 2017 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byanofsky/334ba66c34e11264b718191f807a20d3 to your computer and use it in GitHub Desktop.
Save byanofsky/334ba66c34e11264b718191f807a20d3 to your computer and use it in GitHub Desktop.
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