i am by far a javascript specialist but i am trying to learn it a little.
For the move ordering in my chess engine (i follow a tutorial), i would like to check for captures first.
In the chess.js library the capture moves are listed with the flag ‘c’.
game.moves({ flags: 'c', verbose: true })
so im trying to make a shopping list with first the capture moves, and after that, all the rest moves.
i tried it like this:
var children = [
[game.ugly_moves({ flags: 'c', verbose: true })],
[game.ugly_moves({ verbose: true })]
];
like this:
var children = [game.ugly_moves({ flags: 'c', verbose: true })] + [game.ugly_moves({ verbose: true })];
But nothing seems to work.
My code can be seen at http://users.telenet.be/gianc/chessai/js/main.js at line 153
other info: https://github.com/jhlywa/chess.js/blob/master/README.md
Any input is greatly appreciated!
TIA
Based on the documentation at https://github.com/jhlywa/chess.js/blob/master/README.md#moves-options-, the
flags
are not passed intomoves()
, but rather, are returned frommoves()
as an attribute associated with each legal move. Therefore, to get a list of all captures, you will need to apply a filter on the resulting array of all legal moves. Something along the following lines…Note the use of
indexOf()
as there can be multiple flags per move.EDIT: As a follow up to my original answer, another option is to assign values to the
flags
, and create a new attribute associated with each move called, say,importance
. This new attribute will be constructed by assigning values to the critical flags and summing the flags to get animportance
ranking for each move, and then sorting the moves in descending order.For example, let’s say that promotions (‘p’ flag) are most important followed by captures (‘c’ flag) followed by anything else. Let’s then assign, say, the value of 16 for each ‘p’ flag, and 8 for each ‘c’ flag. Note that in this case that a promotion that also captures will have a sum of 24 putting this move at the top of the list(!).
The code will appear as follows…
And of course there’s nothing prohibiting you from including other factors to feed into
importance
to aid in ranking the moves…