Created
July 4, 2017 17:14
-
-
Save byanofsky/334ba66c34e11264b718191f807a20d3 to your computer and use it in GitHub Desktop.
Evaluates position of board
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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